@openclaw/discord 2026.6.33 → 2026.6.35

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.
Files changed (179) hide show
  1. package/dist/action-runtime-api.js +1 -1
  2. package/dist/{api-CjnGBhM3.js → api-1GXlSrYP.js} +42 -21
  3. package/dist/api.js +14 -14
  4. package/dist/{approval-handler.runtime-BWPQrzpP.js → approval-handler.runtime-Dv4p7REU.js} +3 -3
  5. package/dist/{audit-BwJ_2OjL.js → audit-DEVi9nIs.js} +3 -3
  6. package/dist/{channel-Ddnonoy4.js → channel-CQIRiosn.js} +15 -15
  7. package/dist/{channel-actions-CwmIqnYN.js → channel-actions-JziPEcBU.js} +2 -2
  8. package/dist/{channel-actions.runtime-DvpTfaJ4.js → channel-actions.runtime-D7L47LY3.js} +5 -5
  9. package/dist/channel-plugin-api.js +1 -1
  10. package/dist/{channel.setup-glZ5Y98a.js → channel.setup-oMeR19Cc.js} +2 -2
  11. package/dist/{components-j6lTZBsT.js → components-_s5UPJqU.js} +1 -1
  12. package/dist/{conversation-identity-36FFBwm5.js → conversation-identity-B0k94-bz.js} +2 -2
  13. package/dist/{directory-config-BYMFzL29.js → directory-config-CD1svkyN.js} +1 -1
  14. package/dist/directory-contract-api.js +1 -1
  15. package/dist/{directory-live-9JtJCiu8.js → directory-live-DBTsSRxl.js} +5 -5
  16. package/dist/{handle-action.guild-admin-xxGYrp-I.js → handle-action.guild-admin-CYIFMxh-.js} +2 -2
  17. package/dist/index.js +1 -1
  18. package/dist/{manager.runtime-BK6cf2Zu.js → manager.runtime-BZVdGX2d.js} +17 -9
  19. package/dist/{message-handler-BqpJIavO.js → message-handler-DZd9Bpq8.js} +7 -6
  20. package/dist/{message-handler.preflight-C90MxCcv.js → message-handler.preflight-Axv9J9EO.js} +12 -11
  21. package/dist/{message-handler.process-CeQ7Bd_3.js → message-handler.process-CG0zFS-Z.js} +10 -10
  22. package/dist/{message-utils-CJeAoISH.js → message-utils-Dbuw27gd.js} +1 -1
  23. package/dist/{outbound-adapter-Dxs6iKEq.js → outbound-adapter-CKC_kmUN.js} +6 -6
  24. package/dist/pluralkit-CfTReLl3.js +40 -0
  25. package/dist/{probe-esE_Oqdm.js → probe-DcgZIpyF.js} +3 -2
  26. package/dist/{probe.runtime-C3Atgpvr.js → probe.runtime-CVwM9L5E.js} +1 -1
  27. package/dist/{provider-C7376XFH.js → provider-CwwSXIIj.js} +102 -37
  28. package/dist/{provider-session.runtime-CCdqogGf.js → provider-session.runtime-reBWkqHZ.js} +3 -3
  29. package/dist/provider.runtime-BsmTLYS_.js +2 -0
  30. package/dist/{resolve-allowlist-common-3gB2Gpmm.js → resolve-allowlist-common-D7bZqAw3.js} +3 -3
  31. package/dist/{resolve-channels-B3gQf8QL.js → resolve-channels--oE-RnO6.js} +6 -6
  32. package/dist/{resolve-users-BO10y5fJ.js → resolve-users-QXo8CXBU.js} +5 -5
  33. package/dist/{runtime-CFlR3L9X.js → runtime-CF7ramAs.js} +7 -7
  34. package/dist/runtime-api.actions.js +2 -2
  35. package/dist/runtime-api.js +19 -19
  36. package/dist/runtime-api.lookup.js +5 -5
  37. package/dist/runtime-api.monitor-CzF8MUl_.js +6 -0
  38. package/dist/runtime-api.monitor.js +5 -5
  39. package/dist/runtime-api.send.js +5 -5
  40. package/dist/runtime-api.threads.js +3 -3
  41. package/dist/{send-JHxfT4Pk.js → send-Bb295iHT.js} +5 -5
  42. package/dist/{send.components-CN35E2Ck.js → send.components-COkDUO3B.js} +4 -4
  43. package/dist/{send.outbound-B-cA1Esv.js → send.outbound-B_sk0hNe.js} +3 -3
  44. package/dist/{send.receipt-CGecJDin.js → send.receipt-Cli6_9Sn.js} +19 -7
  45. package/dist/{send.shared-vcbfThdy.js → send.shared-BCG7MWnP.js} +2 -2
  46. package/dist/session-binding-contract-api.js +1 -1
  47. package/dist/setup-plugin-api.js +1 -1
  48. package/dist/{subagent-hooks-20wXhVzZ.js → subagent-hooks-CtqoWK4x.js} +2 -2
  49. package/dist/subagent-hooks-api.js +1 -1
  50. package/dist/{system-events-DR27TE7p.js → system-events-BxGNk_wE.js} +1 -1
  51. package/dist/{target-resolver-CDi1gI90.js → target-resolver-BcoK6b0g.js} +2 -2
  52. package/dist/targets-Q-ZoP7K4.js +3 -0
  53. package/dist/{thread-bindings-DU4T6nDo.js → thread-bindings-DJ_HT6GJ.js} +4 -4
  54. package/dist/{thread-bindings.discord-api-CYkr-3Gj.js → thread-bindings.discord-api-OPyjvgyz.js} +4 -4
  55. package/dist/{thread-bindings.manager-BqWs1UE2.js → thread-bindings.manager-Cd2HAVw_.js} +3 -3
  56. package/dist/{transcripts-source-D-lBI5ZD.js → transcripts-source-CPf5gURy.js} +1 -1
  57. package/dist/transcripts-source-api.js +1 -1
  58. package/dist/{typing-xr05bL-r.js → typing-DY0cwLdg.js} +1 -1
  59. package/node_modules/undici/README.md +8 -2
  60. package/node_modules/undici/docs/docs/api/Agent.md +248 -44
  61. package/node_modules/undici/docs/docs/api/BalancedPool.md +246 -48
  62. package/node_modules/undici/docs/docs/api/CacheStorage.md +171 -13
  63. package/node_modules/undici/docs/docs/api/CacheStore.md +294 -98
  64. package/node_modules/undici/docs/docs/api/Client.md +386 -179
  65. package/node_modules/undici/docs/docs/api/ClientStats.md +80 -14
  66. package/node_modules/undici/docs/docs/api/Connector.md +118 -36
  67. package/node_modules/undici/docs/docs/api/ContentType.md +65 -25
  68. package/node_modules/undici/docs/docs/api/Cookies.md +122 -71
  69. package/node_modules/undici/docs/docs/api/Debug.md +34 -18
  70. package/node_modules/undici/docs/docs/api/DiagnosticsChannel.md +364 -164
  71. package/node_modules/undici/docs/docs/api/Dispatcher.md +485 -1102
  72. package/node_modules/undici/docs/docs/api/EnvHttpProxyAgent.md +102 -87
  73. package/node_modules/undici/docs/docs/api/Errors.md +503 -40
  74. package/node_modules/undici/docs/docs/api/EventSource.md +298 -32
  75. package/node_modules/undici/docs/docs/api/Fetch.md +680 -31
  76. package/node_modules/undici/docs/docs/api/GlobalInstallation.md +78 -98
  77. package/node_modules/undici/docs/docs/api/H2CClient.md +298 -176
  78. package/node_modules/undici/docs/docs/api/Interceptors.md +418 -0
  79. package/node_modules/undici/docs/docs/api/MockAgent.md +333 -314
  80. package/node_modules/undici/docs/docs/api/MockCallHistory.md +272 -98
  81. package/node_modules/undici/docs/docs/api/MockCallHistoryLog.md +189 -26
  82. package/node_modules/undici/docs/docs/api/MockClient.md +151 -33
  83. package/node_modules/undici/docs/docs/api/MockErrors.md +56 -5
  84. package/node_modules/undici/docs/docs/api/MockPool.md +321 -258
  85. package/node_modules/undici/docs/docs/api/Pool.md +235 -43
  86. package/node_modules/undici/docs/docs/api/PoolStats.md +119 -13
  87. package/node_modules/undici/docs/docs/api/ProxyAgent.md +179 -160
  88. package/node_modules/undici/docs/docs/api/RedirectHandler.md +238 -63
  89. package/node_modules/undici/docs/docs/api/RetryAgent.md +113 -26
  90. package/node_modules/undici/docs/docs/api/RetryHandler.md +161 -77
  91. package/node_modules/undici/docs/docs/api/RoundRobinPool.md +166 -72
  92. package/node_modules/undici/docs/docs/api/SnapshotAgent.md +264 -542
  93. package/node_modules/undici/docs/docs/api/Socks5ProxyAgent.md +177 -196
  94. package/node_modules/undici/docs/docs/api/Util.md +68 -11
  95. package/node_modules/undici/docs/docs/api/WebSocket.md +475 -80
  96. package/node_modules/undici/docs/docs/api/api-lifecycle.md +100 -32
  97. package/node_modules/undici/docs/docs/best-practices/client-certificate.md +2 -0
  98. package/node_modules/undici/docs/docs/best-practices/crawling.md +3 -1
  99. package/node_modules/undici/docs/docs/best-practices/migrating-from-v7-to-v8.md +6 -4
  100. package/node_modules/undici/docs/docs/best-practices/mocking-request.md +9 -7
  101. package/node_modules/undici/docs/docs/best-practices/proxy.md +3 -1
  102. package/node_modules/undici/docs/docs/best-practices/undici-vs-builtin-fetch.md +10 -8
  103. package/node_modules/undici/docs/docs/best-practices/writing-tests.md +2 -0
  104. package/node_modules/undici/docs/docs/{GettingStarted.md → getting-started.md} +22 -19
  105. package/node_modules/undici/docs/docs/index.md +784 -0
  106. package/node_modules/undici/docs/docs/site.json +125 -0
  107. package/node_modules/undici/docs/docs/type-map.json +79 -0
  108. package/node_modules/undici/lib/api/api-request.js +7 -1
  109. package/node_modules/undici/lib/api/readable.js +42 -7
  110. package/node_modules/undici/lib/cache/memory-cache-store.js +56 -11
  111. package/node_modules/undici/lib/cache/sqlite-cache-store.js +7 -1
  112. package/node_modules/undici/lib/core/connect.js +16 -2
  113. package/node_modules/undici/lib/core/errors.js +20 -0
  114. package/node_modules/undici/lib/core/request.js +14 -3
  115. package/node_modules/undici/lib/core/symbols.js +3 -0
  116. package/node_modules/undici/lib/core/util.js +30 -2
  117. package/node_modules/undici/lib/dispatcher/agent.js +10 -5
  118. package/node_modules/undici/lib/dispatcher/balanced-pool.js +7 -4
  119. package/node_modules/undici/lib/dispatcher/client-h1.js +74 -9
  120. package/node_modules/undici/lib/dispatcher/client-h2.js +483 -151
  121. package/node_modules/undici/lib/dispatcher/client.js +76 -30
  122. package/node_modules/undici/lib/dispatcher/dispatcher-base.js +13 -1
  123. package/node_modules/undici/lib/dispatcher/dispatcher.js +15 -1
  124. package/node_modules/undici/lib/dispatcher/dispatcher1-wrapper.js +3 -0
  125. package/node_modules/undici/lib/dispatcher/env-http-proxy-agent.js +37 -8
  126. package/node_modules/undici/lib/dispatcher/proxy-agent.js +58 -7
  127. package/node_modules/undici/lib/dispatcher/retry-agent.js +3 -0
  128. package/node_modules/undici/lib/dispatcher/round-robin-pool.js +1 -1
  129. package/node_modules/undici/lib/dispatcher/socks5-proxy-agent.js +106 -22
  130. package/node_modules/undici/lib/global.js +36 -16
  131. package/node_modules/undici/lib/handler/cache-handler.js +297 -65
  132. package/node_modules/undici/lib/handler/cache-revalidation-handler.js +13 -3
  133. package/node_modules/undici/lib/handler/decorator-handler.js +7 -1
  134. package/node_modules/undici/lib/handler/deduplication-handler.js +12 -6
  135. package/node_modules/undici/lib/handler/redirect-handler.js +26 -5
  136. package/node_modules/undici/lib/handler/retry-handler.js +238 -51
  137. package/node_modules/undici/lib/interceptor/cache.js +221 -58
  138. package/node_modules/undici/lib/interceptor/decompress.js +124 -15
  139. package/node_modules/undici/lib/interceptor/deduplicate.js +5 -4
  140. package/node_modules/undici/lib/interceptor/dns.js +7 -0
  141. package/node_modules/undici/lib/interceptor/dump.js +10 -23
  142. package/node_modules/undici/lib/mock/mock-agent.js +13 -1
  143. package/node_modules/undici/lib/mock/mock-interceptor.js +25 -7
  144. package/node_modules/undici/lib/mock/mock-utils.js +246 -27
  145. package/node_modules/undici/lib/util/cache.js +415 -71
  146. package/node_modules/undici/lib/util/date.js +23 -6
  147. package/node_modules/undici/lib/web/cookies/parse.js +150 -146
  148. package/node_modules/undici/lib/web/cookies/util.js +79 -9
  149. package/node_modules/undici/lib/web/eventsource/eventsource-stream.js +28 -1
  150. package/node_modules/undici/lib/web/eventsource/eventsource.js +13 -3
  151. package/node_modules/undici/lib/web/eventsource/util.js +1 -1
  152. package/node_modules/undici/lib/web/fetch/body.js +2 -1
  153. package/node_modules/undici/lib/web/fetch/constants.js +1 -1
  154. package/node_modules/undici/lib/web/fetch/index.js +17 -2
  155. package/node_modules/undici/lib/web/fetch/request.js +2 -3
  156. package/node_modules/undici/lib/web/fetch/response.js +1 -3
  157. package/node_modules/undici/lib/web/fetch/util.js +10 -2
  158. package/node_modules/undici/lib/web/webidl/index.js +3 -3
  159. package/node_modules/undici/lib/web/websocket/connection.js +1 -1
  160. package/node_modules/undici/lib/web/websocket/permessage-deflate.js +5 -0
  161. package/node_modules/undici/lib/web/websocket/stream/websocketstream.js +8 -10
  162. package/node_modules/undici/lib/web/websocket/websocket.js +22 -0
  163. package/node_modules/undici/package.json +4 -4
  164. package/node_modules/undici/types/client.d.ts +53 -3
  165. package/node_modules/undici/types/cookies.d.ts +1 -1
  166. package/node_modules/undici/types/dispatcher.d.ts +3 -3
  167. package/node_modules/undici/types/errors.d.ts +10 -0
  168. package/node_modules/undici/types/handlers.d.ts +2 -0
  169. package/node_modules/undici/types/interceptors.d.ts +2 -0
  170. package/node_modules/undici/types/mock-agent.d.ts +11 -10
  171. package/node_modules/undici/types/mock-interceptor.d.ts +5 -1
  172. package/node_modules/undici/types/proxy-agent.d.ts +7 -0
  173. package/node_modules/undici/types/socks5-proxy-agent.d.ts +2 -0
  174. package/npm-shrinkwrap.json +7 -7
  175. package/package.json +6 -5
  176. package/dist/pluralkit-DI6RYaVj.js +0 -24
  177. package/dist/provider.runtime-D1m66kDS.js +0 -2
  178. package/dist/runtime-api.monitor-4oc58TSk.js +0 -6
  179. package/dist/targets-C6yd3y8R.js +0 -3
