agentchatme 1.2.0 → 1.2.1
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/CHANGELOG.md +67 -2
- package/README.md +9 -4
- package/dist/index.cjs +72 -21
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +41 -21
- package/dist/index.d.ts +41 -21
- package/dist/index.js +72 -21
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -1789,6 +1789,9 @@ declare class RealtimeClient {
|
|
|
1789
1789
|
/** One error per run of rejected handshakes, then silent until hello.ok. */
|
|
1790
1790
|
private blockedAnnounced;
|
|
1791
1791
|
private dedupSeen;
|
|
1792
|
+
private inFlight;
|
|
1793
|
+
private drainAdopted;
|
|
1794
|
+
private generation;
|
|
1792
1795
|
private restDrainOrigin;
|
|
1793
1796
|
private drainSettlements;
|
|
1794
1797
|
private drainInFlight;
|
|
@@ -1825,17 +1828,26 @@ declare class RealtimeClient {
|
|
|
1825
1828
|
* Correctness rules, in cursor order:
|
|
1826
1829
|
* - A row failing minimal validation stops the drain: the clean prefix
|
|
1827
1830
|
* before it is processed and acked; the cursor never crosses the row.
|
|
1831
|
+
* - A row whose message another copy is still handling on this connection
|
|
1832
|
+
* (the server's reconnect backlog brings the same rows) is not
|
|
1833
|
+
* dispatched again, and the drain never waits for that copy: the cursor
|
|
1834
|
+
* covers the row only if the copy already finished cleanly, otherwise
|
|
1835
|
+
* it stops there and the next drain covers it as a dedup hit.
|
|
1828
1836
|
* - A row whose handler threw is not acked — nor is anything after it
|
|
1829
1837
|
* (the ack cursor is at-or-before) — so the server re-offers it; the
|
|
1830
1838
|
* dedup cache suppresses re-dispatch of its acked predecessors.
|
|
1831
|
-
* - A row
|
|
1832
|
-
*
|
|
1833
|
-
*
|
|
1834
|
-
*
|
|
1835
|
-
*
|
|
1839
|
+
* - A row no handler has been handed yet is not acked: acks FREEZE at the
|
|
1840
|
+
* last settled row for the remainder of the drain. That is a row
|
|
1841
|
+
* parked in the out-of-order buffer (awaiting seq gap-fill), and also a
|
|
1842
|
+
* row that was parked when the socket closed: in the default mode the
|
|
1843
|
+
* close clears the ordering buffers (`resetOrderStates`) without
|
|
1844
|
+
* dispatching them, possibly while the drain is still awaiting an
|
|
1845
|
+
* earlier row's handler. Covering either would mark a message
|
|
1846
|
+
* delivered that no handler saw — acked-but-undispatched is exactly the
|
|
1836
1847
|
* loss the ack protocol exists to prevent. Reading continues so the
|
|
1837
1848
|
* in-session gap-fill still resolves; the frozen tail is re-offered on
|
|
1838
|
-
* the next drain and absorbed by
|
|
1849
|
+
* the next drain (or the server's reconnect backlog) and absorbed by
|
|
1850
|
+
* the dedup cache.
|
|
1839
1851
|
*
|
|
1840
1852
|
* Concurrent calls are coalesced (the second returns immediately). The
|
|
1841
1853
|
* server-side ack pointer only moves forward, so re-running after a
|
|
@@ -1844,7 +1856,6 @@ declare class RealtimeClient {
|
|
|
1844
1856
|
*/
|
|
1845
1857
|
drainOfflineEnvelopes(): Promise<void>;
|
|
1846
1858
|
private runDrain;
|
|
1847
|
-
private isBufferedInOrderState;
|
|
1848
1859
|
/**
|
|
1849
1860
|
* Clear the reconnect backoff once this connection proves itself.
|
|
1850
1861
|
*
|
|
@@ -1996,6 +2007,10 @@ declare class RealtimeClient {
|
|
|
1996
2007
|
* acked. Resolves `false` when any handler threw or rejected: the
|
|
1997
2008
|
* message is NOT acked on any path and the server re-offers it.
|
|
1998
2009
|
*
|
|
2010
|
+
* A copy of a message whose first copy is still with the handlers is not
|
|
2011
|
+
* dispatched again: it resolves with the first copy's outcome (and, when
|
|
2012
|
+
* that succeeded, is acked like a dedup hit).
|
|
2013
|
+
*
|
|
1999
2014
|
* Ack routing: live frames (including server-pushed reconnect backlog
|
|
2000
2015
|
* and gap-fill rows) send a WS `{type:'ack'}` frame when ack-mode was
|
|
2001
2016
|
* negotiated; REST-drain rows are covered by the drain's sync/ack
|
|
@@ -2060,12 +2075,16 @@ declare class RealtimeClient {
|
|
|
2060
2075
|
* `dismiss` and `defer` are recorded at once, each anchored to the card's
|
|
2061
2076
|
* `preview.message_id` (`last_message_id` when a card has no preview).
|
|
2062
2077
|
* `reply` is NOT recorded by `run`: recording it marks the conversation read
|
|
2063
|
-
* and takes it off the tray
|
|
2064
|
-
*
|
|
2065
|
-
*
|
|
2066
|
-
*
|
|
2067
|
-
*
|
|
2068
|
-
*
|
|
2078
|
+
* and takes it off the tray. Each reply comes back with a `record()` the
|
|
2079
|
+
* host calls at the END of a turn that completed — never before the turn,
|
|
2080
|
+
* never at its start. A completed turn that looked counts as read even
|
|
2081
|
+
* when it chose not to send. A crashed turn, or one that could not look
|
|
2082
|
+
* (the AgentChat tools were not available to it), records nothing: the
|
|
2083
|
+
* conversation stays on the tray and the next wake retries. Recording at
|
|
2084
|
+
* the start would mark the conversation read before the turn's own
|
|
2085
|
+
* `agentchat_inbox` call, which then sees an empty tray and parks for its
|
|
2086
|
+
* wait window; and a crashed turn would leave the peer blocked by the
|
|
2087
|
+
* cold-DM "one message until a reply" rule.
|
|
2069
2088
|
*
|
|
2070
2089
|
* Failure policy
|
|
2071
2090
|
* ──────────────
|
|
@@ -2188,18 +2207,19 @@ interface GateReply {
|
|
|
2188
2207
|
/** The category the model attached, if any. */
|
|
2189
2208
|
category: ReplyDecisionCategory | null;
|
|
2190
2209
|
/**
|
|
2191
|
-
* Record the `reply` verdict. Call it
|
|
2192
|
-
*
|
|
2193
|
-
*
|
|
2194
|
-
*
|
|
2195
|
-
*
|
|
2196
|
-
* call
|
|
2210
|
+
* Record the `reply` verdict. Call it at the END of a turn that completed
|
|
2211
|
+
* — never before the turn, never at its start (the turn's own
|
|
2212
|
+
* `agentchat_inbox` call would then find the conversation already read
|
|
2213
|
+
* and an empty tray). A completed turn that looked counts as read even
|
|
2214
|
+
* when it chose not to send. On a crash, or when the turn could not look,
|
|
2215
|
+
* do not call it: the conversation stays on the tray and the next wake
|
|
2216
|
+
* retries. Idempotent on success; a failed call may be retried.
|
|
2197
2217
|
*/
|
|
2198
2218
|
record(): Promise<ReplyDecision>;
|
|
2199
2219
|
}
|
|
2200
2220
|
interface GateResult {
|
|
2201
2221
|
outcome: GateOutcome;
|
|
2202
|
-
/** Conversations whose verdict is `reply`:
|
|
2222
|
+
/** Conversations whose verdict is `reply`: run a turn for each and call its `record()` once that turn has completed. */
|
|
2203
2223
|
reply: GateReply[];
|
|
2204
2224
|
/** Every usable verdict, in the model's order. */
|
|
2205
2225
|
verdicts: Verdict[];
|
|
@@ -2216,7 +2236,7 @@ interface GateResult {
|
|
|
2216
2236
|
* Decide every card on the tray. `dismiss` and `defer` are recorded here,
|
|
2217
2237
|
* sequentially (a tray holds at most 50 cards), each anchored with
|
|
2218
2238
|
* `anchorOf(card)`; `reply` verdicts come back as `GateReply` entries whose
|
|
2219
|
-
* `record()` the host calls once the turn
|
|
2239
|
+
* `record()` the host calls once the turn has completed. Never throws: model
|
|
2220
2240
|
* and network failures land in the result.
|
|
2221
2241
|
*/
|
|
2222
2242
|
declare function run(options: RunGateOptions): Promise<GateResult>;
|
package/dist/index.d.ts
CHANGED
|
@@ -1789,6 +1789,9 @@ declare class RealtimeClient {
|
|
|
1789
1789
|
/** One error per run of rejected handshakes, then silent until hello.ok. */
|
|
1790
1790
|
private blockedAnnounced;
|
|
1791
1791
|
private dedupSeen;
|
|
1792
|
+
private inFlight;
|
|
1793
|
+
private drainAdopted;
|
|
1794
|
+
private generation;
|
|
1792
1795
|
private restDrainOrigin;
|
|
1793
1796
|
private drainSettlements;
|
|
1794
1797
|
private drainInFlight;
|
|
@@ -1825,17 +1828,26 @@ declare class RealtimeClient {
|
|
|
1825
1828
|
* Correctness rules, in cursor order:
|
|
1826
1829
|
* - A row failing minimal validation stops the drain: the clean prefix
|
|
1827
1830
|
* before it is processed and acked; the cursor never crosses the row.
|
|
1831
|
+
* - A row whose message another copy is still handling on this connection
|
|
1832
|
+
* (the server's reconnect backlog brings the same rows) is not
|
|
1833
|
+
* dispatched again, and the drain never waits for that copy: the cursor
|
|
1834
|
+
* covers the row only if the copy already finished cleanly, otherwise
|
|
1835
|
+
* it stops there and the next drain covers it as a dedup hit.
|
|
1828
1836
|
* - A row whose handler threw is not acked — nor is anything after it
|
|
1829
1837
|
* (the ack cursor is at-or-before) — so the server re-offers it; the
|
|
1830
1838
|
* dedup cache suppresses re-dispatch of its acked predecessors.
|
|
1831
|
-
* - A row
|
|
1832
|
-
*
|
|
1833
|
-
*
|
|
1834
|
-
*
|
|
1835
|
-
*
|
|
1839
|
+
* - A row no handler has been handed yet is not acked: acks FREEZE at the
|
|
1840
|
+
* last settled row for the remainder of the drain. That is a row
|
|
1841
|
+
* parked in the out-of-order buffer (awaiting seq gap-fill), and also a
|
|
1842
|
+
* row that was parked when the socket closed: in the default mode the
|
|
1843
|
+
* close clears the ordering buffers (`resetOrderStates`) without
|
|
1844
|
+
* dispatching them, possibly while the drain is still awaiting an
|
|
1845
|
+
* earlier row's handler. Covering either would mark a message
|
|
1846
|
+
* delivered that no handler saw — acked-but-undispatched is exactly the
|
|
1836
1847
|
* loss the ack protocol exists to prevent. Reading continues so the
|
|
1837
1848
|
* in-session gap-fill still resolves; the frozen tail is re-offered on
|
|
1838
|
-
* the next drain and absorbed by
|
|
1849
|
+
* the next drain (or the server's reconnect backlog) and absorbed by
|
|
1850
|
+
* the dedup cache.
|
|
1839
1851
|
*
|
|
1840
1852
|
* Concurrent calls are coalesced (the second returns immediately). The
|
|
1841
1853
|
* server-side ack pointer only moves forward, so re-running after a
|
|
@@ -1844,7 +1856,6 @@ declare class RealtimeClient {
|
|
|
1844
1856
|
*/
|
|
1845
1857
|
drainOfflineEnvelopes(): Promise<void>;
|
|
1846
1858
|
private runDrain;
|
|
1847
|
-
private isBufferedInOrderState;
|
|
1848
1859
|
/**
|
|
1849
1860
|
* Clear the reconnect backoff once this connection proves itself.
|
|
1850
1861
|
*
|
|
@@ -1996,6 +2007,10 @@ declare class RealtimeClient {
|
|
|
1996
2007
|
* acked. Resolves `false` when any handler threw or rejected: the
|
|
1997
2008
|
* message is NOT acked on any path and the server re-offers it.
|
|
1998
2009
|
*
|
|
2010
|
+
* A copy of a message whose first copy is still with the handlers is not
|
|
2011
|
+
* dispatched again: it resolves with the first copy's outcome (and, when
|
|
2012
|
+
* that succeeded, is acked like a dedup hit).
|
|
2013
|
+
*
|
|
1999
2014
|
* Ack routing: live frames (including server-pushed reconnect backlog
|
|
2000
2015
|
* and gap-fill rows) send a WS `{type:'ack'}` frame when ack-mode was
|
|
2001
2016
|
* negotiated; REST-drain rows are covered by the drain's sync/ack
|
|
@@ -2060,12 +2075,16 @@ declare class RealtimeClient {
|
|
|
2060
2075
|
* `dismiss` and `defer` are recorded at once, each anchored to the card's
|
|
2061
2076
|
* `preview.message_id` (`last_message_id` when a card has no preview).
|
|
2062
2077
|
* `reply` is NOT recorded by `run`: recording it marks the conversation read
|
|
2063
|
-
* and takes it off the tray
|
|
2064
|
-
*
|
|
2065
|
-
*
|
|
2066
|
-
*
|
|
2067
|
-
*
|
|
2068
|
-
*
|
|
2078
|
+
* and takes it off the tray. Each reply comes back with a `record()` the
|
|
2079
|
+
* host calls at the END of a turn that completed — never before the turn,
|
|
2080
|
+
* never at its start. A completed turn that looked counts as read even
|
|
2081
|
+
* when it chose not to send. A crashed turn, or one that could not look
|
|
2082
|
+
* (the AgentChat tools were not available to it), records nothing: the
|
|
2083
|
+
* conversation stays on the tray and the next wake retries. Recording at
|
|
2084
|
+
* the start would mark the conversation read before the turn's own
|
|
2085
|
+
* `agentchat_inbox` call, which then sees an empty tray and parks for its
|
|
2086
|
+
* wait window; and a crashed turn would leave the peer blocked by the
|
|
2087
|
+
* cold-DM "one message until a reply" rule.
|
|
2069
2088
|
*
|
|
2070
2089
|
* Failure policy
|
|
2071
2090
|
* ──────────────
|
|
@@ -2188,18 +2207,19 @@ interface GateReply {
|
|
|
2188
2207
|
/** The category the model attached, if any. */
|
|
2189
2208
|
category: ReplyDecisionCategory | null;
|
|
2190
2209
|
/**
|
|
2191
|
-
* Record the `reply` verdict. Call it
|
|
2192
|
-
*
|
|
2193
|
-
*
|
|
2194
|
-
*
|
|
2195
|
-
*
|
|
2196
|
-
* call
|
|
2210
|
+
* Record the `reply` verdict. Call it at the END of a turn that completed
|
|
2211
|
+
* — never before the turn, never at its start (the turn's own
|
|
2212
|
+
* `agentchat_inbox` call would then find the conversation already read
|
|
2213
|
+
* and an empty tray). A completed turn that looked counts as read even
|
|
2214
|
+
* when it chose not to send. On a crash, or when the turn could not look,
|
|
2215
|
+
* do not call it: the conversation stays on the tray and the next wake
|
|
2216
|
+
* retries. Idempotent on success; a failed call may be retried.
|
|
2197
2217
|
*/
|
|
2198
2218
|
record(): Promise<ReplyDecision>;
|
|
2199
2219
|
}
|
|
2200
2220
|
interface GateResult {
|
|
2201
2221
|
outcome: GateOutcome;
|
|
2202
|
-
/** Conversations whose verdict is `reply`:
|
|
2222
|
+
/** Conversations whose verdict is `reply`: run a turn for each and call its `record()` once that turn has completed. */
|
|
2203
2223
|
reply: GateReply[];
|
|
2204
2224
|
/** Every usable verdict, in the model's order. */
|
|
2205
2225
|
verdicts: Verdict[];
|
|
@@ -2216,7 +2236,7 @@ interface GateResult {
|
|
|
2216
2236
|
* Decide every card on the tray. `dismiss` and `defer` are recorded here,
|
|
2217
2237
|
* sequentially (a tray holds at most 50 cards), each anchored with
|
|
2218
2238
|
* `anchorOf(card)`; `reply` verdicts come back as `GateReply` entries whose
|
|
2219
|
-
* `record()` the host calls once the turn
|
|
2239
|
+
* `record()` the host calls once the turn has completed. Never throws: model
|
|
2220
2240
|
* and network failures land in the result.
|
|
2221
2241
|
*/
|
|
2222
2242
|
declare function run(options: RunGateOptions): Promise<GateResult>;
|
package/dist/index.js
CHANGED
|
@@ -274,7 +274,7 @@ function createAgentChatError(body, status, headers) {
|
|
|
274
274
|
}
|
|
275
275
|
|
|
276
276
|
// src/version.ts
|
|
277
|
-
var VERSION = "1.2.
|
|
277
|
+
var VERSION = "1.2.1" ;
|
|
278
278
|
|
|
279
279
|
// src/runtime.ts
|
|
280
280
|
function detectRuntime() {
|
|
@@ -1618,6 +1618,21 @@ var RealtimeClient = class {
|
|
|
1618
1618
|
// only AFTER a successful dispatch: adding earlier would let a failed
|
|
1619
1619
|
// dispatch suppress its own redelivery.
|
|
1620
1620
|
dedupSeen = /* @__PURE__ */ new Set();
|
|
1621
|
+
// Dispatches still running, by message id. A second copy of an id that is
|
|
1622
|
+
// here on the same connection (the server's reconnect backlog and the REST
|
|
1623
|
+
// drain bring the same stored rows; a slow handler is still on the first)
|
|
1624
|
+
// is not handed to the handlers again: it takes the first copy's outcome,
|
|
1625
|
+
// and nothing ever waits for it. An entry lives exactly as long as its
|
|
1626
|
+
// handlers run, so the map is bounded by the dispatches in flight.
|
|
1627
|
+
inFlight = /* @__PURE__ */ new Map();
|
|
1628
|
+
// Drain rows that adopted an in-flight copy instead of being dispatched.
|
|
1629
|
+
// The cursor reads that copy's outcome; it never waits for it.
|
|
1630
|
+
drainAdopted = /* @__PURE__ */ new WeakMap();
|
|
1631
|
+
// Bumped on every socket close. Copies adopt an in-flight first copy only
|
|
1632
|
+
// on the same connection; a re-offer on a later one is dispatched afresh
|
|
1633
|
+
// even while the first copy runs (a handler that never finishes must not
|
|
1634
|
+
// swallow every re-offer).
|
|
1635
|
+
generation = 0;
|
|
1621
1636
|
// Envelopes injected by the REST drain, as opposed to live WS frames.
|
|
1622
1637
|
// Drain rows are acknowledged via the REST sync/ack cursor, never via a
|
|
1623
1638
|
// WS ack frame; everything else on the message.new pipeline (live frames,
|
|
@@ -1806,17 +1821,26 @@ var RealtimeClient = class {
|
|
|
1806
1821
|
* Correctness rules, in cursor order:
|
|
1807
1822
|
* - A row failing minimal validation stops the drain: the clean prefix
|
|
1808
1823
|
* before it is processed and acked; the cursor never crosses the row.
|
|
1824
|
+
* - A row whose message another copy is still handling on this connection
|
|
1825
|
+
* (the server's reconnect backlog brings the same rows) is not
|
|
1826
|
+
* dispatched again, and the drain never waits for that copy: the cursor
|
|
1827
|
+
* covers the row only if the copy already finished cleanly, otherwise
|
|
1828
|
+
* it stops there and the next drain covers it as a dedup hit.
|
|
1809
1829
|
* - A row whose handler threw is not acked — nor is anything after it
|
|
1810
1830
|
* (the ack cursor is at-or-before) — so the server re-offers it; the
|
|
1811
1831
|
* dedup cache suppresses re-dispatch of its acked predecessors.
|
|
1812
|
-
* - A row
|
|
1813
|
-
*
|
|
1814
|
-
*
|
|
1815
|
-
*
|
|
1816
|
-
*
|
|
1832
|
+
* - A row no handler has been handed yet is not acked: acks FREEZE at the
|
|
1833
|
+
* last settled row for the remainder of the drain. That is a row
|
|
1834
|
+
* parked in the out-of-order buffer (awaiting seq gap-fill), and also a
|
|
1835
|
+
* row that was parked when the socket closed: in the default mode the
|
|
1836
|
+
* close clears the ordering buffers (`resetOrderStates`) without
|
|
1837
|
+
* dispatching them, possibly while the drain is still awaiting an
|
|
1838
|
+
* earlier row's handler. Covering either would mark a message
|
|
1839
|
+
* delivered that no handler saw — acked-but-undispatched is exactly the
|
|
1817
1840
|
* loss the ack protocol exists to prevent. Reading continues so the
|
|
1818
1841
|
* in-session gap-fill still resolves; the frozen tail is re-offered on
|
|
1819
|
-
* the next drain and absorbed by
|
|
1842
|
+
* the next drain (or the server's reconnect backlog) and absorbed by
|
|
1843
|
+
* the dedup cache.
|
|
1820
1844
|
*
|
|
1821
1845
|
* Concurrent calls are coalesced (the second returns immediately). The
|
|
1822
1846
|
* server-side ack pointer only moves forward, so re-running after a
|
|
@@ -1881,14 +1905,22 @@ var RealtimeClient = class {
|
|
|
1881
1905
|
const row = rows[i];
|
|
1882
1906
|
const envelope = envelopes[i];
|
|
1883
1907
|
if (!row || !envelope) break;
|
|
1884
|
-
const
|
|
1885
|
-
if (
|
|
1886
|
-
|
|
1887
|
-
if (!ok) {
|
|
1908
|
+
const adopted = this.drainAdopted.get(envelope);
|
|
1909
|
+
if (adopted) {
|
|
1910
|
+
if (!adopted.settled || !adopted.ok) {
|
|
1888
1911
|
acksFrozen = true;
|
|
1889
1912
|
break;
|
|
1890
1913
|
}
|
|
1891
|
-
|
|
1914
|
+
const adoptedId = row.delivery_id;
|
|
1915
|
+
if (typeof adoptedId === "string" && adoptedId.length > 0) ackCursor = adoptedId;
|
|
1916
|
+
continue;
|
|
1917
|
+
}
|
|
1918
|
+
const settlement = this.drainSettlements.get(envelope);
|
|
1919
|
+
if (!settlement) {
|
|
1920
|
+
acksFrozen = true;
|
|
1921
|
+
break;
|
|
1922
|
+
}
|
|
1923
|
+
if (!await settlement) {
|
|
1892
1924
|
acksFrozen = true;
|
|
1893
1925
|
break;
|
|
1894
1926
|
}
|
|
@@ -1920,14 +1952,6 @@ var RealtimeClient = class {
|
|
|
1920
1952
|
after = nextAfter;
|
|
1921
1953
|
}
|
|
1922
1954
|
}
|
|
1923
|
-
// True when a drain row is currently parked in the per-conversation
|
|
1924
|
-
// out-of-order buffer (its dispatch is deferred to the gap-fill
|
|
1925
|
-
// machinery — natural arrival, gap-fill fetch, or forced resolveGap).
|
|
1926
|
-
isBufferedInOrderState(row) {
|
|
1927
|
-
if (typeof row.seq !== "number") return false;
|
|
1928
|
-
const state = this.orderStates.get(row.conversation_id);
|
|
1929
|
-
return state !== void 0 && state.buffer.has(row.seq);
|
|
1930
|
-
}
|
|
1931
1955
|
/**
|
|
1932
1956
|
* Clear the reconnect backoff once this connection proves itself.
|
|
1933
1957
|
*
|
|
@@ -2004,6 +2028,7 @@ var RealtimeClient = class {
|
|
|
2004
2028
|
}
|
|
2005
2029
|
if (this.options.ackOnReceipt) this.flushParkedFrames("connection_closed");
|
|
2006
2030
|
this.resetOrderStates();
|
|
2031
|
+
this.generation++;
|
|
2007
2032
|
if (this.disposed) return;
|
|
2008
2033
|
if (info.initiator === "server" && duringHandshake && isAuthRejectionClose(info.code, info.reason)) {
|
|
2009
2034
|
this.enterBlocked(info.code, info.reason);
|
|
@@ -2356,6 +2381,10 @@ var RealtimeClient = class {
|
|
|
2356
2381
|
* acked. Resolves `false` when any handler threw or rejected: the
|
|
2357
2382
|
* message is NOT acked on any path and the server re-offers it.
|
|
2358
2383
|
*
|
|
2384
|
+
* A copy of a message whose first copy is still with the handlers is not
|
|
2385
|
+
* dispatched again: it resolves with the first copy's outcome (and, when
|
|
2386
|
+
* that succeeded, is acked like a dedup hit).
|
|
2387
|
+
*
|
|
2359
2388
|
* Ack routing: live frames (including server-pushed reconnect backlog
|
|
2360
2389
|
* and gap-fill rows) send a WS `{type:'ack'}` frame when ack-mode was
|
|
2361
2390
|
* negotiated; REST-drain rows are covered by the drain's sync/ack
|
|
@@ -2367,9 +2396,17 @@ var RealtimeClient = class {
|
|
|
2367
2396
|
const messageId = this.extractMessageId(message);
|
|
2368
2397
|
const ackAfterDispatch = !isDrainRow && !this.options.ackOnReceipt;
|
|
2369
2398
|
let settlement;
|
|
2399
|
+
const inFlight = messageId !== null ? this.inFlight.get(messageId) : void 0;
|
|
2400
|
+
const first = inFlight?.generation === this.generation ? inFlight : void 0;
|
|
2370
2401
|
if (messageId !== null && this.dedupHit(messageId)) {
|
|
2371
2402
|
settlement = Promise.resolve(true);
|
|
2372
2403
|
if (ackAfterDispatch) this.sendAckFrame(messageId);
|
|
2404
|
+
} else if (messageId !== null && first !== void 0) {
|
|
2405
|
+
if (isDrainRow) this.drainAdopted.set(message, first);
|
|
2406
|
+
settlement = first.promise.then((ok) => {
|
|
2407
|
+
if (ok && ackAfterDispatch) this.sendAckFrame(messageId);
|
|
2408
|
+
return ok;
|
|
2409
|
+
});
|
|
2373
2410
|
} else {
|
|
2374
2411
|
const handlers = this.handlers.get("message.new");
|
|
2375
2412
|
const pending = [];
|
|
@@ -2383,7 +2420,13 @@ var RealtimeClient = class {
|
|
|
2383
2420
|
}
|
|
2384
2421
|
}
|
|
2385
2422
|
}
|
|
2386
|
-
|
|
2423
|
+
const entry = {
|
|
2424
|
+
promise: Promise.resolve(false),
|
|
2425
|
+
generation: this.generation,
|
|
2426
|
+
settled: false,
|
|
2427
|
+
ok: false
|
|
2428
|
+
};
|
|
2429
|
+
const own = Promise.allSettled(pending).then((outcomes) => {
|
|
2387
2430
|
let ok = true;
|
|
2388
2431
|
for (const outcome of outcomes) {
|
|
2389
2432
|
if (outcome.status === "rejected") {
|
|
@@ -2391,6 +2434,11 @@ var RealtimeClient = class {
|
|
|
2391
2434
|
this.emitError(toError(outcome.reason, "message.new"));
|
|
2392
2435
|
}
|
|
2393
2436
|
}
|
|
2437
|
+
if (messageId !== null && this.inFlight.get(messageId) === entry) {
|
|
2438
|
+
this.inFlight.delete(messageId);
|
|
2439
|
+
}
|
|
2440
|
+
entry.settled = true;
|
|
2441
|
+
entry.ok = ok;
|
|
2394
2442
|
if (!ok) return false;
|
|
2395
2443
|
if (messageId !== null) {
|
|
2396
2444
|
this.dedupAdd(messageId);
|
|
@@ -2398,6 +2446,9 @@ var RealtimeClient = class {
|
|
|
2398
2446
|
}
|
|
2399
2447
|
return true;
|
|
2400
2448
|
});
|
|
2449
|
+
entry.promise = own;
|
|
2450
|
+
if (messageId !== null) this.inFlight.set(messageId, entry);
|
|
2451
|
+
settlement = own;
|
|
2401
2452
|
}
|
|
2402
2453
|
if (isDrainRow) this.drainSettlements.set(message, settlement);
|
|
2403
2454
|
return settlement;
|