@ably/ai-transport 0.2.0 → 0.3.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 +10 -19
- package/dist/ably-ai-transport.js +1790 -1091
- 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 +2 -2
- package/dist/core/agent.d.ts +20 -5
- package/dist/core/channel-options.d.ts +57 -0
- package/dist/core/codec/codec-event.d.ts +9 -0
- package/dist/core/codec/decoder.d.ts +4 -1
- package/dist/core/codec/define-codec.d.ts +100 -0
- package/dist/core/codec/encoder.d.ts +2 -7
- package/dist/core/codec/field-bag.d.ts +85 -0
- package/dist/core/codec/fields.d.ts +141 -0
- package/dist/core/codec/index.d.ts +8 -1
- package/dist/core/codec/input-descriptor-decoder.d.ts +19 -0
- package/dist/core/codec/input-descriptor-encoder.d.ts +22 -0
- package/dist/core/codec/input-descriptors.d.ts +281 -0
- package/dist/core/codec/output-descriptor-decoder.d.ts +29 -0
- package/dist/core/codec/output-descriptor-encoder.d.ts +31 -0
- package/dist/core/codec/output-descriptors.d.ts +237 -0
- package/dist/core/codec/types.d.ts +95 -36
- package/dist/core/codec/well-known-inputs.d.ts +52 -0
- package/dist/core/transport/agent-view.d.ts +296 -0
- package/dist/core/transport/decode-fold.d.ts +40 -32
- package/dist/core/transport/headers.d.ts +30 -1
- package/dist/core/transport/index.d.ts +1 -1
- package/dist/core/transport/invocation.d.ts +1 -1
- package/dist/core/transport/load-history-pages.d.ts +71 -0
- package/dist/core/transport/load-history.d.ts +21 -16
- package/dist/core/transport/run-manager.d.ts +9 -11
- package/dist/core/transport/session-support.d.ts +55 -0
- package/dist/core/transport/tree.d.ts +165 -15
- package/dist/core/transport/types/agent.d.ts +120 -98
- package/dist/core/transport/types/client.d.ts +45 -12
- package/dist/core/transport/types/tree.d.ts +52 -10
- package/dist/core/transport/types/view.d.ts +55 -28
- package/dist/core/transport/view.d.ts +176 -58
- package/dist/core/transport/wire-log.d.ts +102 -0
- package/dist/errors.d.ts +10 -4
- package/dist/index.d.ts +6 -5
- package/dist/react/ably-ai-transport-react.js +784 -415
- 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 +2 -1
- package/dist/react/contexts/client-session-provider.d.ts +3 -0
- package/dist/react/index.d.ts +2 -1
- package/dist/react/internal/skipped-session.d.ts +8 -0
- package/dist/react/use-view.d.ts +3 -3
- package/dist/utils.d.ts +22 -54
- package/dist/vercel/ably-ai-transport-vercel.js +2297 -2026
- 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/decode-lifecycle.d.ts +9 -0
- package/dist/vercel/codec/events.d.ts +1 -2
- package/dist/vercel/codec/fields.d.ts +44 -0
- package/dist/vercel/codec/fold-content.d.ts +16 -0
- package/dist/vercel/codec/fold-data.d.ts +16 -0
- package/dist/vercel/codec/fold-input.d.ts +67 -0
- package/dist/vercel/codec/fold-lifecycle.d.ts +16 -0
- package/dist/vercel/codec/fold-text.d.ts +16 -0
- package/dist/vercel/codec/fold-tool-input.d.ts +17 -0
- package/dist/vercel/codec/fold-tool-output.d.ts +16 -0
- package/dist/vercel/codec/index.d.ts +5 -30
- package/dist/vercel/codec/inputs.d.ts +11 -0
- package/dist/vercel/codec/outputs.d.ts +11 -0
- package/dist/vercel/codec/reducer-state.d.ts +121 -0
- package/dist/vercel/codec/reducer.d.ts +20 -102
- package/dist/vercel/codec/tool-transitions.d.ts +0 -6
- package/dist/vercel/codec/wire-data.d.ts +34 -0
- package/dist/vercel/index.d.ts +1 -0
- package/dist/vercel/react/ably-ai-transport-vercel-react.js +2013 -9500
- package/dist/vercel/react/ably-ai-transport-vercel-react.js.map +1 -1
- package/dist/vercel/react/ably-ai-transport-vercel-react.umd.cjs +1 -70
- package/dist/vercel/react/ably-ai-transport-vercel-react.umd.cjs.map +1 -1
- package/dist/vercel/react/contexts/chat-transport-context.d.ts +2 -1
- package/dist/vercel/run-end-reason.d.ts +66 -11
- package/dist/vercel/tool-part.d.ts +21 -0
- package/dist/vercel/transport/chat-transport.d.ts +0 -2
- package/dist/vercel/transport/index.d.ts +1 -1
- package/dist/vercel/transport/run-output-stream.d.ts +6 -8
- package/dist/version.d.ts +1 -1
- package/package.json +2 -2
- package/src/constants.ts +2 -2
- package/src/core/agent.ts +43 -19
- package/src/core/channel-options.ts +89 -0
- package/src/core/codec/codec-event.ts +27 -0
- package/src/core/codec/decoder.ts +145 -21
- package/src/core/codec/define-codec.ts +432 -0
- package/src/core/codec/encoder.ts +13 -54
- package/src/core/codec/field-bag.ts +142 -0
- package/src/core/codec/fields.ts +193 -0
- package/src/core/codec/index.ts +43 -0
- package/src/core/codec/input-descriptor-decoder.ts +97 -0
- package/src/core/codec/input-descriptor-encoder.ts +150 -0
- package/src/core/codec/input-descriptors.ts +373 -0
- package/src/core/codec/output-descriptor-decoder.ts +139 -0
- package/src/core/codec/output-descriptor-encoder.ts +101 -0
- package/src/core/codec/output-descriptors.ts +307 -0
- package/src/core/codec/types.ts +99 -36
- package/src/core/codec/well-known-inputs.ts +96 -0
- package/src/core/transport/agent-session.ts +330 -589
- package/src/core/transport/agent-view.ts +738 -0
- package/src/core/transport/client-session.ts +74 -69
- package/src/core/transport/decode-fold.ts +57 -47
- package/src/core/transport/headers.ts +57 -4
- package/src/core/transport/index.ts +2 -1
- package/src/core/transport/invocation.ts +1 -1
- package/src/core/transport/load-history-pages.ts +220 -0
- package/src/core/transport/load-history.ts +63 -61
- package/src/core/transport/pipe-stream.ts +10 -1
- package/src/core/transport/run-manager.ts +25 -31
- package/src/core/transport/session-support.ts +96 -0
- package/src/core/transport/tree.ts +414 -47
- package/src/core/transport/types/agent.ts +129 -102
- package/src/core/transport/types/client.ts +49 -13
- package/src/core/transport/types/tree.ts +61 -12
- package/src/core/transport/types/view.ts +57 -28
- package/src/core/transport/view.ts +520 -172
- package/src/core/transport/wire-log.ts +189 -0
- package/src/errors.ts +10 -3
- package/src/index.ts +44 -11
- package/src/react/contexts/client-session-context.ts +1 -1
- package/src/react/contexts/client-session-provider.tsx +38 -2
- package/src/react/index.ts +2 -1
- package/src/react/internal/skipped-session.ts +62 -0
- package/src/react/use-client-session.ts +7 -30
- package/src/react/use-view.ts +3 -3
- package/src/utils.ts +31 -97
- package/src/vercel/codec/decode-lifecycle.ts +70 -0
- package/src/vercel/codec/events.ts +1 -3
- package/src/vercel/codec/fields.ts +58 -0
- package/src/vercel/codec/fold-content.ts +54 -0
- package/src/vercel/codec/fold-data.ts +46 -0
- package/src/vercel/codec/fold-input.ts +255 -0
- package/src/vercel/codec/fold-lifecycle.ts +85 -0
- package/src/vercel/codec/fold-text.ts +55 -0
- package/src/vercel/codec/fold-tool-input.ts +86 -0
- package/src/vercel/codec/fold-tool-output.ts +79 -0
- package/src/vercel/codec/index.ts +23 -63
- package/src/vercel/codec/inputs.ts +116 -0
- package/src/vercel/codec/outputs.ts +207 -0
- package/src/vercel/codec/reducer-state.ts +169 -0
- package/src/vercel/codec/reducer.ts +52 -838
- package/src/vercel/codec/tool-transitions.ts +1 -12
- package/src/vercel/codec/wire-data.ts +64 -0
- package/src/vercel/index.ts +1 -0
- package/src/vercel/react/contexts/chat-transport-context.ts +1 -1
- package/src/vercel/react/use-chat-transport.ts +8 -28
- package/src/vercel/react/use-message-sync.ts +5 -10
- package/src/vercel/run-end-reason.ts +95 -16
- package/src/vercel/tool-part.ts +25 -0
- package/src/vercel/transport/chat-transport.ts +10 -22
- package/src/vercel/transport/index.ts +1 -1
- package/src/vercel/transport/run-output-stream.ts +7 -8
- package/src/version.ts +1 -1
- package/dist/core/transport/branch-chain.d.ts +0 -43
- package/dist/core/transport/load-conversation.d.ts +0 -128
- package/dist/vercel/codec/decoder.d.ts +0 -9
- package/dist/vercel/codec/encoder.d.ts +0 -11
- package/src/core/transport/branch-chain.ts +0 -58
- package/src/core/transport/load-conversation.ts +0 -355
- package/src/vercel/codec/decoder.ts +0 -696
- package/src/vercel/codec/encoder.ts +0 -548
|
@@ -1,21 +1,50 @@
|
|
|
1
1
|
import * as e from "ably";
|
|
2
|
-
import {
|
|
3
|
-
import { createContext as
|
|
4
|
-
import { jsx as
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
2
|
+
import { ChannelProvider as t, useAbly as n } from "ably/react";
|
|
3
|
+
import { createContext as r, useCallback as i, useContext as a, useEffect as o, useMemo as s, useRef as c, useState as l } from "react";
|
|
4
|
+
import { jsx as u } from "react/jsx-runtime";
|
|
5
|
+
//#region src/core/channel-options.ts
|
|
6
|
+
var d = [
|
|
7
|
+
"PUBLISH",
|
|
8
|
+
"SUBSCRIBE",
|
|
9
|
+
"PRESENCE",
|
|
10
|
+
"PRESENCE_SUBSCRIBE",
|
|
11
|
+
"ANNOTATION_PUBLISH"
|
|
12
|
+
], f = ["OBJECT_SUBSCRIBE", "OBJECT_PUBLISH"], p = [
|
|
13
|
+
"PUBLISH",
|
|
14
|
+
"SUBSCRIBE",
|
|
15
|
+
"PRESENCE",
|
|
16
|
+
"PRESENCE_SUBSCRIBE",
|
|
17
|
+
"OBJECT_PUBLISH",
|
|
18
|
+
"OBJECT_SUBSCRIBE",
|
|
19
|
+
"ANNOTATION_PUBLISH",
|
|
20
|
+
"ANNOTATION_SUBSCRIBE"
|
|
21
|
+
], m = (e) => {
|
|
22
|
+
if (e === void 0 || e.length === 0) return;
|
|
23
|
+
let t = new Set([...d, ...e]), n = p.filter((e) => t.has(e)), r = [...t].filter((e) => !p.includes(e)).toSorted();
|
|
24
|
+
return [...n, ...r];
|
|
25
|
+
}, h = "0.3.0", g = "ai-transport-js", _ = (e, t) => {
|
|
26
|
+
let n = e;
|
|
27
|
+
return n.options.agents = {
|
|
28
|
+
...n.options.agents,
|
|
29
|
+
...t
|
|
30
|
+
}, { params: { agent: y(t) } };
|
|
31
|
+
}, v = (e) => {
|
|
32
|
+
let t = e?.adapterTag, n = { [g]: h };
|
|
33
|
+
return t && (n[t] = h), n;
|
|
34
|
+
}, y = (e) => Object.entries(e).map(([e, t]) => `${e}/${t}`).join(" "), b = (e) => y(v(e)), x = (e, t) => _(e, v(t)), S = "stream", C = "status", w = "run-id", T = "invocation-id", E = "event-id", D = "codec-message-id", ee = "run-client-id", te = "input-client-id", O = "role", k = "parent", A = "fork-of", j = "msg-regenerate", M = "input-codec-message-id", ne = "error-code", re = "ai-cancel", N = /* @__PURE__ */ function(e) {
|
|
35
|
+
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[e.HistoryFetchFailed = 104011] = "HistoryFetchFailed", e;
|
|
36
|
+
}({}), ie = (e) => ({
|
|
8
37
|
logAction: (t, n, r) => {
|
|
9
38
|
e.error(n, { detail: r });
|
|
10
39
|
},
|
|
11
40
|
shouldLog: () => !0
|
|
12
|
-
}),
|
|
41
|
+
}), ae = e.Realtime.EventEmitter, P = class extends ae {
|
|
13
42
|
constructor(e) {
|
|
14
|
-
super(
|
|
43
|
+
super(ie(e));
|
|
15
44
|
}
|
|
16
|
-
},
|
|
45
|
+
}, oe = /* @__PURE__ */ function(e) {
|
|
17
46
|
return e.Trace = "trace", e.Debug = "debug", e.Info = "info", e.Warn = "warn", e.Error = "error", e.Silent = "silent", e;
|
|
18
|
-
}({}),
|
|
47
|
+
}({}), se = (e, t, n) => {
|
|
19
48
|
let r = n ? `, context: ${JSON.stringify(n)}` : "", i = `[${(/* @__PURE__ */ new Date()).toISOString()}] ${t.valueOf().toUpperCase()} ably-ai-transport: ${e}${r}`;
|
|
20
49
|
switch (t) {
|
|
21
50
|
case "trace":
|
|
@@ -33,18 +62,18 @@ var u = "status", d = "run-id", f = "invocation-id", p = "event-id", m = "codec-
|
|
|
33
62
|
break;
|
|
34
63
|
case "silent": break;
|
|
35
64
|
}
|
|
36
|
-
},
|
|
65
|
+
}, ce = (e) => new ue(e.logHandler ?? se, e.logLevel), le = new Map([
|
|
37
66
|
["trace", 0],
|
|
38
67
|
["debug", 1],
|
|
39
68
|
["info", 2],
|
|
40
69
|
["warn", 3],
|
|
41
70
|
["error", 4],
|
|
42
71
|
["silent", 5]
|
|
43
|
-
]),
|
|
72
|
+
]), ue = class t {
|
|
44
73
|
constructor(t, n, r) {
|
|
45
74
|
this._handler = t, this._context = r;
|
|
46
|
-
let i =
|
|
47
|
-
if (i === void 0) throw new e.ErrorInfo(`unable to create logger; invalid log level: ${n}`,
|
|
75
|
+
let i = le.get(n);
|
|
76
|
+
if (i === void 0) throw new e.ErrorInfo(`unable to create logger; invalid log level: ${n}`, N.InvalidArgument, 400);
|
|
48
77
|
this._levelNumber = i;
|
|
49
78
|
}
|
|
50
79
|
trace(e, t) {
|
|
@@ -63,7 +92,7 @@ var u = "status", d = "run-id", f = "invocation-id", p = "event-id", m = "codec-
|
|
|
63
92
|
this._write(e, "error", 4, t);
|
|
64
93
|
}
|
|
65
94
|
withContext(e) {
|
|
66
|
-
let n = [...
|
|
95
|
+
let n = [...le.entries()].find(([, e]) => e === this._levelNumber)?.[0] ?? "error";
|
|
67
96
|
return new t(this._handler, n, this._mergeContext(e));
|
|
68
97
|
}
|
|
69
98
|
_write(e, t, n, r) {
|
|
@@ -75,82 +104,89 @@ var u = "status", d = "run-id", f = "invocation-id", p = "event-id", m = "codec-
|
|
|
75
104
|
...e
|
|
76
105
|
} : this._context : e ?? void 0;
|
|
77
106
|
}
|
|
78
|
-
},
|
|
107
|
+
}, F = (e) => e instanceof Error ? e.message : String(e), I = (t) => t instanceof e.ErrorInfo ? t : void 0, de = (e, t) => {
|
|
79
108
|
let n = e.extras;
|
|
80
109
|
if (!n || typeof n != "object") return {};
|
|
81
110
|
let r = n.ai;
|
|
82
111
|
if (!r || typeof r != "object") return {};
|
|
83
112
|
let i = r[t];
|
|
84
113
|
return !i || typeof i != "object" ? {} : i;
|
|
85
|
-
},
|
|
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) => {
|
|
114
|
+
}, L = (e) => de(e, "transport"), fe = (e) => {
|
|
95
115
|
let t = {
|
|
96
|
-
[
|
|
97
|
-
[
|
|
116
|
+
[O]: e.role,
|
|
117
|
+
[D]: e.codecMessageId
|
|
98
118
|
};
|
|
99
|
-
return e.runId !== void 0 && (t[
|
|
100
|
-
},
|
|
101
|
-
let r = t[
|
|
102
|
-
|
|
103
|
-
|
|
119
|
+
return e.runId !== void 0 && (t[w] = e.runId), e.runClientId !== void 0 && (t[ee] = e.runClientId), e.parent && (t[k] = e.parent), e.forkOf && (t[A] = e.forkOf), e.regenerates && (t[j] = e.regenerates), e.invocationId && (t[T] = e.invocationId), e.inputClientId !== void 0 && (t[te] = e.inputClientId), e.inputCodecMessageId !== void 0 && (t[M] = e.inputCodecMessageId), e.inputEventId && (t[E] = e.inputEventId), t;
|
|
120
|
+
}, pe = (e) => e === "ai-run-start" || e === "ai-run-suspend" || e === "ai-run-resume" || e === "ai-run-end", R = (t) => {
|
|
121
|
+
let n = t[ne], r = n === void 0 ? NaN : Number(n), i = Number.isFinite(r) ? r : N.SessionSubscriptionError, a = t["error-message"] ?? "agent reported an error", o = i >= 1e4 && i < 6e4 ? Math.floor(i / 100) : 500;
|
|
122
|
+
return new e.ErrorInfo(a, i, o);
|
|
123
|
+
}, me = (e, t, n, r) => {
|
|
124
|
+
let i = t[w];
|
|
125
|
+
if (!i) return;
|
|
126
|
+
let a = t["run-client-id"] ?? "", o = r === void 0 ? {} : { timestamp: r };
|
|
104
127
|
if (e === "ai-run-start") {
|
|
105
|
-
let e = t[
|
|
128
|
+
let e = t[k], r = t[A], s = t[j];
|
|
106
129
|
return {
|
|
107
130
|
type: "start",
|
|
108
|
-
runId:
|
|
109
|
-
clientId:
|
|
131
|
+
runId: i,
|
|
132
|
+
clientId: a,
|
|
110
133
|
serial: n,
|
|
111
134
|
invocationId: t["invocation-id"] ?? "",
|
|
135
|
+
...o,
|
|
112
136
|
...e !== void 0 && { parent: e },
|
|
113
|
-
...
|
|
114
|
-
...
|
|
137
|
+
...r !== void 0 && { forkOf: r },
|
|
138
|
+
...s !== void 0 && { regenerates: s }
|
|
115
139
|
};
|
|
116
140
|
}
|
|
117
141
|
if (e === "ai-run-suspend") return {
|
|
118
142
|
type: "suspend",
|
|
119
|
-
runId:
|
|
120
|
-
clientId:
|
|
143
|
+
runId: i,
|
|
144
|
+
clientId: a,
|
|
121
145
|
serial: n,
|
|
122
|
-
invocationId: t["invocation-id"] ?? ""
|
|
146
|
+
invocationId: t["invocation-id"] ?? "",
|
|
147
|
+
...o
|
|
123
148
|
};
|
|
124
149
|
if (e === "ai-run-resume") return {
|
|
125
150
|
type: "resume",
|
|
126
|
-
runId:
|
|
127
|
-
clientId:
|
|
151
|
+
runId: i,
|
|
152
|
+
clientId: a,
|
|
128
153
|
serial: n,
|
|
129
|
-
invocationId: t["invocation-id"] ?? ""
|
|
154
|
+
invocationId: t["invocation-id"] ?? "",
|
|
155
|
+
...o
|
|
130
156
|
};
|
|
131
157
|
if (e === "ai-run-end") {
|
|
132
|
-
let e = t["run-reason"] ?? "complete";
|
|
133
|
-
return {
|
|
158
|
+
let e = t["run-reason"] ?? "complete", r = t["invocation-id"] ?? "";
|
|
159
|
+
return e === "error" ? {
|
|
134
160
|
type: "end",
|
|
135
|
-
runId:
|
|
136
|
-
clientId:
|
|
161
|
+
runId: i,
|
|
162
|
+
clientId: a,
|
|
137
163
|
serial: n,
|
|
138
|
-
invocationId:
|
|
139
|
-
reason: e
|
|
164
|
+
invocationId: r,
|
|
165
|
+
reason: e,
|
|
166
|
+
...o,
|
|
167
|
+
error: R(t)
|
|
168
|
+
} : {
|
|
169
|
+
type: "end",
|
|
170
|
+
runId: i,
|
|
171
|
+
clientId: a,
|
|
172
|
+
serial: n,
|
|
173
|
+
invocationId: r,
|
|
174
|
+
reason: e,
|
|
175
|
+
...o
|
|
140
176
|
};
|
|
141
177
|
}
|
|
142
|
-
},
|
|
143
|
-
let r =
|
|
144
|
-
if (
|
|
145
|
-
let t =
|
|
178
|
+
}, he = (e, t, n) => {
|
|
179
|
+
let r = L(n), i = n.serial, a = n.timestamp;
|
|
180
|
+
if (pe(n.name)) {
|
|
181
|
+
let t = me(n.name, r, i, a);
|
|
146
182
|
return t && e.applyRunLifecycle(t), t;
|
|
147
183
|
}
|
|
148
|
-
let { inputs:
|
|
149
|
-
(
|
|
150
|
-
inputs:
|
|
151
|
-
outputs:
|
|
152
|
-
}, r, i);
|
|
153
|
-
},
|
|
184
|
+
let { inputs: o, outputs: s } = t.decode(n);
|
|
185
|
+
(o.length > 0 || s.length > 0 || r["run-id"]) && e.applyMessage({
|
|
186
|
+
inputs: o,
|
|
187
|
+
outputs: s
|
|
188
|
+
}, r, i, a, n.version.serial);
|
|
189
|
+
}, ge = (e, t) => ({ apply: (n) => he(e, t, n) }), _e = class e {
|
|
154
190
|
constructor(e) {
|
|
155
191
|
this.inputEventId = e.inputEventId, this.sessionName = e.sessionName;
|
|
156
192
|
}
|
|
@@ -163,22 +199,80 @@ var u = "status", d = "run-id", f = "invocation-id", p = "event-id", m = "codec-
|
|
|
163
199
|
sessionName: this.sessionName
|
|
164
200
|
};
|
|
165
201
|
}
|
|
166
|
-
},
|
|
202
|
+
}, ve = async (t, n) => {
|
|
203
|
+
if (!t) throw new e.ErrorInfo(`unable to ${n}; connect() must be called before ${n}()`, N.InvalidArgument, 400);
|
|
204
|
+
return t;
|
|
205
|
+
}, ye = async (e, t, n, r) => {
|
|
206
|
+
if (t !== void 0) try {
|
|
207
|
+
await e.detach();
|
|
208
|
+
} catch (e) {
|
|
209
|
+
n?.debug(`${r}.close(); channel detach failed`, { error: e });
|
|
210
|
+
}
|
|
211
|
+
}, be = (e) => {
|
|
212
|
+
let { current: t, resumed: n } = e;
|
|
213
|
+
return t === "failed" || t === "suspended" || t === "detached" || t === "attached" && !n;
|
|
214
|
+
}, xe = (t, n) => {
|
|
215
|
+
let { current: r } = t;
|
|
216
|
+
return new e.ErrorInfo(`unable to ${n}; channel continuity lost (${r}${r === "attached" ? ", resumed: false" : ""})`, N.ChannelContinuityLost, 500, t.reason);
|
|
217
|
+
}, z = (e) => [...e.inputs.map((e) => ({
|
|
218
|
+
direction: "input",
|
|
219
|
+
event: e
|
|
220
|
+
})), ...e.outputs.map((e) => ({
|
|
221
|
+
direction: "output",
|
|
222
|
+
event: e
|
|
223
|
+
}))], Se = class {
|
|
224
|
+
constructor() {
|
|
225
|
+
this._entries = [], this._swept = !1;
|
|
226
|
+
}
|
|
227
|
+
get swept() {
|
|
228
|
+
return this._swept;
|
|
229
|
+
}
|
|
230
|
+
record(e, t, n, r, i) {
|
|
231
|
+
let a = this._recordEntry(e, t, this._swept ? [] : n, r, i);
|
|
232
|
+
return a === void 0 ? "dropped" : this._swept || a === this._entries.length - 1 ? "incremental" : "refold";
|
|
233
|
+
}
|
|
234
|
+
replay(e) {
|
|
235
|
+
for (let t of this._entries) for (let n of t.events) e(n, t.serial, t.messageId);
|
|
236
|
+
}
|
|
237
|
+
sweep() {
|
|
238
|
+
this._swept = !0;
|
|
239
|
+
for (let e of this._entries) e.events.length = 0;
|
|
240
|
+
}
|
|
241
|
+
_recordEntry(e, t, n, r, i) {
|
|
242
|
+
for (let a = this._entries.length - 1; a >= 0; a--) {
|
|
243
|
+
let o = this._entries[a];
|
|
244
|
+
if (!o) break;
|
|
245
|
+
if (o.serial === e) return r !== void 0 && (r <= o.decodedThrough || !i) ? void 0 : (o.events.push(...n), r !== void 0 && (o.decodedThrough = r), a);
|
|
246
|
+
if (o.serial < e) return this._entries.splice(a + 1, 0, {
|
|
247
|
+
serial: e,
|
|
248
|
+
messageId: t,
|
|
249
|
+
events: [...n],
|
|
250
|
+
decodedThrough: r ?? e
|
|
251
|
+
}), a + 1;
|
|
252
|
+
}
|
|
253
|
+
return this._entries.unshift({
|
|
254
|
+
serial: e,
|
|
255
|
+
messageId: t,
|
|
256
|
+
events: [...n],
|
|
257
|
+
decodedThrough: r ?? e
|
|
258
|
+
}), 0;
|
|
259
|
+
}
|
|
260
|
+
}, B = (e) => e.kind === "run" ? e.runId : e.codecMessageId, V = (e) => e.kind === "run" ? e.startSerial : e.serial, H = (e, t, n) => {
|
|
167
261
|
let r = e.get(t);
|
|
168
262
|
r || (r = /* @__PURE__ */ new Set(), e.set(t, r)), r.add(n);
|
|
169
|
-
},
|
|
263
|
+
}, U = (e, t, n) => {
|
|
170
264
|
let r = e.get(t);
|
|
171
265
|
r && (r.delete(n), r.size === 0 && e.delete(t));
|
|
172
|
-
},
|
|
266
|
+
}, Ce = class {
|
|
173
267
|
constructor(e, t) {
|
|
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
|
|
268
|
+
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._eventIdIndex = /* @__PURE__ */ new Map(), this._clock = 0, this._sweepQueue = [], this._codec = e, this._logger = t, this._emitter = new P(t);
|
|
175
269
|
}
|
|
176
270
|
_compareNodes(e, t) {
|
|
177
|
-
let n =
|
|
271
|
+
let n = V(e.node), r = V(t.node);
|
|
178
272
|
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;
|
|
179
273
|
}
|
|
180
274
|
_insertSortedNode(e) {
|
|
181
|
-
if (
|
|
275
|
+
if (V(e.node) === void 0) {
|
|
182
276
|
this._sortedNodes.push(e);
|
|
183
277
|
return;
|
|
184
278
|
}
|
|
@@ -208,28 +302,94 @@ var u = "status", d = "run-id", f = "invocation-id", p = "event-id", m = "codec-
|
|
|
208
302
|
});
|
|
209
303
|
} catch (t) {
|
|
210
304
|
this._logger.error("Tree._foldInto(); fold threw", {
|
|
211
|
-
key:
|
|
305
|
+
key: B(e.node),
|
|
212
306
|
messageId: r,
|
|
213
307
|
err: t
|
|
214
308
|
});
|
|
215
309
|
}
|
|
216
310
|
}
|
|
311
|
+
_recordAndFold(e, t, n, r, i, a) {
|
|
312
|
+
if (n === void 0 || t.length === 0) {
|
|
313
|
+
n === void 0 && t.length > 0 && (e.optimistic = !0), this._foldInto(e, t, n, r);
|
|
314
|
+
return;
|
|
315
|
+
}
|
|
316
|
+
let o = e.log.record(n, r, t, i, a);
|
|
317
|
+
if (o === "dropped") {
|
|
318
|
+
this._logger.debug("Tree._recordAndFold(); version guard dropped re-delivered wire", {
|
|
319
|
+
key: B(e.node),
|
|
320
|
+
serial: n,
|
|
321
|
+
version: i,
|
|
322
|
+
swept: e.log.swept
|
|
323
|
+
});
|
|
324
|
+
return;
|
|
325
|
+
}
|
|
326
|
+
if (e.optimistic && !e.log.swept) {
|
|
327
|
+
e.optimistic = !1, this._refold(e);
|
|
328
|
+
return;
|
|
329
|
+
}
|
|
330
|
+
if (o === "refold") {
|
|
331
|
+
this._refold(e);
|
|
332
|
+
return;
|
|
333
|
+
}
|
|
334
|
+
e.log.swept && this._logger.warn("Tree._recordAndFold(); late wire after log retention window; folding in arrival order", {
|
|
335
|
+
key: B(e.node),
|
|
336
|
+
serial: n
|
|
337
|
+
}), this._foldInto(e, t, n, r);
|
|
338
|
+
}
|
|
339
|
+
_refold(e) {
|
|
340
|
+
let t = this._codec.init();
|
|
341
|
+
e.log.replay((n, r, i) => {
|
|
342
|
+
try {
|
|
343
|
+
t = this._codec.fold(t, n, {
|
|
344
|
+
serial: r,
|
|
345
|
+
messageId: i
|
|
346
|
+
});
|
|
347
|
+
} catch (t) {
|
|
348
|
+
this._logger.error("Tree._refold(); fold threw", {
|
|
349
|
+
key: B(e.node),
|
|
350
|
+
messageId: i,
|
|
351
|
+
err: t
|
|
352
|
+
});
|
|
353
|
+
}
|
|
354
|
+
}), e.node.projection = t;
|
|
355
|
+
}
|
|
356
|
+
_recordActivity(e, t) {
|
|
357
|
+
t !== void 0 && (t > e.lastActivityTs && (e.lastActivityTs = t), t > this._clock && (this._clock = t, this._drainSweepQueue()));
|
|
358
|
+
}
|
|
359
|
+
_maybeQueueSweep(e) {
|
|
360
|
+
let t = e.node;
|
|
361
|
+
t.kind === "run" && (e.log.swept || e.sweepQueued || e.runStartSeen && (t.state.status === "active" || t.state.status === "suspended" || (e.sweepQueued = !0, this._sweepQueue.push(t.runId))));
|
|
362
|
+
}
|
|
363
|
+
_drainSweepQueue() {
|
|
364
|
+
for (; this._sweepQueue.length > 0;) {
|
|
365
|
+
let e = this._sweepQueue[0], t = e === void 0 ? void 0 : this._nodeIndex.get(e);
|
|
366
|
+
if (!t || t.log.swept) {
|
|
367
|
+
this._sweepQueue.shift();
|
|
368
|
+
continue;
|
|
369
|
+
}
|
|
370
|
+
if (t.lastActivityTs + 12e4 >= this._clock) return;
|
|
371
|
+
this._sweepQueue.shift(), t.sweepQueued = !1, t.log.sweep(), this._logger.debug("Tree._drainSweepQueue(); dropped event-log payloads, kept replay keys", {
|
|
372
|
+
key: e,
|
|
373
|
+
lastActivityTs: t.lastActivityTs
|
|
374
|
+
});
|
|
375
|
+
}
|
|
376
|
+
}
|
|
217
377
|
_addToParentIndex(e, t) {
|
|
218
|
-
|
|
378
|
+
H(this._parentIndex, e, t);
|
|
219
379
|
}
|
|
220
380
|
_removeFromParentIndex(e, t) {
|
|
221
|
-
|
|
381
|
+
U(this._parentIndex, e, t);
|
|
222
382
|
}
|
|
223
383
|
_parentKeyOf(e) {
|
|
224
384
|
let t = e.parentCodecMessageId;
|
|
225
385
|
return t === void 0 ? void 0 : this._codecMessageIdToNodeKey.get(t);
|
|
226
386
|
}
|
|
227
387
|
_inputGroupRoot(e) {
|
|
228
|
-
let t = e, n = new Set([
|
|
388
|
+
let t = e, n = new Set([B(t)]);
|
|
229
389
|
for (; t.forkOf !== void 0 && !n.has(t.forkOf);) {
|
|
230
390
|
let e = this._nodeIndex.get(t.forkOf);
|
|
231
391
|
if (e?.node.kind !== "input" || e.node.parentCodecMessageId !== t.parentCodecMessageId) break;
|
|
232
|
-
t = e.node, n.add(
|
|
392
|
+
t = e.node, n.add(B(t));
|
|
233
393
|
}
|
|
234
394
|
return t;
|
|
235
395
|
}
|
|
@@ -247,47 +407,47 @@ var u = "status", d = "run-id", f = "invocation-id", p = "event-id", m = "codec-
|
|
|
247
407
|
t && this._isSiblingOf(t.node, r) && a.push(t);
|
|
248
408
|
}
|
|
249
409
|
a.sort((e, t) => this._compareNodes(e, t));
|
|
250
|
-
for (let e of a) this._siblingCache.set(
|
|
410
|
+
for (let e of a) this._siblingCache.set(B(e.node), a);
|
|
251
411
|
return this._siblingCache.set(e, a), a;
|
|
252
412
|
}
|
|
253
413
|
_isSiblingOf(e, t) {
|
|
254
414
|
if (e.kind !== t.kind || e.parentCodecMessageId !== t.parentCodecMessageId) return !1;
|
|
255
415
|
if (e.kind === "run") return !0;
|
|
256
|
-
let n =
|
|
257
|
-
if (
|
|
258
|
-
let r = e, i = new Set([
|
|
416
|
+
let n = B(t);
|
|
417
|
+
if (B(e) === n) return !0;
|
|
418
|
+
let r = e, i = new Set([B(r)]);
|
|
259
419
|
for (; r.kind === "input" && r.forkOf !== void 0;) {
|
|
260
420
|
if (r.forkOf === n) return !0;
|
|
261
421
|
if (i.has(r.forkOf)) break;
|
|
262
422
|
let e = this._nodeIndex.get(r.forkOf);
|
|
263
423
|
if (!e) break;
|
|
264
|
-
r = e.node, i.add(
|
|
424
|
+
r = e.node, i.add(B(r));
|
|
265
425
|
}
|
|
266
426
|
return !1;
|
|
267
427
|
}
|
|
268
428
|
getGroupRoot(e) {
|
|
269
429
|
let t = this._nodeIndex.get(e);
|
|
270
430
|
if (!t) return e;
|
|
271
|
-
if (t.node.kind === "input") return
|
|
431
|
+
if (t.node.kind === "input") return B(this._inputGroupRoot(t.node));
|
|
272
432
|
let n = this._getSiblingGroup(e)[0]?.node;
|
|
273
|
-
return n ?
|
|
433
|
+
return n ? B(n) : e;
|
|
274
434
|
}
|
|
275
435
|
visibleNodes(e = /* @__PURE__ */ new Map()) {
|
|
276
436
|
this._logger.trace("DefaultTree.visibleNodes();");
|
|
277
437
|
let t = [], n = /* @__PURE__ */ new Set(), r = /* @__PURE__ */ new Map();
|
|
278
438
|
for (let i of this._sortedNodes) {
|
|
279
|
-
let a = i.node, o =
|
|
439
|
+
let a = i.node, o = B(a), s = this._parentKeyOf(a);
|
|
280
440
|
if (s !== void 0 && !n.has(s)) continue;
|
|
281
441
|
let c = this._getSiblingGroup(o);
|
|
282
442
|
if (c.length > 1) {
|
|
283
443
|
let t = this.getGroupRoot(o), n = r.get(t);
|
|
284
444
|
if (n === void 0) {
|
|
285
445
|
let i = e.get(t);
|
|
286
|
-
if (i !== void 0 && c.some((e) =>
|
|
446
|
+
if (i !== void 0 && c.some((e) => B(e.node) === i)) n = i;
|
|
287
447
|
else {
|
|
288
448
|
let e = c.at(-1);
|
|
289
449
|
if (!e) break;
|
|
290
|
-
n =
|
|
450
|
+
n = B(e.node);
|
|
291
451
|
}
|
|
292
452
|
r.set(t, n);
|
|
293
453
|
}
|
|
@@ -323,23 +483,23 @@ var u = "status", d = "run-id", f = "invocation-id", p = "event-id", m = "codec-
|
|
|
323
483
|
getSiblingNodes(e) {
|
|
324
484
|
return this._logger.trace("DefaultTree.getSiblingNodes();", { key: e }), this._getSiblingGroup(e).map((e) => e.node);
|
|
325
485
|
}
|
|
326
|
-
applyMessage(e, t, n) {
|
|
327
|
-
let
|
|
328
|
-
if (
|
|
486
|
+
applyMessage(e, t, n, r, i) {
|
|
487
|
+
let a = t[w], o = t[D], s = a === void 0 && o !== void 0 && t.role === "user" && e.inputs.length > 0 ? o : void 0;
|
|
488
|
+
if (a === void 0 && s === void 0) {
|
|
329
489
|
this._logger.warn("Tree.applyMessage(); message has no run-id and is not a user input; skipping");
|
|
330
490
|
return;
|
|
331
491
|
}
|
|
332
|
-
let
|
|
333
|
-
if (
|
|
334
|
-
let
|
|
335
|
-
|
|
336
|
-
}
|
|
337
|
-
_applyInputMessage(e, t, n, r) {
|
|
338
|
-
let
|
|
339
|
-
|
|
492
|
+
let c = z(e), l = s ?? a;
|
|
493
|
+
if (c.length === 0 && l !== void 0 && !this._nodeIndex.has(l)) return;
|
|
494
|
+
let u = this._structuralVersion;
|
|
495
|
+
s === void 0 ? a !== void 0 && this._applyRunMessage(a, e, t, n, r, i) : this._applyInputMessage(s, t, n, r, i, c), this._structuralVersion !== u && this._emitter.emit("update");
|
|
496
|
+
}
|
|
497
|
+
_applyInputMessage(e, t, n, r, i, a) {
|
|
498
|
+
let o = this._nodeIndex.get(e);
|
|
499
|
+
o ? o.node.kind === "input" && n && !o.node.serial && (this._logger.debug("Tree.applyMessage(); promoting input serial", {
|
|
340
500
|
codecMessageId: e,
|
|
341
501
|
serial: n
|
|
342
|
-
}),
|
|
502
|
+
}), o.node.serial = n, this._promoteSerial(o)) : (o = this._createInputNodeFromHeaders(e, t, n), this._insertNode(e, o, o.node.parentCodecMessageId), this._codecMessageIdToNodeKey.set(e, e), this._logger.debug("Tree.applyMessage(); created input node", { codecMessageId: e })), this._recordActivity(o, r), this._recordAndFold(o, a, n, e, i, t[S] === "true"), this._emitter.emit("output", {
|
|
343
503
|
runId: void 0,
|
|
344
504
|
inputCodecMessageId: e,
|
|
345
505
|
codecMessageId: e,
|
|
@@ -347,27 +507,27 @@ var u = "status", d = "run-id", f = "invocation-id", p = "event-id", m = "codec-
|
|
|
347
507
|
events: []
|
|
348
508
|
});
|
|
349
509
|
}
|
|
350
|
-
_applyRunMessage(e, t, n, r) {
|
|
351
|
-
let
|
|
352
|
-
if (!
|
|
353
|
-
let e = this._codecMessageIdToNodeKey.get(
|
|
354
|
-
t?.node.kind === "run" && t.node.startSerial === void 0 && (
|
|
510
|
+
_applyRunMessage(e, t, n, r, i, a) {
|
|
511
|
+
let o = n[D], s = n[M], c = z(t), l = t.outputs, u = this._nodeIndex.get(e);
|
|
512
|
+
if (!u && o !== void 0) {
|
|
513
|
+
let e = this._codecMessageIdToNodeKey.get(o), t = e === void 0 ? void 0 : this._nodeIndex.get(e);
|
|
514
|
+
t?.node.kind === "run" && t.node.startSerial === void 0 && (u = t);
|
|
355
515
|
}
|
|
356
|
-
|
|
516
|
+
u ? r && u.node.kind === "run" && !u.node.startSerial && (this._logger.debug("Tree.applyMessage(); promoting startSerial", {
|
|
357
517
|
runId: e,
|
|
358
518
|
serial: r
|
|
359
|
-
}),
|
|
360
|
-
let
|
|
361
|
-
|
|
362
|
-
runId:
|
|
363
|
-
inputCodecMessageId:
|
|
364
|
-
codecMessageId:
|
|
519
|
+
}), u.node.startSerial = r, this._promoteSerial(u)) : (u = this._createRunFromHeaders(e, n, r), this._insertNode(e, u, u.node.parentCodecMessageId), this._indexReplyRun(u.node, e), this._logger.debug("Tree.applyMessage(); created new Run", { runId: e }));
|
|
520
|
+
let d = B(u.node);
|
|
521
|
+
o && this._codecMessageIdToNodeKey.set(o, d), this._recordActivity(u, i), this._recordAndFold(u, c, r, o, a, n[S] === "true"), this._emitter.emit("output", {
|
|
522
|
+
runId: d,
|
|
523
|
+
inputCodecMessageId: s,
|
|
524
|
+
codecMessageId: o,
|
|
365
525
|
serial: r,
|
|
366
|
-
events:
|
|
526
|
+
events: l
|
|
367
527
|
});
|
|
368
528
|
}
|
|
369
529
|
_indexReplyRun(e, t) {
|
|
370
|
-
e.parentCodecMessageId !== void 0 &&
|
|
530
|
+
e.parentCodecMessageId !== void 0 && H(this._replyRunsByInput, e.parentCodecMessageId, t);
|
|
371
531
|
}
|
|
372
532
|
applyRunLifecycle(e) {
|
|
373
533
|
this._logger.trace("DefaultTree.applyRunLifecycle();", {
|
|
@@ -395,75 +555,85 @@ var u = "status", d = "run-id", f = "invocation-id", p = "event-id", m = "codec-
|
|
|
395
555
|
let t = this._nodeIndex.get(e.runId);
|
|
396
556
|
if (t?.node.kind === "run") {
|
|
397
557
|
let n = t.node;
|
|
398
|
-
if (n.status
|
|
558
|
+
if (n.state.status === "suspended" && (n.state = { 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
559
|
let t = this._codecMessageIdToNodeKey.get(e.forkOf);
|
|
400
560
|
t !== void 0 && t !== e.runId && (n.forkOf = t, this._structuralVersion++);
|
|
401
561
|
}
|
|
402
|
-
n.regeneratesCodecMessageId === void 0 && e.regenerates !== void 0 && (n.regeneratesCodecMessageId = e.regenerates, this._structuralVersion++), n.invocationId === "" && e.invocationId !== "" && (n.invocationId = e.invocationId);
|
|
562
|
+
n.regeneratesCodecMessageId === void 0 && e.regenerates !== void 0 && (n.regeneratesCodecMessageId = e.regenerates, this._structuralVersion++), n.invocationId === "" && e.invocationId !== "" && (n.invocationId = e.invocationId), t.runStartSeen = !0, this._recordActivity(t, e.timestamp), this._maybeQueueSweep(t);
|
|
403
563
|
} else if (!t) {
|
|
404
564
|
let t = this._createRunFromLifecycle(e);
|
|
405
|
-
this._insertNode(e.runId, t, t.node.parentCodecMessageId), this._indexReplyRun(t.node, e.runId);
|
|
565
|
+
this._insertNode(e.runId, t, t.node.parentCodecMessageId), this._indexReplyRun(t.node, e.runId), this._recordActivity(t, e.timestamp);
|
|
406
566
|
}
|
|
407
567
|
}
|
|
408
568
|
_applyRunSuspend(e) {
|
|
409
569
|
let t = this._nodeIndex.get(e.runId);
|
|
410
|
-
t?.node.kind === "run" && (t.node.
|
|
570
|
+
t?.node.kind === "run" && (t.node.state = { status: "suspended" }, t.node.endSerial = e.serial, this._recordActivity(t, e.timestamp));
|
|
411
571
|
}
|
|
412
572
|
_applyRunResume(e) {
|
|
413
573
|
let t = this._nodeIndex.get(e.runId);
|
|
414
|
-
t?.node.kind === "run" && t.node.status === "suspended" && (t.node.
|
|
574
|
+
t?.node.kind === "run" && t.node.state.status === "suspended" && (t.node.state = { status: "active" }, this._recordActivity(t, e.timestamp));
|
|
415
575
|
}
|
|
416
576
|
_applyRunEnd(e) {
|
|
417
577
|
let t = this._nodeIndex.get(e.runId);
|
|
418
|
-
t?.node.kind === "run" && (t.node.
|
|
578
|
+
t?.node.kind === "run" && (t.node.state = e.reason === "error" ? {
|
|
579
|
+
status: "error",
|
|
580
|
+
error: e.error
|
|
581
|
+
} : { status: e.reason }, t.node.endSerial = e.serial, this._recordActivity(t, e.timestamp), this._maybeQueueSweep(t));
|
|
419
582
|
}
|
|
420
583
|
delete(e) {
|
|
421
584
|
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 &&
|
|
585
|
+
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 && U(this._replyRunsByInput, t.node.parentCodecMessageId, e), this._structuralVersion++, this._emitter.emit("update"));
|
|
423
586
|
}
|
|
424
587
|
_createRunFromHeaders(e, t, n) {
|
|
425
|
-
let r = t[
|
|
588
|
+
let r = t[A];
|
|
426
589
|
return this._buildRunNode({
|
|
427
590
|
runId: e,
|
|
428
|
-
parentCodecMessageId: t[
|
|
591
|
+
parentCodecMessageId: t[k],
|
|
429
592
|
forkOf: r ? this._codecMessageIdToNodeKey.get(r) : void 0,
|
|
430
|
-
regeneratesCodecMessageId: t[
|
|
593
|
+
regeneratesCodecMessageId: t[j],
|
|
431
594
|
clientId: t["run-client-id"] ?? "",
|
|
432
595
|
invocationId: t["invocation-id"] ?? "",
|
|
433
|
-
startSerial: n
|
|
596
|
+
startSerial: n,
|
|
597
|
+
runStartSeen: !1
|
|
434
598
|
});
|
|
435
599
|
}
|
|
436
|
-
|
|
600
|
+
_wrapNode(e, t = !1) {
|
|
437
601
|
return {
|
|
438
|
-
node:
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
602
|
+
node: e,
|
|
603
|
+
insertSeq: this._seqCounter++,
|
|
604
|
+
log: new Se(),
|
|
605
|
+
lastActivityTs: 0,
|
|
606
|
+
runStartSeen: t,
|
|
607
|
+
sweepQueued: !1,
|
|
608
|
+
optimistic: !1
|
|
609
|
+
};
|
|
610
|
+
}
|
|
611
|
+
_buildRunNode(e) {
|
|
612
|
+
let t = {
|
|
613
|
+
kind: "run",
|
|
614
|
+
runId: e.runId,
|
|
615
|
+
parentCodecMessageId: e.parentCodecMessageId,
|
|
616
|
+
forkOf: e.forkOf,
|
|
617
|
+
regeneratesCodecMessageId: e.regeneratesCodecMessageId,
|
|
618
|
+
clientId: e.clientId,
|
|
619
|
+
invocationId: e.invocationId,
|
|
620
|
+
state: { status: "active" },
|
|
621
|
+
projection: this._codec.init(),
|
|
622
|
+
startSerial: e.startSerial,
|
|
623
|
+
endSerial: void 0
|
|
452
624
|
};
|
|
625
|
+
return this._wrapNode(t, e.runStartSeen);
|
|
453
626
|
}
|
|
454
627
|
_createInputNodeFromHeaders(e, t, n) {
|
|
455
|
-
let r = t[
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
projection: this._codec.init(),
|
|
463
|
-
serial: n
|
|
464
|
-
},
|
|
465
|
-
insertSeq: this._seqCounter++
|
|
628
|
+
let r = t[A], i = {
|
|
629
|
+
kind: "input",
|
|
630
|
+
codecMessageId: e,
|
|
631
|
+
parentCodecMessageId: t[k],
|
|
632
|
+
forkOf: r,
|
|
633
|
+
projection: this._codec.init(),
|
|
634
|
+
serial: n
|
|
466
635
|
};
|
|
636
|
+
return this._wrapNode(i);
|
|
467
637
|
}
|
|
468
638
|
_createRunFromLifecycle(e) {
|
|
469
639
|
let t = e.forkOf;
|
|
@@ -474,7 +644,8 @@ var u = "status", d = "run-id", f = "invocation-id", p = "event-id", m = "codec-
|
|
|
474
644
|
regeneratesCodecMessageId: e.regenerates,
|
|
475
645
|
clientId: e.clientId,
|
|
476
646
|
invocationId: e.invocationId,
|
|
477
|
-
startSerial: e.serial
|
|
647
|
+
startSerial: e.serial,
|
|
648
|
+
runStartSeen: !0
|
|
478
649
|
});
|
|
479
650
|
}
|
|
480
651
|
on(e, t) {
|
|
@@ -484,66 +655,125 @@ var u = "status", d = "run-id", f = "invocation-id", p = "event-id", m = "codec-
|
|
|
484
655
|
};
|
|
485
656
|
}
|
|
486
657
|
emitAblyMessage(e) {
|
|
487
|
-
this._logger.trace("DefaultTree.emitAblyMessage();")
|
|
658
|
+
this._logger.trace("DefaultTree.emitAblyMessage();");
|
|
659
|
+
let t = L(e)[E];
|
|
660
|
+
t !== void 0 && !this._eventIdIndex.has(t) && this._eventIdIndex.set(t, e), this._emitter.emit("ably-message", e);
|
|
661
|
+
}
|
|
662
|
+
findAblyMessageByEventId(e) {
|
|
663
|
+
return this._eventIdIndex.get(e);
|
|
664
|
+
}
|
|
665
|
+
}, we = (e, t) => new Ce(e, t), Te = (t, n) => new Promise((r, i) => {
|
|
666
|
+
if (n?.aborted) {
|
|
667
|
+
i(new e.ErrorInfo("unable to wait; signal aborted", N.InvalidArgument, 400));
|
|
668
|
+
return;
|
|
669
|
+
}
|
|
670
|
+
let a = setTimeout(() => {
|
|
671
|
+
n?.removeEventListener("abort", o), r();
|
|
672
|
+
}, t);
|
|
673
|
+
typeof a == "object" && a.unref();
|
|
674
|
+
let o = () => {
|
|
675
|
+
clearTimeout(a), i(new e.ErrorInfo("unable to wait; signal aborted", N.InvalidArgument, 400));
|
|
676
|
+
};
|
|
677
|
+
n?.addEventListener("abort", o, { once: !0 });
|
|
678
|
+
}), Ee = async (t, n, r, i, a) => {
|
|
679
|
+
let o;
|
|
680
|
+
for (let s = 0; s <= n; s++) {
|
|
681
|
+
if (i?.aborted) throw new e.ErrorInfo("unable to fetch history page; signal aborted", N.InvalidArgument, 400, I(o));
|
|
682
|
+
try {
|
|
683
|
+
return await t();
|
|
684
|
+
} catch (e) {
|
|
685
|
+
if (o = e, s === n) break;
|
|
686
|
+
let t = r * 2 ** s;
|
|
687
|
+
a?.debug("loadHistoryPages.fetchPageWithRetry(); page fetch failed, retrying", {
|
|
688
|
+
attempt: s + 1,
|
|
689
|
+
maxRetries: n,
|
|
690
|
+
backoff: t
|
|
691
|
+
}), await Te(t, i);
|
|
692
|
+
}
|
|
488
693
|
}
|
|
489
|
-
|
|
694
|
+
throw new e.ErrorInfo(`unable to fetch history page; ${F(o)}`, N.HistoryFetchFailed, 500, I(o));
|
|
695
|
+
}, De = async (t, n) => {
|
|
696
|
+
let { pageLimit: r, untilAttach: i = !0, signal: a, maxRetries: o = 3, retryBackoffMs: s = 100, logger: c } = n;
|
|
697
|
+
if (a?.aborted) throw new e.ErrorInfo("unable to load history; signal aborted", N.InvalidArgument, 400);
|
|
698
|
+
await t.attach();
|
|
699
|
+
let l = {
|
|
700
|
+
limit: r,
|
|
701
|
+
untilAttach: i
|
|
702
|
+
}, u = await Ee(() => t.history(l), o, s, a, c), d = !1;
|
|
703
|
+
return {
|
|
704
|
+
hasNext: () => u === void 0 || a?.aborted ? !1 : d ? u.hasNext() : !0,
|
|
705
|
+
next: async () => {
|
|
706
|
+
if (u === void 0) return;
|
|
707
|
+
if (a?.aborted) throw new e.ErrorInfo("unable to load history; signal aborted", N.InvalidArgument, 400);
|
|
708
|
+
if (!d) return d = !0, u.items;
|
|
709
|
+
if (!u.hasNext()) {
|
|
710
|
+
u = void 0;
|
|
711
|
+
return;
|
|
712
|
+
}
|
|
713
|
+
let t = await Ee(async () => await u?.next() ?? void 0, o, s, a, c);
|
|
714
|
+
if (!t) {
|
|
715
|
+
u = void 0;
|
|
716
|
+
return;
|
|
717
|
+
}
|
|
718
|
+
return u = t, t.items;
|
|
719
|
+
}
|
|
720
|
+
};
|
|
721
|
+
}, Oe = (e, t) => {
|
|
490
722
|
for (let n of t) {
|
|
491
|
-
let t =
|
|
723
|
+
let t = L(n), r = t[D];
|
|
492
724
|
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[
|
|
725
|
+
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[C], c = s === "complete" || s === "cancelled";
|
|
494
726
|
(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
727
|
}
|
|
496
|
-
},
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
e.logger.debug("loadHistory.fetchUntilLimit(); fetching next page", {
|
|
728
|
+
}, W = async (e, t) => {
|
|
729
|
+
let n = e.returnedCount + t;
|
|
730
|
+
for (; e.completedCodecMessageIds.size < n && e.cursor.hasNext();) {
|
|
731
|
+
e.logger.debug("loadHistory.fetchUntilLimit(); pulling next page", {
|
|
501
732
|
collected: e.rawMessages.length,
|
|
502
733
|
completed: e.completedCodecMessageIds.size
|
|
503
734
|
});
|
|
504
|
-
let
|
|
505
|
-
if (!
|
|
506
|
-
|
|
735
|
+
let t = await e.cursor.next();
|
|
736
|
+
if (!t) break;
|
|
737
|
+
e.rawMessages.push(...t), Oe(e, t);
|
|
507
738
|
}
|
|
508
|
-
},
|
|
739
|
+
}, G = (e, t) => {
|
|
509
740
|
let n = e.completedCodecMessageIds.size, r = Math.min(t, Math.max(0, n - e.returnedCount));
|
|
510
741
|
e.returnedCount += r;
|
|
511
|
-
let i = n > e.returnedCount, a = e.
|
|
742
|
+
let i = n > e.returnedCount, a = e.cursor.hasNext(), o = e.rawMessages.length - e.returnedRawCount > 0 ? e.rawMessages.slice(e.returnedRawCount).toReversed() : [];
|
|
512
743
|
return e.returnedRawCount = e.rawMessages.length, {
|
|
513
744
|
rawMessages: o,
|
|
514
745
|
hasNext: () => i || a,
|
|
515
746
|
next: async () => {
|
|
516
|
-
if (i) return
|
|
517
|
-
if (
|
|
518
|
-
let n = await e.lastAblyPage.next();
|
|
519
|
-
if (n) return await B(e, n, t), V(e, t);
|
|
747
|
+
if (i) return G(e, t);
|
|
748
|
+
if (a) return await W(e, t), G(e, t);
|
|
520
749
|
}
|
|
521
750
|
};
|
|
522
|
-
},
|
|
523
|
-
let r = t?.limit ?? 100
|
|
751
|
+
}, ke = async (e, t, n) => {
|
|
752
|
+
let r = t?.limit ?? 100;
|
|
753
|
+
n.trace("loadHistory();", { limit: r });
|
|
754
|
+
let i = {
|
|
755
|
+
cursor: await De(e, {
|
|
756
|
+
pageLimit: r * 10,
|
|
757
|
+
untilAttach: !0,
|
|
758
|
+
logger: n
|
|
759
|
+
}),
|
|
524
760
|
rawMessages: [],
|
|
525
761
|
returnedCount: 0,
|
|
526
762
|
returnedRawCount: 0,
|
|
527
|
-
lastAblyPage: void 0,
|
|
528
763
|
startedCodecMessageIds: /* @__PURE__ */ new Set(),
|
|
529
764
|
terminatedCodecMessageIds: /* @__PURE__ */ new Set(),
|
|
530
765
|
completedCodecMessageIds: /* @__PURE__ */ new Set(),
|
|
531
766
|
logger: n
|
|
532
767
|
};
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
return await e.attach(), await B(i, await e.history({
|
|
536
|
-
untilAttach: !0,
|
|
537
|
-
limit: a
|
|
538
|
-
}), r), V(i, r);
|
|
539
|
-
}, de = (e) => Array.isArray(e) ? e : [e], fe = 3, U = (e) => ({
|
|
768
|
+
return await W(i, r), G(i, r);
|
|
769
|
+
}, Ae = (e) => Array.isArray(e) ? e : [e], K = (e) => ({
|
|
540
770
|
runId: e.runId,
|
|
541
771
|
clientId: e.clientId,
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
}),
|
|
772
|
+
invocationId: e.invocationId,
|
|
773
|
+
...e.state
|
|
774
|
+
}), je = class {
|
|
545
775
|
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
|
|
776
|
+
this._branchSelections = /* @__PURE__ */ new Map(), this._regenSelections = /* @__PURE__ */ new Map(), this._nonHeadRegenSelections = /* @__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._hiddenMessageCount = 0, 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._applier = e.applier, this._sendDelegate = e.sendDelegate, this._onClose = e.onClose, this._logger = e.logger.withContext({ component: "View" }), this._logger.trace("DefaultView();"), this._emitter = new P(this._logger), this._cachedNodes = this._computeFlatNodes(), this._updateVisibleSnapshot(this._cachedNodes), this._unsubs.push(this._tree.on("update", () => {
|
|
547
777
|
this._onTreeUpdate();
|
|
548
778
|
}), this._tree.on("ably-message", (e) => {
|
|
549
779
|
this._onTreeAblyMessage(e);
|
|
@@ -554,17 +784,17 @@ var u = "status", d = "run-id", f = "invocation-id", p = "event-id", m = "codec-
|
|
|
554
784
|
}));
|
|
555
785
|
}
|
|
556
786
|
_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"));
|
|
787
|
+
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).slice(this._hiddenMessageCount), this._emitter.emit("update"));
|
|
558
788
|
}
|
|
559
789
|
getMessages() {
|
|
560
790
|
return this._lastVisibleMessagePairs;
|
|
561
791
|
}
|
|
562
792
|
runs() {
|
|
563
|
-
return this._cachedNodes.filter((e) => e.kind === "run").map((e) =>
|
|
793
|
+
return this._cachedNodes.filter((e) => e.kind === "run").map((e) => K(e));
|
|
564
794
|
}
|
|
565
795
|
_computeFlatNodes() {
|
|
566
796
|
let e = this._treeVisibleNodes();
|
|
567
|
-
return this._withheldRunIds.size === 0 ? e : e.filter((e) => !this._withheldRunIds.has(
|
|
797
|
+
return this._withheldRunIds.size === 0 ? e : e.filter((e) => !this._withheldRunIds.has(B(e)));
|
|
568
798
|
}
|
|
569
799
|
_recomputeAndEmit() {
|
|
570
800
|
this._cachedNodes = this._computeFlatNodes(), this._updateVisibleSnapshot(this._cachedNodes), this._emitter.emit("update");
|
|
@@ -577,38 +807,64 @@ var u = "status", d = "run-id", f = "invocation-id", p = "event-id", m = "codec-
|
|
|
577
807
|
let t = this._tree.getNodeByCodecMessageId(e);
|
|
578
808
|
return t?.kind === "run" ? t : void 0;
|
|
579
809
|
}
|
|
810
|
+
_nonHeadRegenerators(e, t) {
|
|
811
|
+
return this._tree.getReplyRuns(t).filter((t) => t.regeneratesCodecMessageId === e).toSorted((e, t) => (e.startSerial ?? "").localeCompare(t.startSerial ?? ""));
|
|
812
|
+
}
|
|
813
|
+
_selectedNonHeadMember(e, t, n) {
|
|
814
|
+
let r = this._nonHeadRegenSelections.get(e);
|
|
815
|
+
return r && r.kind !== "pending" && [t, ...n.map((e) => e.runId)].includes(r.selectedRunId) ? r.selectedRunId : n.at(-1)?.runId ?? t;
|
|
816
|
+
}
|
|
580
817
|
_extractMessages(e) {
|
|
581
|
-
let t = [];
|
|
582
|
-
for (let
|
|
818
|
+
let t = [], n = /* @__PURE__ */ new Set();
|
|
819
|
+
for (let r of e) r.kind === "run" && n.has(r.runId) || this._emitNodeMessages(r, t, n);
|
|
583
820
|
return t;
|
|
584
821
|
}
|
|
822
|
+
_emitNodeMessages(e, t, n) {
|
|
823
|
+
let r = this._codec.getMessages(e.projection);
|
|
824
|
+
if (e.kind !== "run") {
|
|
825
|
+
t.push(...r);
|
|
826
|
+
return;
|
|
827
|
+
}
|
|
828
|
+
for (let i = 0; i < r.length; i++) {
|
|
829
|
+
let a = r[i];
|
|
830
|
+
if (!a) continue;
|
|
831
|
+
let o = i > 0 ? r[i - 1]?.codecMessageId : void 0;
|
|
832
|
+
if (o !== void 0) {
|
|
833
|
+
let r = this._nonHeadRegenerators(a.codecMessageId, o);
|
|
834
|
+
if (r.length > 0) {
|
|
835
|
+
for (let e of r) n.add(e.runId);
|
|
836
|
+
let i = this._selectedNonHeadMember(a.codecMessageId, e.runId, r);
|
|
837
|
+
if (i !== e.runId) {
|
|
838
|
+
let e = r.find((e) => e.runId === i);
|
|
839
|
+
if (e) {
|
|
840
|
+
this._emitNodeMessages(e, t, n);
|
|
841
|
+
return;
|
|
842
|
+
}
|
|
843
|
+
}
|
|
844
|
+
}
|
|
845
|
+
}
|
|
846
|
+
t.push(a);
|
|
847
|
+
}
|
|
848
|
+
}
|
|
585
849
|
hasOlder() {
|
|
586
|
-
return this._withheldBuffer.length > 0 || this._hasMoreHistory;
|
|
850
|
+
return this._hiddenMessageCount > 0 || this._withheldBuffer.length > 0 || this._hasMoreHistory;
|
|
587
851
|
}
|
|
588
|
-
async loadOlder(e =
|
|
852
|
+
async loadOlder(e = 10) {
|
|
589
853
|
if (!(this._closed || this._loadingOlder)) {
|
|
590
854
|
this._loadingOlder = !0, this._logger.trace("DefaultView.loadOlder();", { limit: e });
|
|
591
855
|
try {
|
|
592
|
-
if (this.
|
|
593
|
-
|
|
594
|
-
this._releaseWithheld(t);
|
|
595
|
-
return;
|
|
596
|
-
}
|
|
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;
|
|
856
|
+
if (this._hiddenMessageCount >= e) {
|
|
857
|
+
this._hiddenMessageCount -= e, this._recomputeAndEmit();
|
|
604
858
|
return;
|
|
605
859
|
}
|
|
606
|
-
let t =
|
|
607
|
-
if (this.
|
|
608
|
-
|
|
609
|
-
|
|
860
|
+
let t = e - this._hiddenMessageCount, n = this._extractMessages(this._computeFlatNodes()).length, r = () => this._extractMessages(this._computeFlatNodes()).length - n;
|
|
861
|
+
if (this._withheldBuffer.length > 0) {
|
|
862
|
+
let e = this._messageTailSplitIndex(this._withheldBuffer, t), n = this._withheldBuffer.splice(e);
|
|
863
|
+
this._releaseWithheld(n);
|
|
610
864
|
}
|
|
611
|
-
await this.
|
|
865
|
+
if (r() < t && (await this._fetchOlder(t - r()), this._closed)) return;
|
|
866
|
+
let i = this._extractMessages(this._computeFlatNodes()).length;
|
|
867
|
+
this._hiddenMessageCount = Math.max(0, this._hiddenMessageCount + (i - n) - e), this._recomputeAndEmit();
|
|
612
868
|
} catch (e) {
|
|
613
869
|
throw this._logger.error("DefaultView.loadOlder(); failed", { error: e }), e;
|
|
614
870
|
} finally {
|
|
@@ -616,13 +872,38 @@ var u = "status", d = "run-id", f = "invocation-id", p = "event-id", m = "codec-
|
|
|
616
872
|
}
|
|
617
873
|
}
|
|
618
874
|
}
|
|
875
|
+
async _fetchOlder(e) {
|
|
876
|
+
if (!this._hasMoreHistory && !this._lastHistoryPage) {
|
|
877
|
+
await this._loadFirstPage(e);
|
|
878
|
+
return;
|
|
879
|
+
}
|
|
880
|
+
if (!this._hasMoreHistory) return;
|
|
881
|
+
if (!this._lastHistoryPage?.hasNext()) {
|
|
882
|
+
this._hasMoreHistory = !1;
|
|
883
|
+
return;
|
|
884
|
+
}
|
|
885
|
+
let t = await this._lastHistoryPage.next();
|
|
886
|
+
if (this._closed || !t) {
|
|
887
|
+
t || (this._hasMoreHistory = !1);
|
|
888
|
+
return;
|
|
889
|
+
}
|
|
890
|
+
await this._revealFromPage(t, e);
|
|
891
|
+
}
|
|
892
|
+
_messageTailSplitIndex(e, t) {
|
|
893
|
+
let n = 0;
|
|
894
|
+
for (let r = e.length - 1; r >= 0; r--) {
|
|
895
|
+
let i = e[r];
|
|
896
|
+
if (i && (n += this._codec.getMessages(i.projection).length, n >= t)) return r;
|
|
897
|
+
}
|
|
898
|
+
return 0;
|
|
899
|
+
}
|
|
619
900
|
runOf(e) {
|
|
620
901
|
this._logger.trace("DefaultView.runOf();", { codecMessageId: e });
|
|
621
902
|
let t = this._tree.getNodeByCodecMessageId(e);
|
|
622
903
|
if (!t) return;
|
|
623
|
-
if (t.kind === "run") return
|
|
904
|
+
if (t.kind === "run") return K(t);
|
|
624
905
|
let n = this._selectedReplyRun(t.codecMessageId);
|
|
625
|
-
return n ?
|
|
906
|
+
return n ? K(n) : void 0;
|
|
626
907
|
}
|
|
627
908
|
_selectedReplyRun(e) {
|
|
628
909
|
let t = this._tree.getReplyRuns(e);
|
|
@@ -638,14 +919,16 @@ var u = "status", d = "run-id", f = "invocation-id", p = "event-id", m = "codec-
|
|
|
638
919
|
run(e) {
|
|
639
920
|
this._logger.trace("DefaultView.run();", { runId: e });
|
|
640
921
|
let t = this._tree.getRunNode(e);
|
|
641
|
-
return t ?
|
|
922
|
+
return t ? K(t) : void 0;
|
|
642
923
|
}
|
|
643
924
|
branchSelection(e) {
|
|
644
925
|
let t = this._resolveMessageBranchPoint(e);
|
|
645
926
|
if (t) {
|
|
646
|
-
let e = t.
|
|
647
|
-
let t = this.
|
|
648
|
-
|
|
927
|
+
let e = t.members.flatMap((e) => {
|
|
928
|
+
let t = this._tree.getNodeByCodecMessageId(e.representativeCodecMessageId);
|
|
929
|
+
if (!t) return [];
|
|
930
|
+
let n = this._codec.getMessages(t.projection).find((t) => t.codecMessageId === e.representativeCodecMessageId);
|
|
931
|
+
return n ? [n.message] : [];
|
|
649
932
|
});
|
|
650
933
|
if (e.length > 0) {
|
|
651
934
|
let n = this._resolveSelectedIndex(t), r = Math.max(0, Math.min(n, e.length - 1)), i = e[r];
|
|
@@ -681,35 +964,43 @@ var u = "status", d = "run-id", f = "invocation-id", p = "event-id", m = "codec-
|
|
|
681
964
|
});
|
|
682
965
|
let n = this._resolveMessageBranchPoint(e);
|
|
683
966
|
if (!n) return;
|
|
684
|
-
let r = Math.max(0, Math.min(t, n.
|
|
967
|
+
let r = Math.max(0, Math.min(t, n.members.length - 1)), i = n.members[r];
|
|
685
968
|
i && (n.kind === "fork-of" ? (this._branchSelections.set(n.groupRoot, {
|
|
686
969
|
kind: "user",
|
|
687
|
-
selectedKey:
|
|
970
|
+
selectedKey: i.memberNodeKey
|
|
688
971
|
}), this._logger.debug("DefaultView.selectSibling(); fork-of", {
|
|
689
972
|
codecMessageId: e,
|
|
690
973
|
index: r,
|
|
691
|
-
selectedKey:
|
|
974
|
+
selectedKey: i.memberNodeKey
|
|
975
|
+
})) : n.kind === "non-head-regen" ? (this._nonHeadRegenSelections.set(n.groupRoot, {
|
|
976
|
+
kind: "user",
|
|
977
|
+
selectedRunId: i.memberNodeKey
|
|
978
|
+
}), this._logger.debug("DefaultView.selectSibling(); non-head-regen", {
|
|
979
|
+
codecMessageId: e,
|
|
980
|
+
index: r,
|
|
981
|
+
selectedRunId: i.memberNodeKey,
|
|
982
|
+
anchor: n.groupRoot
|
|
692
983
|
})) : (this._regenSelections.set(n.groupRoot, {
|
|
693
984
|
kind: "user",
|
|
694
|
-
selectedRunId:
|
|
985
|
+
selectedRunId: i.memberNodeKey
|
|
695
986
|
}), this._logger.debug("DefaultView.selectSibling(); regenerate", {
|
|
696
987
|
codecMessageId: e,
|
|
697
988
|
index: r,
|
|
698
|
-
selectedRunId:
|
|
989
|
+
selectedRunId: i.memberNodeKey,
|
|
699
990
|
groupRoot: n.groupRoot
|
|
700
991
|
})), this._recomputeAndEmit());
|
|
701
992
|
}
|
|
702
993
|
_resolveSelectedIndex(e) {
|
|
703
994
|
if (e.kind === "fork-of") {
|
|
704
995
|
let t = this._branchSelections.get(e.groupRoot);
|
|
705
|
-
if (!t) return e.
|
|
706
|
-
let n = e.
|
|
707
|
-
return n === -1 ? e.
|
|
996
|
+
if (!t) return e.members.length - 1;
|
|
997
|
+
let n = e.members.findIndex((e) => e.memberNodeKey === t.selectedKey);
|
|
998
|
+
return n === -1 ? e.members.length - 1 : n;
|
|
708
999
|
}
|
|
709
|
-
let t = this._regenSelections.get(e.groupRoot);
|
|
710
|
-
if (!t || t.kind === "pending") return e.
|
|
711
|
-
let n = e.
|
|
712
|
-
return n === -1 ? e.
|
|
1000
|
+
let t = e.kind === "non-head-regen" ? this._nonHeadRegenSelections.get(e.groupRoot) : this._regenSelections.get(e.groupRoot);
|
|
1001
|
+
if (!t || t.kind === "pending") return e.members.length - 1;
|
|
1002
|
+
let n = e.members.findIndex((e) => e.memberNodeKey === t.selectedRunId);
|
|
1003
|
+
return n === -1 ? e.members.length - 1 : n;
|
|
713
1004
|
}
|
|
714
1005
|
_resolveMessageBranchPoint(e) {
|
|
715
1006
|
let t = this._tree.getNodeByCodecMessageId(e);
|
|
@@ -719,19 +1010,64 @@ var u = "status", d = "run-id", f = "invocation-id", p = "event-id", m = "codec-
|
|
|
719
1010
|
return e.length > 1 ? {
|
|
720
1011
|
kind: "fork-of",
|
|
721
1012
|
groupRoot: this._tree.getGroupRoot(t.codecMessageId),
|
|
722
|
-
|
|
1013
|
+
members: this._nodeHeadMembers(e)
|
|
723
1014
|
} : void 0;
|
|
724
1015
|
}
|
|
725
|
-
let n = this.
|
|
726
|
-
if (
|
|
1016
|
+
let n = this._codec.getMessages(t.projection), r = this._resolveNonHeadBranchPoint(t, n, e);
|
|
1017
|
+
if (r) return r;
|
|
1018
|
+
let i = this._tree.getSiblingNodes(t.runId);
|
|
1019
|
+
if (i.length > 1 && n.at(0)?.codecMessageId === e) return {
|
|
727
1020
|
kind: "regen",
|
|
728
1021
|
groupRoot: this._tree.getGroupRoot(t.runId),
|
|
729
|
-
|
|
1022
|
+
members: this._nodeHeadMembers(i)
|
|
730
1023
|
};
|
|
731
1024
|
}
|
|
1025
|
+
_resolveNonHeadBranchPoint(e, t, n) {
|
|
1026
|
+
if (t.at(0)?.codecMessageId === n && e.regeneratesCodecMessageId !== void 0) {
|
|
1027
|
+
let t = e.regeneratesCodecMessageId, n = this._runByCodecMessageId(t);
|
|
1028
|
+
if (n) {
|
|
1029
|
+
let e = this._codec.getMessages(n.projection), r = e.findIndex((e) => e.codecMessageId === t), i = r > 0 ? e[r - 1]?.codecMessageId : void 0;
|
|
1030
|
+
if (i !== void 0) return this._buildNonHeadGroup(t, n.runId, i);
|
|
1031
|
+
}
|
|
1032
|
+
return;
|
|
1033
|
+
}
|
|
1034
|
+
let r = t.findIndex((e) => e.codecMessageId === n), i = r > 0 ? t[r - 1]?.codecMessageId : void 0;
|
|
1035
|
+
if (i !== void 0) return this._buildNonHeadGroup(n, e.runId, i);
|
|
1036
|
+
}
|
|
1037
|
+
_buildNonHeadGroup(e, t, n) {
|
|
1038
|
+
let r = this._nonHeadRegenerators(e, n);
|
|
1039
|
+
if (r.length === 0) return;
|
|
1040
|
+
let i = [{
|
|
1041
|
+
memberNodeKey: t,
|
|
1042
|
+
representativeCodecMessageId: e
|
|
1043
|
+
}];
|
|
1044
|
+
for (let e of r) {
|
|
1045
|
+
let t = this._codec.getMessages(e.projection).at(0);
|
|
1046
|
+
t && i.push({
|
|
1047
|
+
memberNodeKey: e.runId,
|
|
1048
|
+
representativeCodecMessageId: t.codecMessageId
|
|
1049
|
+
});
|
|
1050
|
+
}
|
|
1051
|
+
return {
|
|
1052
|
+
kind: "non-head-regen",
|
|
1053
|
+
groupRoot: e,
|
|
1054
|
+
members: i
|
|
1055
|
+
};
|
|
1056
|
+
}
|
|
1057
|
+
_nodeHeadMembers(e) {
|
|
1058
|
+
let t = [];
|
|
1059
|
+
for (let n of e) {
|
|
1060
|
+
let e = this._codec.getMessages(n.projection).at(0);
|
|
1061
|
+
e && t.push({
|
|
1062
|
+
memberNodeKey: B(n),
|
|
1063
|
+
representativeCodecMessageId: e.codecMessageId
|
|
1064
|
+
});
|
|
1065
|
+
}
|
|
1066
|
+
return t;
|
|
1067
|
+
}
|
|
732
1068
|
async send(t, n) {
|
|
733
|
-
if (this._logger.trace("DefaultView.send();"), this._closed) throw new e.ErrorInfo("unable to send; view is closed",
|
|
734
|
-
let r =
|
|
1069
|
+
if (this._logger.trace("DefaultView.send();"), this._closed) throw new e.ErrorInfo("unable to send; view is closed", N.InvalidArgument, 400);
|
|
1070
|
+
let r = Ae(t), i = this._lastVisibleMessagePairs.at(-1)?.codecMessageId, a = await this._sendDelegate(r, n, i);
|
|
735
1071
|
return this._applyForkAutoSelect(a, n), a;
|
|
736
1072
|
}
|
|
737
1073
|
_applyForkAutoSelect(e, t) {
|
|
@@ -747,6 +1083,16 @@ var u = "status", d = "run-id", f = "invocation-id", p = "event-id", m = "codec-
|
|
|
747
1083
|
_applyRegenerateAutoSelect(e, t) {
|
|
748
1084
|
let n = this._runByCodecMessageId(t);
|
|
749
1085
|
if (!n) return;
|
|
1086
|
+
if (this._codec.getMessages(n.projection).at(0)?.codecMessageId !== t) {
|
|
1087
|
+
this._nonHeadRegenSelections.set(t, {
|
|
1088
|
+
kind: "pending",
|
|
1089
|
+
carrierCodecMessageId: e.inputCodecMessageId
|
|
1090
|
+
}), this._logger.debug("DefaultView._applyRegenerateAutoSelect(); deferring non-head regenerate selection", {
|
|
1091
|
+
anchorCodecMessageId: t,
|
|
1092
|
+
carrier: e.inputCodecMessageId
|
|
1093
|
+
}), this._resolvePendingNonHeadRegenSelections(), this._recomputeAndEmitIfChanged();
|
|
1094
|
+
return;
|
|
1095
|
+
}
|
|
750
1096
|
let r = this._tree.getGroupRoot(n.runId);
|
|
751
1097
|
this._regenSelections.set(r, {
|
|
752
1098
|
kind: "pending",
|
|
@@ -758,11 +1104,11 @@ var u = "status", d = "run-id", f = "invocation-id", p = "event-id", m = "codec-
|
|
|
758
1104
|
}), this._resolvePendingRegenSelections(), this._recomputeAndEmitIfChanged();
|
|
759
1105
|
}
|
|
760
1106
|
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",
|
|
1107
|
+
if (this._logger.trace("DefaultView.regenerate();", { messageId: t }), this._closed) throw new e.ErrorInfo("unable to regenerate; view is closed", N.InvalidArgument, 400);
|
|
762
1108
|
let r = this._runByCodecMessageId(t);
|
|
763
|
-
if (!r) throw new e.ErrorInfo(`unable to regenerate; message not found in tree: ${t}`,
|
|
1109
|
+
if (!r) throw new e.ErrorInfo(`unable to regenerate; message not found in tree: ${t}`, N.InvalidArgument, 400);
|
|
764
1110
|
let i = this._findParentMsgId(r, t);
|
|
765
|
-
if (!i) throw new e.ErrorInfo(`unable to regenerate; parent user message not found for ${t}`,
|
|
1111
|
+
if (!i) throw new e.ErrorInfo(`unable to regenerate; parent user message not found for ${t}`, N.InvalidArgument, 400);
|
|
766
1112
|
let a = t;
|
|
767
1113
|
r.regeneratesCodecMessageId !== void 0 && this._codec.getMessages(r.projection).at(0)?.codecMessageId === t && (a = r.regeneratesCodecMessageId);
|
|
768
1114
|
let o = {
|
|
@@ -772,9 +1118,9 @@ var u = "status", d = "run-id", f = "invocation-id", p = "event-id", m = "codec-
|
|
|
772
1118
|
return this._applyRegenerateAutoSelect(c, a), c;
|
|
773
1119
|
}
|
|
774
1120
|
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",
|
|
1121
|
+
if (this._logger.trace("DefaultView.edit();", { messageId: t }), this._closed) throw new e.ErrorInfo("unable to edit; view is closed", N.InvalidArgument, 400);
|
|
776
1122
|
let i = this._tree.getNodeByCodecMessageId(t);
|
|
777
|
-
if (!i) throw new e.ErrorInfo(`unable to edit; message not found in tree: ${t}`,
|
|
1123
|
+
if (!i) throw new e.ErrorInfo(`unable to edit; message not found in tree: ${t}`, N.InvalidArgument, 400);
|
|
778
1124
|
let a = this._findParentMsgId(i, t);
|
|
779
1125
|
return this.send(n, {
|
|
780
1126
|
...r,
|
|
@@ -803,35 +1149,26 @@ var u = "status", d = "run-id", f = "invocation-id", p = "event-id", m = "codec-
|
|
|
803
1149
|
if (!this._closed) {
|
|
804
1150
|
this._logger.info("DefaultView.close();"), this._closed = !0, this._loadingOlder = !1;
|
|
805
1151
|
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?.();
|
|
1152
|
+
this._unsubs.length = 0, this._emitter.off(), this._branchSelections.clear(), this._regenSelections.clear(), this._nonHeadRegenSelections.clear(), this._withheldRunIds.clear(), this._withheldBuffer.length = 0, this._hiddenMessageCount = 0, this._onClose?.();
|
|
807
1153
|
}
|
|
808
1154
|
}
|
|
809
1155
|
async _loadFirstPage(e) {
|
|
810
|
-
let t =
|
|
811
|
-
this._closed || await this._revealFromPage(
|
|
1156
|
+
let t = await ke(this._channel, { limit: e }, this._logger);
|
|
1157
|
+
this._closed || await this._revealFromPage(t, e);
|
|
812
1158
|
}
|
|
813
1159
|
async _revealFromPage(e, t) {
|
|
814
|
-
let n = new Set(this._treeVisibleNodes().map((e) =>
|
|
1160
|
+
let n = new Set(this._treeVisibleNodes().map((e) => B(e))), { newVisible: r, lastPage: i } = await this._loadUntilVisible(e, t, n);
|
|
815
1161
|
this._closed || (this._lastHistoryPage = i, this._hasMoreHistory = i.hasNext(), this._splitReveal(r, t));
|
|
816
1162
|
}
|
|
817
1163
|
_splitReveal(e, t) {
|
|
818
|
-
let n =
|
|
819
|
-
for (let
|
|
820
|
-
|
|
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);
|
|
1164
|
+
let n = this._messageTailSplitIndex(e, t), r = e.slice(n), i = e.slice(0, n);
|
|
1165
|
+
for (let e of i) this._withheldRunIds.add(B(e));
|
|
1166
|
+
this._withheldBuffer.push(...i), this._releaseWithheld(r);
|
|
829
1167
|
}
|
|
830
1168
|
_processHistoryPage(e) {
|
|
831
1169
|
this._processingHistory = !0;
|
|
832
1170
|
try {
|
|
833
|
-
let t
|
|
834
|
-
for (let n of e.rawMessages) M(this._tree, t, n);
|
|
1171
|
+
for (let t of e.rawMessages) this._applier.apply(t);
|
|
835
1172
|
for (let t of e.rawMessages) this._tree.emitAblyMessage(t);
|
|
836
1173
|
} finally {
|
|
837
1174
|
this._processingHistory = !1;
|
|
@@ -841,7 +1178,7 @@ var u = "status", d = "run-id", f = "invocation-id", p = "event-id", m = "codec-
|
|
|
841
1178
|
this._processHistoryPage(e);
|
|
842
1179
|
let r = e, i = () => {
|
|
843
1180
|
let e = 0;
|
|
844
|
-
for (let t of this._treeVisibleNodes())
|
|
1181
|
+
for (let t of this._treeVisibleNodes()) n.has(B(t)) || (e += this._codec.getMessages(t.projection).length);
|
|
845
1182
|
return e;
|
|
846
1183
|
};
|
|
847
1184
|
for (; i() < t && r.hasNext();) {
|
|
@@ -850,20 +1187,20 @@ var u = "status", d = "run-id", f = "invocation-id", p = "event-id", m = "codec-
|
|
|
850
1187
|
this._processHistoryPage(e), r = e;
|
|
851
1188
|
}
|
|
852
1189
|
return {
|
|
853
|
-
newVisible: this._treeVisibleNodes().filter((e) => !n.has(
|
|
1190
|
+
newVisible: this._treeVisibleNodes().filter((e) => !n.has(B(e))),
|
|
854
1191
|
lastPage: r
|
|
855
1192
|
};
|
|
856
1193
|
}
|
|
857
1194
|
_releaseWithheld(e) {
|
|
858
|
-
for (let t of e) this._withheldRunIds.delete(
|
|
1195
|
+
for (let t of e) this._withheldRunIds.delete(B(t));
|
|
859
1196
|
e.length > 0 && this._recomputeAndEmit();
|
|
860
1197
|
}
|
|
861
1198
|
_updateVisibleSnapshot(e) {
|
|
862
1199
|
let t = e ?? this._cachedNodes;
|
|
863
|
-
this._lastVisibleNodeKeys = t.map((e) =>
|
|
1200
|
+
this._lastVisibleNodeKeys = t.map((e) => B(e)), this._lastVisibleNodeKeySet = new Set(this._lastVisibleNodeKeys), this._lastVisibleProjections = t.map((e) => e.projection), this._lastVisibleMessagePairs = this._extractMessages(t).slice(this._hiddenMessageCount);
|
|
864
1201
|
}
|
|
865
1202
|
_onTreeUpdate() {
|
|
866
|
-
this._processingHistory || (this._pinBranchSelections(), this._resolvePendingRegenSelections(), this._recomputeAndEmitIfChanged());
|
|
1203
|
+
this._processingHistory || (this._pinBranchSelections(), this._resolvePendingRegenSelections(), this._resolvePendingNonHeadRegenSelections(), this._recomputeAndEmitIfChanged());
|
|
867
1204
|
}
|
|
868
1205
|
_resolveSelections() {
|
|
869
1206
|
let e = /* @__PURE__ */ new Map();
|
|
@@ -896,8 +1233,22 @@ var u = "status", d = "run-id", f = "invocation-id", p = "event-id", m = "codec-
|
|
|
896
1233
|
});
|
|
897
1234
|
}
|
|
898
1235
|
}
|
|
1236
|
+
_resolvePendingNonHeadRegenSelections() {
|
|
1237
|
+
for (let [e, t] of this._nonHeadRegenSelections) {
|
|
1238
|
+
if (t.kind === "user") continue;
|
|
1239
|
+
let n = this._runByCodecMessageId(e);
|
|
1240
|
+
if (!n) continue;
|
|
1241
|
+
let r = this._codec.getMessages(n.projection), i = r.findIndex((t) => t.codecMessageId === e), a = i > 0 ? r[i - 1]?.codecMessageId : void 0;
|
|
1242
|
+
if (a === void 0) continue;
|
|
1243
|
+
let o = this._nonHeadRegenerators(e, a).at(-1);
|
|
1244
|
+
o && this._nonHeadRegenSelections.set(e, {
|
|
1245
|
+
kind: "auto",
|
|
1246
|
+
selectedRunId: o.runId
|
|
1247
|
+
});
|
|
1248
|
+
}
|
|
1249
|
+
}
|
|
899
1250
|
_onTreeAblyMessage(e) {
|
|
900
|
-
let t =
|
|
1251
|
+
let t = L(e), n = t[D], r = t[w];
|
|
901
1252
|
if (!n && !r) {
|
|
902
1253
|
this._emitter.emit("ably-message", e);
|
|
903
1254
|
return;
|
|
@@ -915,32 +1266,33 @@ var u = "status", d = "run-id", f = "invocation-id", p = "event-id", m = "codec-
|
|
|
915
1266
|
let { parent: t } = e;
|
|
916
1267
|
if (t === void 0) return !0;
|
|
917
1268
|
let n = this._tree.getNodeByCodecMessageId(t);
|
|
918
|
-
return n ? this._lastVisibleNodeKeySet.has(
|
|
1269
|
+
return n ? this._lastVisibleNodeKeySet.has(B(n)) : !0;
|
|
919
1270
|
}
|
|
920
1271
|
_visibleChanged(e) {
|
|
921
1272
|
if (e.length !== this._lastVisibleNodeKeys.length) return !0;
|
|
922
|
-
for (let [t, n] of e.entries()) if (
|
|
1273
|
+
for (let [t, n] of e.entries()) if (B(n) !== this._lastVisibleNodeKeys[t] || n.projection !== this._lastVisibleProjections[t]) return !0;
|
|
923
1274
|
return !1;
|
|
924
1275
|
}
|
|
925
|
-
},
|
|
1276
|
+
}, q = (e) => new je(e), Me = () => {}, Ne = class {
|
|
926
1277
|
constructor(e) {
|
|
927
1278
|
this._views = /* @__PURE__ */ new Set(), this._state = "ready", this._pendingRunStarts = /* @__PURE__ */ new Map();
|
|
928
|
-
let t =
|
|
929
|
-
if (this._channel = e.client.channels.get(e.channelName, t), this.
|
|
1279
|
+
let t = x(e.client, e.codec), n = m(e.channelModes);
|
|
1280
|
+
if (n && (t.modes = n), this._channel = e.client.channels.get(e.channelName, t), this._client = e.client, this._codec = e.codec, this._logger = (e.logger ?? ce({ logLevel: oe.Silent })).withContext({ component: "ClientSession" }), this._emitter = new P(this._logger), this._hasAttachedOnce = this._channel.state === "attached", this._tree = we(this._codec, this._logger), this._applier = ge(this._tree, this._codec.createDecoder()), this._view = q({
|
|
930
1281
|
tree: this._tree,
|
|
931
1282
|
channel: this._channel,
|
|
932
1283
|
codec: this._codec,
|
|
1284
|
+
applier: this._applier,
|
|
933
1285
|
sendDelegate: this._internalSend.bind(this),
|
|
934
1286
|
logger: this._logger,
|
|
935
1287
|
onClose: () => this._views.delete(this._view)
|
|
936
|
-
}), this.
|
|
1288
|
+
}), this._encoder = this._codec.createEncoder(this._channel), this._views.add(this._view), this.tree = this._tree, this.view = this._view, e.messages) {
|
|
937
1289
|
let t;
|
|
938
1290
|
for (let n of e.messages) {
|
|
939
1291
|
let e = crypto.randomUUID(), r = {
|
|
940
|
-
[
|
|
941
|
-
[
|
|
1292
|
+
[D]: e,
|
|
1293
|
+
[O]: "user"
|
|
942
1294
|
};
|
|
943
|
-
t && (r[
|
|
1295
|
+
t && (r[k] = t), this._tree.applyMessage({
|
|
944
1296
|
inputs: [this._codec.createUserMessage(n)],
|
|
945
1297
|
outputs: []
|
|
946
1298
|
}, r), t = e;
|
|
@@ -952,60 +1304,68 @@ var u = "status", d = "run-id", f = "invocation-id", p = "event-id", m = "codec-
|
|
|
952
1304
|
this._handleChannelStateChange(e);
|
|
953
1305
|
}, this._channel.on(this._onChannelStateChange);
|
|
954
1306
|
}
|
|
1307
|
+
get presence() {
|
|
1308
|
+
return this._channel.presence;
|
|
1309
|
+
}
|
|
1310
|
+
get object() {
|
|
1311
|
+
return this._channel.object;
|
|
1312
|
+
}
|
|
955
1313
|
connect() {
|
|
956
|
-
return this._state === "closed" ? Promise.reject(new e.ErrorInfo("unable to connect; session is closed",
|
|
1314
|
+
return this._state === "closed" ? Promise.reject(new e.ErrorInfo("unable to connect; session is closed", N.SessionClosed, 400)) : this._connectPromise ? this._connectPromise : (this._logger.trace("DefaultClientSession.connect();"), this._connectPromise = this._channel.subscribe(this._onMessage).then(() => {
|
|
957
1315
|
this._logger.debug("DefaultClientSession.connect(); subscribed and attached");
|
|
958
1316
|
}, (t) => {
|
|
959
|
-
let n = new e.ErrorInfo(`unable to subscribe to channel; ${
|
|
1317
|
+
let n = new e.ErrorInfo(`unable to subscribe to channel; ${F(t)}`, N.SessionSubscriptionError, 500, I(t));
|
|
960
1318
|
throw this._logger.error("DefaultClientSession.connect(); subscribe failed"), this._emitter.emit("error", n), n;
|
|
961
1319
|
}), this._connectPromise);
|
|
962
1320
|
}
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
return
|
|
1321
|
+
_resolveClientId() {
|
|
1322
|
+
let e = this._client.auth.clientId;
|
|
1323
|
+
return e && e !== "*" ? e : void 0;
|
|
1324
|
+
}
|
|
1325
|
+
async _requireConnected(e) {
|
|
1326
|
+
return ve(this._connectPromise, e);
|
|
966
1327
|
}
|
|
967
1328
|
_handleMessage(t) {
|
|
968
1329
|
if (this._state !== "closed") try {
|
|
969
1330
|
if (t.name === "ai-run-end") {
|
|
970
|
-
let
|
|
971
|
-
if ((
|
|
972
|
-
let t =
|
|
1331
|
+
let e = L(t);
|
|
1332
|
+
if ((e["run-reason"] ?? "complete") === "error") {
|
|
1333
|
+
let t = R(e);
|
|
973
1334
|
this._logger.error("ClientSession._handleMessage(); agent error received", {
|
|
974
|
-
runId:
|
|
975
|
-
invocationId:
|
|
976
|
-
code:
|
|
977
|
-
}), this._emitter.emit("error",
|
|
1335
|
+
runId: e[w],
|
|
1336
|
+
invocationId: e[T],
|
|
1337
|
+
code: t.code
|
|
1338
|
+
}), this._emitter.emit("error", t);
|
|
978
1339
|
}
|
|
979
1340
|
}
|
|
980
|
-
let
|
|
981
|
-
if (
|
|
982
|
-
let
|
|
983
|
-
if (
|
|
984
|
-
let t = this._pendingRunStarts.get(
|
|
985
|
-
t && (this._pendingRunStarts.delete(
|
|
1341
|
+
let e = this._applier.apply(t);
|
|
1342
|
+
if (e && (e.type === "start" || e.type === "resume")) {
|
|
1343
|
+
let n = L(t)[M];
|
|
1344
|
+
if (n !== void 0) {
|
|
1345
|
+
let t = this._pendingRunStarts.get(n);
|
|
1346
|
+
t && (this._pendingRunStarts.delete(n), t.resolve(e.runId));
|
|
986
1347
|
}
|
|
987
1348
|
}
|
|
988
1349
|
this._tree.emitAblyMessage(t);
|
|
989
1350
|
} catch (t) {
|
|
990
|
-
|
|
991
|
-
this._emitter.emit("error", new e.ErrorInfo(`unable to process channel message; ${t instanceof Error ? t.message : String(t)}`, C.SessionSubscriptionError, 500, n));
|
|
1351
|
+
this._emitter.emit("error", new e.ErrorInfo(`unable to process channel message; ${F(t)}`, N.SessionSubscriptionError, 500, I(t)));
|
|
992
1352
|
}
|
|
993
1353
|
}
|
|
994
|
-
_handleChannelStateChange(
|
|
1354
|
+
_handleChannelStateChange(e) {
|
|
995
1355
|
if (this._state === "closed") return;
|
|
996
|
-
let { current:
|
|
997
|
-
if (
|
|
1356
|
+
let { current: t, resumed: n } = e;
|
|
1357
|
+
if (t === "attached" && !this._hasAttachedOnce) {
|
|
998
1358
|
this._hasAttachedOnce = !0;
|
|
999
1359
|
return;
|
|
1000
1360
|
}
|
|
1001
|
-
if (!(
|
|
1361
|
+
if (!be(e)) return;
|
|
1002
1362
|
this._logger.error("ClientSession._handleChannelStateChange(); channel continuity lost", {
|
|
1003
|
-
current:
|
|
1004
|
-
resumed:
|
|
1005
|
-
previous:
|
|
1363
|
+
current: t,
|
|
1364
|
+
resumed: n,
|
|
1365
|
+
previous: e.previous
|
|
1006
1366
|
});
|
|
1007
|
-
let
|
|
1008
|
-
this._emitter.emit("error",
|
|
1367
|
+
let r = xe(e, "deliver events");
|
|
1368
|
+
this._emitter.emit("error", r);
|
|
1009
1369
|
}
|
|
1010
1370
|
_cleanupFailedSend(e) {
|
|
1011
1371
|
for (let t of e) {
|
|
@@ -1014,12 +1374,13 @@ var u = "status", d = "run-id", f = "invocation-id", p = "event-id", m = "codec-
|
|
|
1014
1374
|
}
|
|
1015
1375
|
}
|
|
1016
1376
|
createView() {
|
|
1017
|
-
if (this._state === "closed") throw new e.ErrorInfo("unable to create view; session is closed",
|
|
1377
|
+
if (this._state === "closed") throw new e.ErrorInfo("unable to create view; session is closed", N.SessionClosed, 400);
|
|
1018
1378
|
this._logger.trace("DefaultClientSession.createView();");
|
|
1019
|
-
let t =
|
|
1379
|
+
let t = q({
|
|
1020
1380
|
tree: this._tree,
|
|
1021
1381
|
channel: this._channel,
|
|
1022
1382
|
codec: this._codec,
|
|
1383
|
+
applier: this._applier,
|
|
1023
1384
|
sendDelegate: this._internalSend.bind(this),
|
|
1024
1385
|
logger: this._logger,
|
|
1025
1386
|
onClose: () => this._views.delete(t)
|
|
@@ -1027,9 +1388,9 @@ var u = "status", d = "run-id", f = "invocation-id", p = "event-id", m = "codec-
|
|
|
1027
1388
|
return this._views.add(t), t;
|
|
1028
1389
|
}
|
|
1029
1390
|
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",
|
|
1391
|
+
if (this._state === "closed" || (await this._requireConnected("send"), this._state === "closed")) throw new e.ErrorInfo("unable to send; session is closed", N.SessionClosed, 400);
|
|
1031
1392
|
let i = this._channel.state;
|
|
1032
|
-
if (i !== "attached" && i !== "attaching") throw new e.ErrorInfo(`unable to send; channel is ${i}`,
|
|
1393
|
+
if (i !== "attached" && i !== "attaching") throw new e.ErrorInfo(`unable to send; channel is ${i}`, N.ChannelNotReady, 400);
|
|
1033
1394
|
this._logger.trace("ClientSession._internalSend();");
|
|
1034
1395
|
let a = n?.runId !== void 0, o = n?.runId, s;
|
|
1035
1396
|
n?.parent === void 0 && !n?.forkOf && (s = r);
|
|
@@ -1037,11 +1398,11 @@ var u = "status", d = "run-id", f = "invocation-id", p = "event-id", m = "codec-
|
|
|
1037
1398
|
for (let e of t) {
|
|
1038
1399
|
let t = crypto.randomUUID(), r = e.codecMessageId ?? crypto.randomUUID();
|
|
1039
1400
|
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 =
|
|
1401
|
+
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 = fe({
|
|
1041
1402
|
role: "user",
|
|
1042
1403
|
runId: o,
|
|
1043
1404
|
codecMessageId: r,
|
|
1044
|
-
runClientId: this.
|
|
1405
|
+
runClientId: this._resolveClientId(),
|
|
1045
1406
|
...a !== void 0 && { parent: a },
|
|
1046
1407
|
...u !== void 0 && { forkOf: u },
|
|
1047
1408
|
...d !== void 0 && { regenerates: d },
|
|
@@ -1059,7 +1420,7 @@ var u = "status", d = "run-id", f = "invocation-id", p = "event-id", m = "codec-
|
|
|
1059
1420
|
}), !i && n?.parent === void 0 && !n?.forkOf && e.parent === void 0 && (s = r);
|
|
1060
1421
|
}
|
|
1061
1422
|
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)",
|
|
1423
|
+
if (u === void 0) throw new e.ErrorInfo("unable to send; inputs array is empty (include at least one input)", N.InvalidArgument, 400);
|
|
1063
1424
|
let d = u.inputEventId, f = u.codecMessageId, p = new Promise((e, t) => {
|
|
1064
1425
|
this._pendingRunStarts.set(f, {
|
|
1065
1426
|
resolve: e,
|
|
@@ -1070,11 +1431,10 @@ var u = "status", d = "run-id", f = "invocation-id", p = "event-id", m = "codec-
|
|
|
1070
1431
|
try {
|
|
1071
1432
|
for (let e of l) await this._encoder.publishInput(e.input, {
|
|
1072
1433
|
extras: { headers: e.headers },
|
|
1073
|
-
messageId: e.codecMessageId
|
|
1074
|
-
...this._clientId !== void 0 && { clientId: this._clientId }
|
|
1434
|
+
messageId: e.codecMessageId
|
|
1075
1435
|
});
|
|
1076
1436
|
} catch (t) {
|
|
1077
|
-
let n = t
|
|
1437
|
+
let n = I(t), 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; ${F(t)}`, r ? N.InsufficientCapability : N.SessionSendFailed, r ? 401 : 500, n);
|
|
1078
1438
|
throw this._emitter.emit("error", i), this._pendingRunStarts.delete(f), a || this._cleanupFailedSend([...c]), i;
|
|
1079
1439
|
}
|
|
1080
1440
|
})(), {
|
|
@@ -1088,7 +1448,7 @@ var u = "status", d = "run-id", f = "invocation-id", p = "event-id", m = "codec-
|
|
|
1088
1448
|
});
|
|
1089
1449
|
},
|
|
1090
1450
|
optimisticCodecMessageIds: [...c],
|
|
1091
|
-
toInvocation: () =>
|
|
1451
|
+
toInvocation: () => _e.fromJSON({
|
|
1092
1452
|
inputEventId: d,
|
|
1093
1453
|
sessionName: this._channel.name
|
|
1094
1454
|
})
|
|
@@ -1103,14 +1463,14 @@ var u = "status", d = "run-id", f = "invocation-id", p = "event-id", m = "codec-
|
|
|
1103
1463
|
runId: e.runId,
|
|
1104
1464
|
inputCodecMessageId: e.inputCodecMessageId
|
|
1105
1465
|
});
|
|
1106
|
-
let t = { [
|
|
1107
|
-
e.runId !== void 0 && (t[
|
|
1108
|
-
name:
|
|
1466
|
+
let t = { [E]: crypto.randomUUID() };
|
|
1467
|
+
e.runId !== void 0 && (t[w] = e.runId), e.inputCodecMessageId !== void 0 && (t[M] = e.inputCodecMessageId), await this._channel.publish({
|
|
1468
|
+
name: re,
|
|
1109
1469
|
extras: { ai: { transport: t } }
|
|
1110
1470
|
});
|
|
1111
1471
|
}
|
|
1112
1472
|
on(e, t) {
|
|
1113
|
-
if (this._state === "closed") return
|
|
1473
|
+
if (this._state === "closed") return Me;
|
|
1114
1474
|
let n = t;
|
|
1115
1475
|
return this._emitter.on(e, n), () => {
|
|
1116
1476
|
this._emitter.off(e, n);
|
|
@@ -1121,135 +1481,144 @@ var u = "status", d = "run-id", f = "invocation-id", p = "event-id", m = "codec-
|
|
|
1121
1481
|
this._state = "closed", this._logger.info("ClientSession.close();"), this._connectPromise && this._channel.unsubscribe(this._onMessage), this._channel.off(this._onChannelStateChange), this._emitter.off();
|
|
1122
1482
|
for (let e of this._views) e.close();
|
|
1123
1483
|
if (this._views.clear(), this._pendingRunStarts.size > 0) {
|
|
1124
|
-
let t = new e.ErrorInfo("unable to await run-start; session closed",
|
|
1484
|
+
let t = new e.ErrorInfo("unable to await run-start; session closed", N.SessionClosed, 400);
|
|
1125
1485
|
for (let e of this._pendingRunStarts.values()) e.reject(t);
|
|
1126
1486
|
this._pendingRunStarts.clear();
|
|
1127
1487
|
}
|
|
1128
1488
|
try {
|
|
1129
1489
|
await this._encoder.close();
|
|
1130
1490
|
} catch {}
|
|
1131
|
-
|
|
1132
|
-
await this._channel.detach();
|
|
1133
|
-
} catch (e) {
|
|
1134
|
-
this._logger.debug("ClientSession.close(); channel detach failed", { error: e });
|
|
1135
|
-
}
|
|
1491
|
+
await ye(this._channel, this._connectPromise, this._logger, "ClientSession");
|
|
1136
1492
|
}
|
|
1137
1493
|
}
|
|
1138
|
-
},
|
|
1494
|
+
}, Pe = (e) => new Ne(e), J = r({
|
|
1139
1495
|
nearest: void 0,
|
|
1140
1496
|
providers: {}
|
|
1141
|
-
}),
|
|
1142
|
-
let
|
|
1143
|
-
|
|
1144
|
-
|
|
1497
|
+
}), Y = ({ children: r, ...i }) => {
|
|
1498
|
+
let l = n(), { channelName: d } = i, f = s(() => {
|
|
1499
|
+
let e = { params: { agent: b(i.codec) } }, t = m(i.channelModes);
|
|
1500
|
+
return t && (e.modes = t), e;
|
|
1501
|
+
}, [i.codec, i.channelModes]), p = c(void 0), h = c(d), g = c([]), _ = c(!1), v = c(void 0);
|
|
1502
|
+
if (!(p.current || v.current) || h.current !== d) {
|
|
1503
|
+
h.current = d, p.current && g.current.push(p.current);
|
|
1145
1504
|
try {
|
|
1146
|
-
|
|
1147
|
-
...
|
|
1148
|
-
client:
|
|
1149
|
-
}),
|
|
1505
|
+
p.current = Pe({
|
|
1506
|
+
...i,
|
|
1507
|
+
client: l
|
|
1508
|
+
}), v.current = void 0;
|
|
1150
1509
|
} catch (t) {
|
|
1151
|
-
|
|
1510
|
+
p.current = void 0, v.current = t instanceof e.ErrorInfo ? t : new e.ErrorInfo("Unknown error while creating client session", N.BadRequest, 400);
|
|
1152
1511
|
}
|
|
1153
1512
|
}
|
|
1154
|
-
let
|
|
1155
|
-
session:
|
|
1156
|
-
sessionError:
|
|
1157
|
-
}), [
|
|
1158
|
-
nearest:
|
|
1513
|
+
let y = a(J), x = p.current, S = v.current, C = s(() => ({
|
|
1514
|
+
session: x,
|
|
1515
|
+
sessionError: S
|
|
1516
|
+
}), [x, S]), w = s(() => ({
|
|
1517
|
+
nearest: C,
|
|
1159
1518
|
providers: {
|
|
1160
|
-
...
|
|
1161
|
-
[
|
|
1519
|
+
...y.providers,
|
|
1520
|
+
[d]: C
|
|
1162
1521
|
}
|
|
1163
1522
|
}), [
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1523
|
+
d,
|
|
1524
|
+
y,
|
|
1525
|
+
C
|
|
1167
1526
|
]);
|
|
1168
|
-
return
|
|
1169
|
-
for (let e of
|
|
1170
|
-
}, [
|
|
1171
|
-
|
|
1172
|
-
}, [
|
|
1173
|
-
|
|
1174
|
-
|
|
1527
|
+
return o(() => () => {
|
|
1528
|
+
for (let e of g.current) e.close();
|
|
1529
|
+
}, [d]), o(() => {
|
|
1530
|
+
p.current?.connect();
|
|
1531
|
+
}, [d]), o(() => (_.current = !1, () => {
|
|
1532
|
+
_.current = !0, Promise.resolve().then(() => {
|
|
1533
|
+
_.current && p.current?.close();
|
|
1175
1534
|
});
|
|
1176
|
-
}), []), /* @__PURE__ */
|
|
1177
|
-
value:
|
|
1178
|
-
children:
|
|
1535
|
+
}), []), /* @__PURE__ */ u(J.Provider, {
|
|
1536
|
+
value: w,
|
|
1537
|
+
children: /* @__PURE__ */ u(t, {
|
|
1538
|
+
channelName: d,
|
|
1539
|
+
options: f,
|
|
1540
|
+
children: r
|
|
1541
|
+
})
|
|
1179
1542
|
});
|
|
1180
|
-
},
|
|
1181
|
-
let { nearest: n } =
|
|
1543
|
+
}, X = ({ session: e, skip: t } = {}) => {
|
|
1544
|
+
let { nearest: n } = a(J), r = n?.session;
|
|
1182
1545
|
if (!t && e !== null) return e ?? r;
|
|
1183
|
-
},
|
|
1184
|
-
let n =
|
|
1546
|
+
}, Fe = ({ session: e, skip: t } = {}) => {
|
|
1547
|
+
let n = X({
|
|
1185
1548
|
session: e,
|
|
1186
1549
|
skip: t
|
|
1187
|
-
}), [r, i] =
|
|
1188
|
-
return
|
|
1189
|
-
if (
|
|
1190
|
-
let t = [...
|
|
1191
|
-
|
|
1550
|
+
}), [r, i] = l([]), a = c([]);
|
|
1551
|
+
return o(() => {
|
|
1552
|
+
if (a.current = [], i([]), n) return n.tree.on("ably-message", (e) => {
|
|
1553
|
+
let t = [...a.current, e];
|
|
1554
|
+
a.current = t, i(t);
|
|
1192
1555
|
});
|
|
1193
1556
|
}, [n]), r;
|
|
1194
|
-
},
|
|
1557
|
+
}, Z = (t) => new e.ErrorInfo(`unable to ${t}; hook is skipped`, N.InvalidArgument, 400), Q = () => ({
|
|
1195
1558
|
get tree() {
|
|
1196
|
-
throw
|
|
1559
|
+
throw Z("access tree");
|
|
1197
1560
|
},
|
|
1198
1561
|
get view() {
|
|
1199
|
-
throw
|
|
1562
|
+
throw Z("access view");
|
|
1563
|
+
},
|
|
1564
|
+
get presence() {
|
|
1565
|
+
throw Z("access presence");
|
|
1566
|
+
},
|
|
1567
|
+
get object() {
|
|
1568
|
+
throw Z("access object");
|
|
1200
1569
|
},
|
|
1201
1570
|
connect: () => {
|
|
1202
|
-
throw
|
|
1571
|
+
throw Z("connect");
|
|
1203
1572
|
},
|
|
1204
1573
|
createView: () => {
|
|
1205
|
-
throw
|
|
1574
|
+
throw Z("create view");
|
|
1206
1575
|
},
|
|
1207
1576
|
cancel: () => {
|
|
1208
|
-
throw
|
|
1577
|
+
throw Z("cancel");
|
|
1209
1578
|
},
|
|
1210
1579
|
on: () => {
|
|
1211
|
-
throw
|
|
1580
|
+
throw Z("subscribe");
|
|
1212
1581
|
},
|
|
1213
1582
|
close: () => {
|
|
1214
|
-
throw
|
|
1583
|
+
throw Z("close");
|
|
1215
1584
|
}
|
|
1216
|
-
},
|
|
1217
|
-
let { nearest:
|
|
1585
|
+
}), Ie = ({ channelName: t, skip: n, onError: r } = {}) => {
|
|
1586
|
+
let { nearest: i, providers: s } = a(J), l = c(r);
|
|
1218
1587
|
l.current = r;
|
|
1219
|
-
let u = n ? void 0 : t === void 0 ?
|
|
1220
|
-
if (
|
|
1588
|
+
let u = n ? void 0 : t === void 0 ? i?.session : s[t]?.session;
|
|
1589
|
+
if (o(() => {
|
|
1221
1590
|
if (u) return u.on("error", (e) => {
|
|
1222
1591
|
l.current?.(e);
|
|
1223
1592
|
});
|
|
1224
|
-
}, [u]), n) return { session:
|
|
1593
|
+
}, [u]), n) return { session: Q() };
|
|
1225
1594
|
if (t !== void 0) {
|
|
1226
|
-
let n =
|
|
1595
|
+
let n = s[t];
|
|
1227
1596
|
return n ? n.session ? { session: n.session } : {
|
|
1228
|
-
session:
|
|
1597
|
+
session: Q(),
|
|
1229
1598
|
sessionError: n.sessionError
|
|
1230
1599
|
} : {
|
|
1231
|
-
session:
|
|
1232
|
-
sessionError: new e.ErrorInfo(`unable to use session; no ClientSessionProvider found for channelName "${t}"`,
|
|
1600
|
+
session: Q(),
|
|
1601
|
+
sessionError: new e.ErrorInfo(`unable to use session; no ClientSessionProvider found for channelName "${t}"`, N.BadRequest, 400)
|
|
1233
1602
|
};
|
|
1234
1603
|
}
|
|
1235
|
-
return
|
|
1236
|
-
session:
|
|
1237
|
-
sessionError:
|
|
1604
|
+
return i ? i.session ? { session: i.session } : {
|
|
1605
|
+
session: Q(),
|
|
1606
|
+
sessionError: i.sessionError
|
|
1238
1607
|
} : {
|
|
1239
|
-
session:
|
|
1240
|
-
sessionError: new e.ErrorInfo("unable to use session; no ClientSessionProvider found in the tree",
|
|
1608
|
+
session: Q(),
|
|
1609
|
+
sessionError: new e.ErrorInfo("unable to use session; no ClientSessionProvider found in the tree", N.BadRequest, 400)
|
|
1241
1610
|
};
|
|
1242
|
-
},
|
|
1611
|
+
}, Le = {
|
|
1243
1612
|
hasSiblings: !1,
|
|
1244
1613
|
siblings: [],
|
|
1245
1614
|
index: 0,
|
|
1246
1615
|
selected: void 0
|
|
1247
|
-
},
|
|
1248
|
-
let
|
|
1616
|
+
}, $ = ({ session: t, view: n, limit: r, skip: a } = {}) => {
|
|
1617
|
+
let s = X({
|
|
1249
1618
|
session: t,
|
|
1250
|
-
skip:
|
|
1251
|
-
}), u =
|
|
1252
|
-
|
|
1619
|
+
skip: a
|
|
1620
|
+
}), u = a ? void 0 : n ?? s?.view, [d, f] = l(() => u?.getMessages() ?? []), [p, m] = l(() => u?.hasOlder() ?? !1), [h, g] = l(!1), [_, v] = l(), y = c(!1), b = r !== void 0, x = c(!1);
|
|
1621
|
+
o(() => {
|
|
1253
1622
|
if (!u) {
|
|
1254
1623
|
f([]), m(!1), v(void 0);
|
|
1255
1624
|
return;
|
|
@@ -1258,19 +1627,19 @@ var u = "status", d = "run-id", f = "invocation-id", p = "event-id", m = "codec-
|
|
|
1258
1627
|
f(u.getMessages()), m(u.hasOlder());
|
|
1259
1628
|
});
|
|
1260
1629
|
}, [u]);
|
|
1261
|
-
let S =
|
|
1630
|
+
let S = i(async () => {
|
|
1262
1631
|
if (!(!u || y.current)) {
|
|
1263
1632
|
y.current = !0, g(!0);
|
|
1264
1633
|
try {
|
|
1265
|
-
await u.loadOlder(
|
|
1634
|
+
await u.loadOlder(r), v(void 0);
|
|
1266
1635
|
} catch (t) {
|
|
1267
|
-
t instanceof e.ErrorInfo ? v(t) : v(new e.ErrorInfo("Unknown error loading older messages",
|
|
1636
|
+
t instanceof e.ErrorInfo ? v(t) : v(new e.ErrorInfo("Unknown error loading older messages", N.BadRequest, 400));
|
|
1268
1637
|
} finally {
|
|
1269
1638
|
y.current = !1, g(!1);
|
|
1270
1639
|
}
|
|
1271
1640
|
}
|
|
1272
|
-
}, [u,
|
|
1273
|
-
return
|
|
1641
|
+
}, [u, r]);
|
|
1642
|
+
return o(() => {
|
|
1274
1643
|
!b || x.current || !u || (x.current = !0, S());
|
|
1275
1644
|
}, [
|
|
1276
1645
|
b,
|
|
@@ -1282,61 +1651,61 @@ var u = "status", d = "run-id", f = "invocation-id", p = "event-id", m = "codec-
|
|
|
1282
1651
|
loading: h,
|
|
1283
1652
|
loadError: _,
|
|
1284
1653
|
loadOlder: S,
|
|
1285
|
-
runOf:
|
|
1286
|
-
run:
|
|
1287
|
-
runs:
|
|
1288
|
-
branchSelection:
|
|
1289
|
-
selectSibling:
|
|
1654
|
+
runOf: i((e) => u?.runOf(e), [u]),
|
|
1655
|
+
run: i((e) => u?.run(e), [u]),
|
|
1656
|
+
runs: i(() => u?.runs() ?? [], [u]),
|
|
1657
|
+
branchSelection: i((e) => u?.branchSelection(e) ?? Le, [u]),
|
|
1658
|
+
selectSibling: i((e, t) => {
|
|
1290
1659
|
u?.selectSibling(e, t);
|
|
1291
1660
|
}, [u]),
|
|
1292
|
-
send:
|
|
1293
|
-
if (!u) throw new e.ErrorInfo("unable to send; view is not available",
|
|
1661
|
+
send: i(async (t, n) => {
|
|
1662
|
+
if (!u) throw new e.ErrorInfo("unable to send; view is not available", N.InvalidArgument, 400);
|
|
1294
1663
|
return u.send(t, n);
|
|
1295
1664
|
}, [u]),
|
|
1296
|
-
regenerate:
|
|
1297
|
-
if (!u) throw new e.ErrorInfo("unable to regenerate; view is not available",
|
|
1665
|
+
regenerate: i(async (t, n) => {
|
|
1666
|
+
if (!u) throw new e.ErrorInfo("unable to regenerate; view is not available", N.InvalidArgument, 400);
|
|
1298
1667
|
return u.regenerate(t, n);
|
|
1299
1668
|
}, [u]),
|
|
1300
|
-
edit:
|
|
1301
|
-
if (!u) throw new e.ErrorInfo("unable to edit; view is not available",
|
|
1669
|
+
edit: i(async (t, n, r) => {
|
|
1670
|
+
if (!u) throw new e.ErrorInfo("unable to edit; view is not available", N.InvalidArgument, 400);
|
|
1302
1671
|
return u.edit(t, n, r);
|
|
1303
1672
|
}, [u])
|
|
1304
1673
|
};
|
|
1305
|
-
},
|
|
1306
|
-
let r =
|
|
1674
|
+
}, Re = ({ session: e, limit: t, skip: n } = {}) => {
|
|
1675
|
+
let r = X({
|
|
1307
1676
|
session: e,
|
|
1308
1677
|
skip: n
|
|
1309
|
-
}), [i,
|
|
1310
|
-
return
|
|
1678
|
+
}), [i, a] = l();
|
|
1679
|
+
return o(() => {
|
|
1311
1680
|
if (!r) {
|
|
1312
|
-
|
|
1681
|
+
a(void 0);
|
|
1313
1682
|
return;
|
|
1314
1683
|
}
|
|
1315
1684
|
let e = r.createView();
|
|
1316
|
-
return
|
|
1685
|
+
return a(e), () => {
|
|
1317
1686
|
e.close();
|
|
1318
1687
|
};
|
|
1319
|
-
}, [r]),
|
|
1688
|
+
}, [r]), $({
|
|
1320
1689
|
view: i,
|
|
1321
1690
|
limit: t,
|
|
1322
1691
|
skip: n
|
|
1323
1692
|
});
|
|
1324
|
-
},
|
|
1325
|
-
let t =
|
|
1693
|
+
}, ze = ({ session: e } = {}) => {
|
|
1694
|
+
let t = X({ session: e });
|
|
1326
1695
|
return {
|
|
1327
|
-
getRunNode:
|
|
1328
|
-
getNodeByCodecMessageId:
|
|
1329
|
-
getSiblingNodes:
|
|
1696
|
+
getRunNode: i((e) => t?.tree.getRunNode(e), [t]),
|
|
1697
|
+
getNodeByCodecMessageId: i((e) => t?.tree.getNodeByCodecMessageId(e), [t]),
|
|
1698
|
+
getSiblingNodes: i((e) => t?.tree.getSiblingNodes(e) ?? [], [t])
|
|
1330
1699
|
};
|
|
1331
|
-
},
|
|
1332
|
-
ClientSessionProvider:
|
|
1333
|
-
useClientSession: (e) =>
|
|
1334
|
-
useView: (e) =>
|
|
1335
|
-
useTree: (e) =>
|
|
1336
|
-
useAblyMessages: (e) =>
|
|
1337
|
-
useCreateView: (e) =>
|
|
1700
|
+
}, Be = () => ({
|
|
1701
|
+
ClientSessionProvider: Y,
|
|
1702
|
+
useClientSession: (e) => Ie(e ?? {}),
|
|
1703
|
+
useView: (e) => $(e ?? {}),
|
|
1704
|
+
useTree: (e) => ze(e ?? {}),
|
|
1705
|
+
useAblyMessages: (e) => Fe(e ?? {}),
|
|
1706
|
+
useCreateView: (e) => Re(e ?? {})
|
|
1338
1707
|
});
|
|
1339
1708
|
//#endregion
|
|
1340
|
-
export {
|
|
1709
|
+
export { Y as ClientSessionProvider, f as OBJECT_MODES, Be as createSessionHooks, Fe as useAblyMessages, Ie as useClientSession, Re as useCreateView, ze as useTree, $ as useView };
|
|
1341
1710
|
|
|
1342
1711
|
//# sourceMappingURL=ably-ai-transport-react.js.map
|