@@ -1,14 +1,15 @@
1
1
  # EventSource
2
2
 
3
- > ⚠️ Warning: the EventSource API is experimental.
3
+ <!--introduced_in=v6.5.0-->
4
+ <!--type=module-->
5
+ <!-- source_link=lib/web/eventsource/eventsource.js -->
4
6
 
5
- Undici exposes a WHATWG spec-compliant implementation of [EventSource](https://developer.mozilla.org/en-US/docs/Web/API/EventSource)
6
- for [Server-Sent Events](https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events).
7
+ > Stability: 1 - Experimental
7
8
 
8
- ## Instantiating EventSource
9
-
10
- Undici exports an EventSource class. You can instantiate the EventSource as
11
- follows:
9
+ `EventSource` is a [WHATWG-conformant][] implementation of the
10
+ [server-sent events][] interface. It opens a persistent HTTP connection to a
11
+ server that responds with the `text/event-stream` content type and dispatches
12
+ the events it receives without closing the connection.
12
13
 
13
14
  ```mjs
14
15
  import { EventSource } from 'undici'
@@ -19,11 +20,269 @@ eventSource.onmessage = (event) => {
19
20
  }
20
21
  ```
21
22
 
22
- ## Receiving events from a server
23
+ Constructing an `EventSource` for the first time emits a one-time
24
+ `ExperimentalWarning` with the code `'UNDICI-ES'`. The interface is also
25
+ installed onto `globalThis` as `globalThis.EventSource`.
26
+
27
+ ## Class: `EventSource`
28
+
29
+ <!-- YAML
30
+ added: v6.5.0
31
+ -->
32
+
33
+ > Stability: 1 - Experimental
34
+
35
+ * Extends: {EventTarget}
36
+
37
+ The `EventSource` interface receives server-sent events over an HTTP
38
+ connection. Instances are created with the [`new EventSource()`](#new-eventsourceurl-eventsourceinitdict)
39
+ constructor and emit [`'open'`](#event-open), [`'message'`](#event-message), and
40
+ [`'error'`](#event-error) events.
41
+
42
+ ### `new EventSource(url[, eventSourceInitDict])`
43
+
44
+ <!-- YAML
45
+ added: v6.5.0
46
+ -->
47
+
48
+ > Stability: 1 - Experimental
49
+
50
+ * `url` {string|URL} The URL of the event stream. Relative URLs are resolved
51
+ against the environment's base URL.
52
+ * `eventSourceInitDict` {Object} (optional)
53
+ * `withCredentials` {boolean} When `true`, the request is made with the
54
+ credentials mode set to `include` and CORS attribute state set to
55
+ `use-credentials`; otherwise the credentials mode is `same-origin`.
56
+ **Default:** `false`.
57
+ * `dispatcher` {Dispatcher} The dispatcher used for the underlying request.
58
+ **Default:** the global dispatcher.
59
+
60
+ > Stability: 0 - Deprecated. Use `node.dispatcher` instead.
61
+ * `node` {Object} undici-specific extensions to the standard
62
+ `EventSourceInit` dictionary.
63
+ * `dispatcher` {Dispatcher} The dispatcher used for the underlying request.
64
+ **Default:** the global dispatcher.
65
+ * `reconnectionTime` {number} The reconnection time, in milliseconds, to
66
+ wait before re-establishing a dropped connection. The server may override
67
+ this value with a `retry` field. **Default:** `3000`.
68
+
69
+ EventSource-specific limits can be configured on the dispatcher using the
70
+ `eventSource` option. See [`Client`][] for details.
71
+
72
+ Creates a new `EventSource` and immediately begins connecting to `url`. The
73
+ request is sent with the `Accept: text/event-stream` header, a cache mode of
74
+ `no-store`, and an initiator type of `other`.
75
+
76
+ If `url` cannot be parsed, a `SyntaxError` `DOMException` is thrown.
77
+
78
+ ```mjs
79
+ import { EventSource } from 'undici'
80
+
81
+ const eventSource = new EventSource('http://localhost:3000', {
82
+ withCredentials: true
83
+ })
84
+ ```
85
+
86
+ A custom [`Dispatcher`][] can be supplied to control the underlying request, for
87
+ example to add request headers:
88
+
89
+ ```mjs
90
+ import { EventSource, Agent } from 'undici'
91
+
92
+ class CustomHeaderAgent extends Agent {
93
+ dispatch (opts) {
94
+ opts.headers['x-custom-header'] = 'hello world'
95
+ return super.dispatch(...arguments)
96
+ }
97
+ }
98
+
99
+ const eventSource = new EventSource('http://localhost:3000', {
100
+ node: {
101
+ dispatcher: new CustomHeaderAgent()
102
+ }
103
+ })
104
+ ```
105
+
106
+ ### `eventSource.close()`
107
+
108
+ <!-- YAML
109
+ added: v6.5.0
110
+ -->
111
+
112
+ > Stability: 1 - Experimental
113
+
114
+ * Returns: {undefined}
115
+
116
+ Closes the connection, if any, aborts the underlying request, and sets
117
+ [`eventSource.readyState`](#eventsourcereadystate) to `CLOSED`. Once closed, the
118
+ `EventSource` does not attempt to reconnect. Calling `close()` on an already
119
+ closed `EventSource` has no effect.
120
+
121
+ ### `eventSource.readyState`
122
+
123
+ <!-- YAML
124
+ added: v6.5.0
125
+ -->
126
+
127
+ > Stability: 1 - Experimental
128
+
129
+ * Type: {number}
130
+
131
+ A read-only number representing the state of the connection. It is one of the
132
+ following constants:
133
+
134
+ * [`EventSource.CONNECTING`](#eventsourceconnecting) (`0`) — the connection has
135
+ not yet been established, or it was closed and is being re-established.
136
+ * [`EventSource.OPEN`](#eventsourceopen) (`1`) — the connection is open and
137
+ events are being dispatched as they are received.
138
+ * [`EventSource.CLOSED`](#eventsourceclosed) (`2`) — the connection is not open
139
+ and is not being re-established.
140
+
141
+ ### `eventSource.url`
142
+
143
+ <!-- YAML
144
+ added: v6.5.0
145
+ -->
146
+
147
+ > Stability: 1 - Experimental
148
+
149
+ * Type: {string}
150
+
151
+ A read-only string providing the URL of the event stream, after resolution
152
+ against the environment's base URL.
153
+
154
+ ### `eventSource.withCredentials`
155
+
156
+ <!-- YAML
157
+ added: v6.5.0
158
+ -->
159
+
160
+ > Stability: 1 - Experimental
161
+
162
+ * Type: {boolean}
163
+
164
+ A read-only boolean indicating whether the `EventSource` was instantiated with
165
+ CORS credentials (`true`), or not (`false`, the default). It reflects the
166
+ `withCredentials` option passed to the constructor.
167
+
168
+ ### `eventSource.onopen`
169
+
170
+ <!-- YAML
171
+ added: v6.5.0
172
+ -->
173
+
174
+ > Stability: 1 - Experimental
175
+
176
+ * Type: {Function|null} **Default:** `null`.
177
+
178
+ An event handler that is invoked when an [`'open'`](#event-open) event is
179
+ dispatched. Assigning a function registers it as the handler; assigning `null`
180
+ removes the current handler.
181
+
182
+ ### `eventSource.onmessage`
183
+
184
+ <!-- YAML
185
+ added: v6.5.0
186
+ -->
187
+
188
+ > Stability: 1 - Experimental
189
+
190
+ * Type: {Function|null} **Default:** `null`.
191
+
192
+ An event handler that is invoked when a [`'message'`](#event-message) event is
193
+ dispatched. Assigning a function registers it as the handler; assigning `null`
194
+ removes the current handler.
195
+
196
+ ### `eventSource.onerror`
197
+
198
+ <!-- YAML
199
+ added: v6.5.0
200
+ -->
201
+
202
+ > Stability: 1 - Experimental
203
+
204
+ * Type: {Function|null} **Default:** `null`.
205
+
206
+ An event handler that is invoked when an [`'error'`](#event-error) event is
207
+ dispatched. Assigning a function registers it as the handler; assigning `null`
208
+ removes the current handler.
209
+
210
+ ### `EventSource.CONNECTING`
211
+
212
+ <!-- YAML
213
+ added: v6.5.0
214
+ -->
215
+
216
+ > Stability: 1 - Experimental
217
+
218
+ * Type: {number}
219
+
220
+ The numeric constant `0`, representing the `CONNECTING`
221
+ [`readyState`](#eventsourcereadystate). It is defined as a read-only,
222
+ non-writable property on both the `EventSource` constructor and instances.
223
+
224
+ ### `EventSource.OPEN`
225
+
226
+ <!-- YAML
227
+ added: v6.5.0
228
+ -->
229
+
230
+ > Stability: 1 - Experimental
231
+
232
+ * Type: {number}
233
+
234
+ The numeric constant `1`, representing the `OPEN`
235
+ [`readyState`](#eventsourcereadystate). It is defined as a read-only,
236
+ non-writable property on both the `EventSource` constructor and instances.
237
+
238
+ ### `EventSource.CLOSED`
239
+
240
+ <!-- YAML
241
+ added: v6.5.0
242
+ -->
243
+
244
+ > Stability: 1 - Experimental
245
+
246
+ * Type: {number}
247
+
248
+ The numeric constant `2`, representing the `CLOSED`
249
+ [`readyState`](#eventsourcereadystate). It is defined as a read-only,
250
+ non-writable property on both the `EventSource` constructor and instances.
251
+
252
+ ### Event: `'open'`
253
+
254
+ <!-- YAML
255
+ added: v6.5.0
256
+ -->
257
+
258
+ > Stability: 1 - Experimental
259
+
260
+ Emitted when the connection is established and the
261
+ [`readyState`](#eventsourcereadystate) becomes `OPEN`. The listener receives an
262
+ {Event}.
263
+
264
+ ```mjs
265
+ import { EventSource } from 'undici'
266
+
267
+ const eventSource = new EventSource('http://localhost:3000')
268
+ eventSource.addEventListener('open', () => {
269
+ console.log('connection opened')
270
+ })
271
+ ```
272
+
273
+ ### Event: `'message'`
23
274
 
24
- EventSource connects to an HTTP endpoint that responds with a `text/event-stream`
25
- content type. The connection stays open and receives events as the server writes
26
- them.
275
+ <!-- YAML
276
+ added: v6.15.0
277
+ -->
278
+
279
+ > Stability: 1 - Experimental
280
+
281
+ Emitted when a message that has no explicit `event` field is received. The
282
+ listener receives a {MessageEvent} whose `data`, `lastEventId`, and `origin`
283
+ properties are populated from the server-sent event. Named events (those with an
284
+ `event` field) are dispatched under their own type and must be subscribed to with
285
+ [`addEventListener()`][].
27
286
 
28
287
  ```mjs
29
288
  import { createServer } from 'node:http'
@@ -49,44 +308,51 @@ const server = createServer((request, response) => {
49
308
  server.listen(3000, () => {
50
309
  const eventSource = new EventSource('http://localhost:3000')
51
310
 
311
+ // Named event, delivered under its own type.
52
312
  eventSource.addEventListener('ping', (event) => {
53
313
  console.log('ping:', event.data)
54
314
  })
55
315
 
316
+ // Unnamed event, delivered as 'message'.
56
317
  eventSource.onmessage = (event) => {
57
318
  console.log('message:', event.data)
58
319
  }
59
-
60
- eventSource.onerror = () => {
61
- eventSource.close()
62
- server.close()
63
- }
64
320
  })
65
321
  ```
66
322
 
67
- The `message` event receives events without an explicit `event:` field. Use
68
- `addEventListener()` to subscribe to named events.
323
+ ### Event: `'error'`
69
324
 
70
- ## Using a custom Dispatcher
325
+ <!-- YAML
326
+ added: v6.5.0
327
+ changes:
328
+ - version: v7.11.0
329
+ pr-url: https://github.com/nodejs/undici/pull/4247
330
+ description: The connection is no longer re-established after a network
331
+ error; the `EventSource` is closed instead.
332
+ -->
71
333
 
72
- Undici allows you to set your own Dispatcher in the EventSource constructor.
334
+ > Stability: 1 - Experimental
73
335
 
74
- An example which allows you to modify the request headers is:
336
+ Emitted when the connection fails or is interrupted. The listener receives an
337
+ {Event}. When the failure is recoverable, the `EventSource` transitions back to
338
+ `CONNECTING` and retries after the reconnection time; when it is not, the
339
+ `EventSource` transitions to `CLOSED` and does not reconnect.
75
340
 
76
341
  ```mjs
77
- import { EventSource, Agent } from 'undici'
342
+ import { EventSource } from 'undici'
78
343
 
79
- class CustomHeaderAgent extends Agent {
80
- dispatch (opts) {
81
- opts.headers['x-custom-header'] = 'hello world'
82
- return super.dispatch(...arguments)
344
+ const eventSource = new EventSource('http://localhost:3000')
345
+ eventSource.onerror = () => {
346
+ if (eventSource.readyState === EventSource.CLOSED) {
347
+ console.log('connection closed')
348
+ } else {
349
+ console.log('reconnecting')
83
350
  }
84
351
  }
85
-
86
- const eventSource = new EventSource('http://localhost:3000', {
87
- dispatcher: new CustomHeaderAgent()
88
- })
89
352
  ```
90
353
 
91
- More information about the EventSource API can be found on
92
- [MDN](https://developer.mozilla.org/en-US/docs/Web/API/EventSource).
354
+ [WHATWG-conformant]: https://html.spec.whatwg.org/multipage/server-sent-events.html#server-sent-events
355
+ [`Client`]: Client.md#new-clienturl-options
356
+ [`Dispatcher`]: Dispatcher.md#class-dispatcher
357
+ [`addEventListener()`]: https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener
358
+ [server-sent events]: https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events