@desplega.ai/agent-swarm 1.152.2 → 1.153.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.
Files changed (224) hide show
  1. package/README.md +1 -1
  2. package/dist/{acp-adapter-pfeje2v5.js → acp-adapter-ahmjxhek.js} +4 -4
  3. package/dist/{actions-0sttc7f5.js → actions-jzrfpkmn.js} +30 -26
  4. package/dist/{anthropic-messages-2y8nktar.js → anthropic-messages-9vqsbznt.js} +112 -84
  5. package/dist/{app-p8teva95.js → app-03na2vwb.js} +9 -6
  6. package/dist/{assistant-r45jnsrt.js → assistant-hfkxvhgt.js} +31 -27
  7. package/dist/{azure-openai-responses-f38x2avq.js → azure-openai-responses-04qwdwfq.js} +27 -13
  8. package/dist/{boot-reembed-je26h5y7.js → boot-reembed-c98xrad3.js} +8 -6
  9. package/dist/{boot-reembed-1qmybsd4.js → boot-reembed-zt3qm9xn.js} +9 -7
  10. package/dist/{boot-scrub-logs-gte3h1mm.js → boot-scrub-logs-jcqd8ksj.js} +6 -4
  11. package/dist/{claude-adapter-csc1mzka.js → claude-adapter-mgryg8g3.js} +17 -15
  12. package/dist/{claude-managed-adapter-dsmkcrjy.js → claude-managed-adapter-ea2aga6w.js} +3 -3
  13. package/dist/{claude-sdk-session-fcd6f078.js → claude-sdk-session-jjf4zss1.js} +17 -15
  14. package/dist/{cli-r2fpe7cx.js → cli-00w2c66p.js} +61 -55
  15. package/dist/{cli-fm4ytsdk.js → cli-0d9nbqxf.js} +1 -1
  16. package/dist/cli-0x5qzvkg.js +4279 -0
  17. package/dist/{cli-d3p82erb.js → cli-18amys3y.js} +9 -9
  18. package/dist/{cli-wbyk465z.js → cli-1hwnb4hc.js} +1 -1
  19. package/dist/{cli-xw7vak96.js → cli-3bcmp015.js} +5 -5
  20. package/dist/cli-3er6gcsn.js +1849 -0
  21. package/dist/{cli-c4eeb5q2.js → cli-5b6b62tz.js} +1 -1
  22. package/dist/{cli-4ahpr4sw.js → cli-5mbmvxnn.js} +5 -5
  23. package/dist/{cli-xy1cchaf.js → cli-5taqtpze.js} +235 -8
  24. package/dist/{cli-fmy65jdn.js → cli-6ks9xf1n.js} +7 -5
  25. package/dist/cli-7g9s78jf.js +2827 -0
  26. package/dist/{cli-jew3jda5.js → cli-7pnz2v6s.js} +2 -2
  27. package/dist/{cli-r84ctdxn.js → cli-83wkg402.js} +2 -2
  28. package/dist/{cli-jvy9qgjs.js → cli-a9scg8sv.js} +4 -4
  29. package/dist/{cli-4yc5d8fk.js → cli-avkd6mqv.js} +50 -0
  30. package/dist/{cli-ht5rs63n.js → cli-b2g6mzjc.js} +15 -6
  31. package/dist/{cli-jbmc0r7r.js → cli-bw0dfwkr.js} +1 -1
  32. package/dist/{cli-8wrympd7.js → cli-bzr0ftht.js} +26 -7
  33. package/dist/{cli-wpv5rgg2.js → cli-cdq08v3r.js} +2 -2
  34. package/dist/cli-cgj4hc12.js +18902 -0
  35. package/dist/cli-d6hk10xx.js +14075 -0
  36. package/dist/{cli-zvgj5zg8.js → cli-djvxhnc4.js} +31 -3324
  37. package/dist/{cli-s25avqg9.js → cli-e781c6f9.js} +1 -0
  38. package/dist/{cli-3bpzj8me.js → cli-eazstkad.js} +2 -2
  39. package/dist/{cli-s2qjdd6z.js → cli-eetrvv91.js} +1 -1
  40. package/dist/cli-h38x0qhg.js +6912 -0
  41. package/dist/{cli-9xvdm3bx.js → cli-h60qfasa.js} +742 -278
  42. package/dist/{pi-mono-adapter-jcqt71cg.js → cli-ja7mrygn.js} +67343 -101083
  43. package/dist/{cli-j8dggbcr.js → cli-k0g1sjzm.js} +23 -31
  44. package/dist/{cli-gphgnvpf.js → cli-m04pt18h.js} +2 -2
  45. package/dist/{cli-rgvp6r2x.js → cli-mcnhgnn1.js} +193 -4
  46. package/dist/{cli-j4nv2wqy.js → cli-mzgyhxbe.js} +10 -4
  47. package/dist/{cli-qn042eh7.js → cli-n0q9b7j4.js} +46 -1870
  48. package/dist/cli-n7h1kqpf.js +29 -0
  49. package/dist/{cli-ckz5t2hb.js → cli-nq0kgyxe.js} +5 -5
  50. package/dist/{cli-z3wkng35.js → cli-qrqhc31j.js} +151 -125
  51. package/dist/{cli-56h18ng2.js → cli-r8tdds6s.js} +1 -1
  52. package/dist/{cli-ch38q5z4.js → cli-rj7de4b2.js} +6788 -2541
  53. package/dist/{cli-qd65dvr6.js → cli-s5s1f2yn.js} +56 -40
  54. package/dist/{cli-kj76p1ez.js → cli-scwq51gn.js} +13 -7
  55. package/dist/{cli-2nnd56zt.js → cli-tdh4hjr2.js} +3 -2
  56. package/dist/{cli-c2mk1kgf.js → cli-v4en75c5.js} +8 -1
  57. package/dist/{cli-b9dd0h3k.js → cli-vw03hg5t.js} +3 -2
  58. package/dist/{cli-zvkq5csn.js → cli-ybpp1srm.js} +6 -6
  59. package/dist/cli-yn0a417a.js +4069 -0
  60. package/dist/{cli-gpqcs935.js → cli-ysc1kbet.js} +2 -2
  61. package/dist/{cli-zfzznn7c.js → cli-ytxs7mn1.js} +26 -2
  62. package/dist/cli-zcsyfw2z.js +3335 -0
  63. package/dist/{cli-4j8k1m4w.js → cli-zt1227k1.js} +1162 -192
  64. package/dist/cli-zy5w9gpt.js +230 -0
  65. package/dist/cli.js +26 -34
  66. package/dist/{codex-adapter-fxmpsabw.js → codex-adapter-8548daap.js} +12 -11
  67. package/dist/{codex-session-runner-rr1e47ea.js → codex-session-runner-2dad8p4x.js} +12 -11
  68. package/dist/{commands-0f5rxz51.js → commands-355dbpa8.js} +6 -4
  69. package/dist/{db-r3jxf3wy.js → db-4jjvwz1s.js} +6 -4
  70. package/dist/{dispatcher-06vph6q4.js → dispatcher-ca590nkz.js} +29 -25
  71. package/dist/dsh-adapter-rgvj6ykp.js +19 -0
  72. package/dist/{e2b-413b8t4v.js → e2b-93x1k0j5.js} +6 -7
  73. package/dist/{google-generative-ai-ndjmj5fa.js → google-generative-ai-xtw7tggr.js} +33 -73
  74. package/dist/{google-vertex-fr665tqs.js → google-vertex-zdqpms6n.js} +38 -68
  75. package/dist/{handlers-0hgtc910.js → handlers-2y6dqpvf.js} +32 -28
  76. package/dist/{hook-9kvrv1er.js → hook-0s8knepr.js} +11 -9
  77. package/dist/{hook-fbfhkat3.js → hook-k0gec254.js} +12 -10
  78. package/dist/{http-xbyx8k5j.js → http-jp2nb4zw.js} +300 -237
  79. package/dist/{index-tfsdxyv6.js → index-0wzg3sp3.js} +39 -24
  80. package/dist/{index-rnyahfn5.js → index-3mq6ce93.js} +29 -25
  81. package/dist/{index-jsw3aynb.js → index-42s7eezq.js} +29 -25
  82. package/dist/{cli-pdz9qde4.js → index-9ch1n761.js} +10 -11
  83. package/dist/{index-gpfn1741.js → index-b56xkbc7.js} +8 -6
  84. package/dist/{index-66xz5e9j.js → index-h5gs261z.js} +521 -9
  85. package/dist/{index-2sp0384z.js → index-kkeftv5h.js} +738 -21
  86. package/dist/{index-sgk50mbg.js → index-s37dbevy.js} +30 -26
  87. package/dist/index-w097eg0x.js +5 -0
  88. package/dist/jiti-loader-b4837mtm.js +34 -0
  89. package/dist/jiti-static-loader-q2g5ds0y.js +31267 -0
  90. package/dist/{keepalive-s3xpr7sw.js → keepalive-9pfw7t02.js} +8 -6
  91. package/dist/{lead-rq4n5r16.js → lead-7vcmcdq4.js} +44 -39
  92. package/dist/{maintenance-f0atj1ab.js → maintenance-x277jbpd.js} +9 -7
  93. package/dist/{mistral-conversations-qhr84ph3.js → mistral-conversations-zx0kn554.js} +24 -18
  94. package/dist/{node-x1g4v0pq.js → node-5qtycf6a.js} +16 -11
  95. package/dist/{oauth-refresh-sweep-q0t3bxre.js → oauth-refresh-sweep-5fwa7th2.js} +7 -5
  96. package/dist/{onboard-br5j1kch.js → onboard-17sv0f51.js} +103 -35
  97. package/dist/{openai-codex-responses-wy6a43wd.js → openai-codex-responses-4vjqzvjp.js} +33 -27
  98. package/dist/{openai-completions-32rdwmze.js → openai-completions-pxsmym7g.js} +52 -64
  99. package/dist/{openai-responses-6xwf7bzg.js → openai-responses-tmn0rqp0.js} +23 -24
  100. package/dist/{opencode-adapter-28axqa09.js → opencode-adapter-qbmv4tpy.js} +6 -6
  101. package/dist/{otel-impl-vdqge2nt.js → otel-impl-srjy4be4.js} +4 -4
  102. package/dist/{pi-messages-b1mbr6gp.js → pi-messages-txpjj39q.js} +3 -3
  103. package/dist/pi-mono-adapter-946a0sdd.js +1316 -0
  104. package/dist/{pricing-refresh-hb3691fd.js → pricing-refresh-vetcm563.js} +8 -6
  105. package/dist/{rbac-roles-jh280k9g.js → rbac-roles-cfzgr6r1.js} +8 -6
  106. package/dist/{rbac-roles-t78xt39b.js → rbac-roles-cmxaddmy.js} +7 -5
  107. package/dist/{render-v2-7p8r2ymg.js → render-v2-f9hzff72.js} +9 -6
  108. package/dist/{seed-pricing-hf889enh.js → seed-pricing-jggk6rsy.js} +7 -5
  109. package/dist/{setup-w6mb03jv.js → setup-8mfceb9t.js} +4 -5
  110. package/dist/virtual-modules-ax661xp0.js +54 -0
  111. package/dist/{work-objects-nt8gy1kj.js → work-objects-vdsdcczj.js} +32 -28
  112. package/dist/{worker-dwy617t0.js → worker-cd0nhyv1.js} +44 -39
  113. package/openapi.json +36 -14
  114. package/package.json +6 -6
  115. package/src/be/automation-preflight.ts +6 -4
  116. package/src/be/extensions/db.ts +35 -4
  117. package/src/be/models-catalog.ts +2 -0
  118. package/src/be/modelsdev-cache.json +213 -0
  119. package/src/be/rbac-audit.ts +2 -0
  120. package/src/be/seed-pricing.ts +3 -1
  121. package/src/be/swarm-config-guard.ts +1 -0
  122. package/src/commands/onboard/compose-generator.ts +6 -1
  123. package/src/commands/onboard/env-generator.ts +6 -1
  124. package/src/commands/onboard/manifest.ts +1 -0
  125. package/src/commands/onboard/steps/integration-slack.tsx +56 -16
  126. package/src/commands/onboard/steps/review.tsx +5 -0
  127. package/src/commands/onboard/types.ts +6 -0
  128. package/src/commands/onboard.tsx +5 -1
  129. package/src/commands/provider-credentials.ts +14 -2
  130. package/src/extensions/lifecycle.ts +15 -21
  131. package/src/http/agents.ts +2 -2
  132. package/src/http/config.ts +1 -1
  133. package/src/http/core.ts +5 -3
  134. package/src/http/extensions.ts +108 -34
  135. package/src/http/status.ts +22 -10
  136. package/src/prompts/base-prompt.ts +15 -7
  137. package/src/providers/claude-managed-models.ts +8 -0
  138. package/src/providers/codex-models.ts +15 -1
  139. package/src/providers/dsh-adapter.ts +248 -0
  140. package/src/providers/index.ts +5 -1
  141. package/src/providers/modelsdev-reasoning.json +50 -0
  142. package/src/rbac/legacy-policy.ts +15 -1
  143. package/src/rbac/types.ts +2 -0
  144. package/src/server.ts +7 -1
  145. package/src/slack/app.ts +32 -10
  146. package/src/slack/config.ts +29 -0
  147. package/src/telemetry.ts +2 -3
  148. package/src/tests/agents-harness-provider.test.ts +19 -0
  149. package/src/tests/agents-list-model-display.test.ts +60 -1
  150. package/src/tests/base-prompt.test.ts +25 -0
  151. package/src/tests/claude-managed-adapter.test.ts +6 -0
  152. package/src/tests/codex-gpt6-release.test.ts +97 -0
  153. package/src/tests/config-api-only-keys.test.ts +9 -0
  154. package/src/tests/context-window.test.ts +1 -0
  155. package/src/tests/dsh-adapter.test.ts +276 -0
  156. package/src/tests/e2e-nightly-report.test.ts +3 -3
  157. package/src/tests/e2e-redact.test.ts +2 -0
  158. package/src/tests/env-flag.test.ts +6 -0
  159. package/src/tests/extensions-db.test.ts +41 -0
  160. package/src/tests/extensions-http.test.ts +148 -4
  161. package/src/tests/extensions-lifecycle.test.ts +18 -0
  162. package/src/tests/extensions-mcp-tools.test.ts +9 -5
  163. package/src/tests/internal-ai/complete-structured.test.ts +32 -9
  164. package/src/tests/internal-ai/credentials.test.ts +4 -4
  165. package/src/tests/internal-ai/models.test.ts +20 -0
  166. package/src/tests/migration-046-budgets.test.ts +2 -0
  167. package/src/tests/model-control.test.ts +2 -2
  168. package/src/tests/onboard-compose.test.ts +14 -0
  169. package/src/tests/onboard-env.test.ts +17 -0
  170. package/src/tests/onboard-manifest.test.ts +12 -0
  171. package/src/tests/opus-5-5-registry.test.ts +48 -0
  172. package/src/tests/pricing-refresh.test.ts +1 -1
  173. package/src/tests/pricing-routes.test.ts +15 -3
  174. package/src/tests/provider-registration.test.ts +5 -2
  175. package/src/tests/rbac-admission-e2e.test.ts +54 -0
  176. package/src/tests/rbac-e2e-helpers.ts +2 -0
  177. package/src/tests/rbac-engine.test.ts +32 -0
  178. package/src/tests/rbac-wire-e2e.test.ts +33 -0
  179. package/src/tests/reasoning-effort.test.ts +8 -0
  180. package/src/tests/reload-config.test.ts +33 -0
  181. package/src/tests/session-costs-model-key-normalize.test.ts +1 -0
  182. package/src/tests/slack-config.test.ts +136 -0
  183. package/src/tests/slack-mode-lifecycle.test.ts +69 -0
  184. package/src/tests/status.test.ts +22 -2
  185. package/src/tests/task-tool-preload-mcp.test.ts +3 -1
  186. package/src/tests/telemetry-init.test.ts +18 -0
  187. package/src/tests/workflow-llm.test.ts +3 -3
  188. package/src/tools/extension-common.ts +4 -0
  189. package/src/tools/extension-install.ts +1 -1
  190. package/src/tools/extension-list.ts +4 -3
  191. package/src/types.ts +17 -8
  192. package/src/utils/context-window.ts +1 -0
  193. package/src/utils/credentials.ts +8 -0
  194. package/src/utils/internal-ai/complete-structured.ts +8 -0
  195. package/src/utils/internal-ai/models.ts +5 -5
  196. package/templates/schedules/daily-status-report/content.md +25 -12
  197. package/templates/schedules/daily-workflow-health-audit/content.md +1 -1
  198. package/templates/skills/swarm-extensions/content.md +9 -5
  199. package/dist/cli-4wppfkcm.js +0 -16384
  200. package/dist/cli-55qrx3q8.js +0 -6041
  201. package/dist/cli-cg4vnyh4.js +0 -305
  202. package/dist/cli-jyetr64j.js +0 -52
  203. package/dist/cli-pp9ax9pa.js +0 -520
  204. package/dist/cli-qa66qaf0.js +0 -6076
  205. package/dist/cli-qghpvca2.js +0 -590
  206. package/dist/cli-rembwgt8.js +0 -861
  207. package/dist/cli-tcvj7j2r.js +0 -1971
  208. package/dist/cli-vfcth11k.js +0 -36
  209. package/dist/cli-w1d1bgkk.js +0 -1422
  210. package/dist/cli-y6x0gqtg.js +0 -5977
  211. package/dist/es5-tj3tn4jj.js +0 -844
  212. package/dist/index-1kq5hw2p.js +0 -467
  213. package/dist/index-1p8wdstt.js +0 -7
  214. package/dist/index-8fdjzb2f.js +0 -100
  215. package/dist/index-bxmwzbgw.js +0 -365
  216. package/dist/index-nzerxd5z.js +0 -7
  217. package/dist/index-pyymnzat.js +0 -1168
  218. package/dist/index-qv6atbab.js +0 -619
  219. package/dist/index-rja32qa7.js +0 -801
  220. package/dist/index-tzg5srfp.js +0 -211
  221. package/dist/index-vhncw983.js +0 -90
  222. package/dist/index-xk036zsk.js +0 -859
  223. package/dist/index-zyazbzcb.js +0 -6
  224. package/dist/{claude-managed-setup-48dwg9bv.js → claude-managed-setup-f5pmsyrp.js} +3 -3
@@ -1,861 +0,0 @@
1
- import {
2
- require_protocols
3
- } from "./cli-qa66qaf0.js";
4
- import {
5
- __commonJS,
6
- __require
7
- } from "./cli-bc05qbss.js";
8
-
9
- // node_modules/@smithy/node-http-handler/dist-cjs/index.js
10
- var require_dist_cjs = __commonJS(function(exports) {
11
- var node_https = __require("node:https");
12
- var protocols = require_protocols();
13
- var node_stream = __require("node:stream");
14
- var http2 = __require("node:http2");
15
- function buildAbortError(abortSignal) {
16
- const reason = abortSignal && typeof abortSignal === "object" && "reason" in abortSignal ? abortSignal.reason : undefined;
17
- if (reason) {
18
- if (reason instanceof Error) {
19
- const abortError3 = new Error("Request aborted");
20
- abortError3.name = "AbortError";
21
- abortError3.cause = reason;
22
- return abortError3;
23
- }
24
- const abortError2 = new Error(String(reason));
25
- abortError2.name = "AbortError";
26
- return abortError2;
27
- }
28
- const abortError = new Error("Request aborted");
29
- abortError.name = "AbortError";
30
- return abortError;
31
- }
32
- var NODEJS_TIMEOUT_ERROR_CODES = ["ECONNRESET", "EPIPE", "ETIMEDOUT"];
33
- var getTransformedHeaders = (headers) => {
34
- const transformedHeaders = {};
35
- for (const name in headers) {
36
- const headerValues = headers[name];
37
- transformedHeaders[name] = Array.isArray(headerValues) ? headerValues.join(",") : headerValues;
38
- }
39
- return transformedHeaders;
40
- };
41
- var timing = {
42
- setTimeout: (cb, ms) => setTimeout(cb, ms),
43
- clearTimeout: (timeoutId) => clearTimeout(timeoutId)
44
- };
45
- var DEFER_EVENT_LISTENER_TIME$2 = 1000;
46
- var setConnectionTimeout = (request, reject, timeoutInMs = 0) => {
47
- if (!timeoutInMs) {
48
- return -1;
49
- }
50
- const registerTimeout = (offset) => {
51
- const timeoutId = timing.setTimeout(() => {
52
- request.destroy();
53
- reject(Object.assign(new Error(`@smithy/node-http-handler - the request socket did not establish a connection with the server within the configured timeout of ${timeoutInMs} ms.`), {
54
- name: "TimeoutError"
55
- }));
56
- }, timeoutInMs - offset);
57
- const doWithSocket = (socket) => {
58
- if (socket?.connecting) {
59
- socket.on("connect", () => {
60
- timing.clearTimeout(timeoutId);
61
- });
62
- } else {
63
- timing.clearTimeout(timeoutId);
64
- }
65
- };
66
- if (request.socket) {
67
- doWithSocket(request.socket);
68
- } else {
69
- request.on("socket", doWithSocket);
70
- }
71
- };
72
- if (timeoutInMs < 2000) {
73
- registerTimeout(0);
74
- return 0;
75
- }
76
- return timing.setTimeout(registerTimeout.bind(null, DEFER_EVENT_LISTENER_TIME$2), DEFER_EVENT_LISTENER_TIME$2);
77
- };
78
- var setRequestTimeout = (req, reject, timeoutInMs = 0, throwOnRequestTimeout, logger) => {
79
- if (timeoutInMs) {
80
- return timing.setTimeout(() => {
81
- let msg = `@smithy/node-http-handler - [${throwOnRequestTimeout ? "ERROR" : "WARN"}] a request has exceeded the configured ${timeoutInMs} ms requestTimeout.`;
82
- if (throwOnRequestTimeout) {
83
- const error = Object.assign(new Error(msg), {
84
- name: "TimeoutError",
85
- code: "ETIMEDOUT"
86
- });
87
- req.destroy(error);
88
- reject(error);
89
- } else {
90
- msg += ` Init client requestHandler with throwOnRequestTimeout=true to turn this into an error.`;
91
- logger?.warn?.(msg);
92
- }
93
- }, timeoutInMs);
94
- }
95
- return -1;
96
- };
97
- var DEFER_EVENT_LISTENER_TIME$1 = 3000;
98
- var setSocketKeepAlive = (request, { keepAlive, keepAliveMsecs }, deferTimeMs = DEFER_EVENT_LISTENER_TIME$1) => {
99
- if (keepAlive !== true) {
100
- return -1;
101
- }
102
- const registerListener = () => {
103
- if (request.socket) {
104
- request.socket.setKeepAlive(keepAlive, keepAliveMsecs || 0);
105
- } else {
106
- request.on("socket", (socket) => {
107
- socket.setKeepAlive(keepAlive, keepAliveMsecs || 0);
108
- });
109
- }
110
- };
111
- if (deferTimeMs === 0) {
112
- registerListener();
113
- return 0;
114
- }
115
- return timing.setTimeout(registerListener, deferTimeMs);
116
- };
117
- var DEFER_EVENT_LISTENER_TIME = 3000;
118
- var setSocketTimeout = (request, reject, timeoutInMs = 0) => {
119
- const registerTimeout = (offset) => {
120
- const timeout = timeoutInMs - offset;
121
- const onTimeout = () => {
122
- request.destroy();
123
- reject(Object.assign(new Error(`@smithy/node-http-handler - the request socket timed out after ${timeoutInMs} ms of inactivity (configured by client requestHandler).`), { name: "TimeoutError" }));
124
- };
125
- if (request.socket) {
126
- request.socket.setTimeout(timeout, onTimeout);
127
- request.on("close", () => request.socket?.removeListener("timeout", onTimeout));
128
- } else {
129
- request.setTimeout(timeout, onTimeout);
130
- }
131
- };
132
- if (0 < timeoutInMs && timeoutInMs < 6000) {
133
- registerTimeout(0);
134
- return 0;
135
- }
136
- return timing.setTimeout(registerTimeout.bind(null, timeoutInMs === 0 ? 0 : DEFER_EVENT_LISTENER_TIME), DEFER_EVENT_LISTENER_TIME);
137
- };
138
- var MIN_WAIT_TIME = 6000;
139
- async function writeRequestBody(httpRequest, request, maxContinueTimeoutMs = MIN_WAIT_TIME, externalAgent = false) {
140
- const headers = request.headers;
141
- const expect = headers ? headers.Expect || headers.expect : undefined;
142
- let timeoutId = -1;
143
- let sendBody = true;
144
- if (!externalAgent && expect === "100-continue") {
145
- sendBody = await Promise.race([
146
- new Promise((resolve) => {
147
- timeoutId = Number(timing.setTimeout(() => resolve(true), Math.max(MIN_WAIT_TIME, maxContinueTimeoutMs)));
148
- }),
149
- new Promise((resolve) => {
150
- httpRequest.on("continue", () => {
151
- timing.clearTimeout(timeoutId);
152
- resolve(true);
153
- });
154
- httpRequest.on("response", () => {
155
- timing.clearTimeout(timeoutId);
156
- resolve(false);
157
- });
158
- httpRequest.on("error", () => {
159
- timing.clearTimeout(timeoutId);
160
- resolve(false);
161
- });
162
- })
163
- ]);
164
- }
165
- if (sendBody) {
166
- writeBody(httpRequest, request.body);
167
- }
168
- }
169
- function writeBody(httpRequest, body) {
170
- if (body instanceof node_stream.Readable) {
171
- body.pipe(httpRequest);
172
- return;
173
- }
174
- if (body) {
175
- const isBuffer = Buffer.isBuffer(body);
176
- const isString = typeof body === "string";
177
- if (isBuffer || isString) {
178
- if (isBuffer && body.byteLength === 0) {
179
- httpRequest.end();
180
- } else {
181
- httpRequest.end(body);
182
- }
183
- return;
184
- }
185
- const uint8 = body;
186
- if (typeof uint8 === "object" && uint8.buffer && typeof uint8.byteOffset === "number" && typeof uint8.byteLength === "number") {
187
- httpRequest.end(Buffer.from(uint8.buffer, uint8.byteOffset, uint8.byteLength));
188
- return;
189
- }
190
- httpRequest.end(Buffer.from(body));
191
- return;
192
- }
193
- httpRequest.end();
194
- }
195
- var DEFAULT_REQUEST_TIMEOUT = 0;
196
- var hAgent = undefined;
197
- var hRequest = undefined;
198
-
199
- class NodeHttpHandler {
200
- config;
201
- configProvider;
202
- socketWarningTimestamp = 0;
203
- externalAgent = false;
204
- metadata = { handlerProtocol: "http/1.1" };
205
- static create(instanceOrOptions) {
206
- if (typeof instanceOrOptions?.handle === "function") {
207
- return instanceOrOptions;
208
- }
209
- return new NodeHttpHandler(instanceOrOptions);
210
- }
211
- static checkSocketUsage(agent, socketWarningTimestamp, logger = console) {
212
- const { sockets, requests, maxSockets } = agent;
213
- if (typeof maxSockets !== "number" || maxSockets === Infinity) {
214
- return socketWarningTimestamp;
215
- }
216
- const interval = 15000;
217
- if (Date.now() - interval < socketWarningTimestamp) {
218
- return socketWarningTimestamp;
219
- }
220
- if (sockets && requests) {
221
- for (const origin in sockets) {
222
- const socketsInUse = sockets[origin]?.length ?? 0;
223
- const requestsEnqueued = requests[origin]?.length ?? 0;
224
- if (socketsInUse >= maxSockets && requestsEnqueued >= 2 * maxSockets) {
225
- logger?.warn?.(`@smithy/node-http-handler:WARN - socket usage at capacity=${socketsInUse} and ${requestsEnqueued} additional requests are enqueued.
226
- See https://docs.aws.amazon.com/sdk-for-javascript/v3/developer-guide/node-configuring-maxsockets.html
227
- or increase socketAcquisitionWarningTimeout=(millis) in the NodeHttpHandler config.`);
228
- return Date.now();
229
- }
230
- }
231
- }
232
- return socketWarningTimestamp;
233
- }
234
- constructor(options) {
235
- this.configProvider = new Promise((resolve, reject) => {
236
- if (typeof options === "function") {
237
- options().then((_options) => {
238
- resolve(this.resolveDefaultConfig(_options));
239
- }).catch(reject);
240
- } else {
241
- resolve(this.resolveDefaultConfig(options));
242
- }
243
- });
244
- }
245
- destroy() {
246
- this.config?.httpAgent?.destroy();
247
- this.config?.httpsAgent?.destroy();
248
- }
249
- async handle(request, { abortSignal, requestTimeout } = {}) {
250
- if (!this.config) {
251
- this.config = await this.configProvider;
252
- }
253
- const config = this.config;
254
- const isSSL = request.protocol === "https:";
255
- if (!isSSL && !this.config.httpAgent) {
256
- this.config.httpAgent = await this.config.httpAgentProvider();
257
- }
258
- return new Promise((_resolve, _reject) => {
259
- let writeRequestBodyPromise = undefined;
260
- let socketWarningTimeoutId = -1;
261
- let connectionTimeoutId = -1;
262
- let requestTimeoutId = -1;
263
- let socketTimeoutId = -1;
264
- let keepAliveTimeoutId = -1;
265
- const clearTimeouts = () => {
266
- timing.clearTimeout(socketWarningTimeoutId);
267
- timing.clearTimeout(connectionTimeoutId);
268
- timing.clearTimeout(requestTimeoutId);
269
- timing.clearTimeout(socketTimeoutId);
270
- timing.clearTimeout(keepAliveTimeoutId);
271
- };
272
- const resolve = async (arg) => {
273
- await writeRequestBodyPromise;
274
- clearTimeouts();
275
- _resolve(arg);
276
- };
277
- const reject = async (arg) => {
278
- await writeRequestBodyPromise;
279
- clearTimeouts();
280
- _reject(arg);
281
- };
282
- if (abortSignal?.aborted) {
283
- const abortError = buildAbortError(abortSignal);
284
- reject(abortError);
285
- return;
286
- }
287
- const headers = request.headers;
288
- const expectContinue = headers ? (headers.Expect ?? headers.expect) === "100-continue" : false;
289
- let agent = isSSL ? config.httpsAgent : config.httpAgent;
290
- if (expectContinue && !this.externalAgent) {
291
- agent = new (isSSL ? node_https.Agent : hAgent)({
292
- keepAlive: false,
293
- maxSockets: Infinity
294
- });
295
- }
296
- socketWarningTimeoutId = timing.setTimeout(() => {
297
- this.socketWarningTimestamp = NodeHttpHandler.checkSocketUsage(agent, this.socketWarningTimestamp, config.logger);
298
- }, config.socketAcquisitionWarningTimeout ?? (config.requestTimeout ?? 2000) + (config.connectionTimeout ?? 1000));
299
- const queryString = request.query ? protocols.buildQueryString(request.query) : "";
300
- let auth = undefined;
301
- if (request.username != null || request.password != null) {
302
- const username = request.username ?? "";
303
- const password = request.password ?? "";
304
- auth = `${username}:${password}`;
305
- }
306
- let path = request.path;
307
- if (queryString) {
308
- path += `?${queryString}`;
309
- }
310
- if (request.fragment) {
311
- path += `#${request.fragment}`;
312
- }
313
- let hostname = request.hostname ?? "";
314
- if (hostname[0] === "[" && hostname.endsWith("]")) {
315
- hostname = request.hostname.slice(1, -1);
316
- } else {
317
- hostname = request.hostname;
318
- }
319
- const nodeHttpsOptions = {
320
- headers: request.headers,
321
- host: hostname,
322
- method: request.method,
323
- path,
324
- port: request.port,
325
- agent,
326
- auth
327
- };
328
- const requestFunc = isSSL ? node_https.request : hRequest;
329
- const req = requestFunc(nodeHttpsOptions, (res) => {
330
- const httpResponse = new protocols.HttpResponse({
331
- statusCode: res.statusCode || -1,
332
- reason: res.statusMessage,
333
- headers: getTransformedHeaders(res.headers),
334
- body: res
335
- });
336
- resolve({ response: httpResponse });
337
- });
338
- req.on("error", (err) => {
339
- if (NODEJS_TIMEOUT_ERROR_CODES.includes(err.code)) {
340
- reject(Object.assign(err, { name: "TimeoutError" }));
341
- } else {
342
- reject(err);
343
- }
344
- });
345
- if (abortSignal) {
346
- const onAbort = () => {
347
- req.destroy();
348
- const abortError = buildAbortError(abortSignal);
349
- reject(abortError);
350
- };
351
- if (typeof abortSignal.addEventListener === "function") {
352
- const signal = abortSignal;
353
- signal.addEventListener("abort", onAbort, { once: true });
354
- req.once("close", () => signal.removeEventListener("abort", onAbort));
355
- } else {
356
- abortSignal.onabort = onAbort;
357
- }
358
- }
359
- const effectiveRequestTimeout = requestTimeout ?? config.requestTimeout;
360
- connectionTimeoutId = setConnectionTimeout(req, reject, config.connectionTimeout);
361
- requestTimeoutId = setRequestTimeout(req, reject, effectiveRequestTimeout, config.throwOnRequestTimeout, config.logger ?? console);
362
- socketTimeoutId = setSocketTimeout(req, reject, config.socketTimeout);
363
- const httpAgent = nodeHttpsOptions.agent;
364
- if (typeof httpAgent === "object" && "keepAlive" in httpAgent) {
365
- keepAliveTimeoutId = setSocketKeepAlive(req, {
366
- keepAlive: httpAgent.keepAlive,
367
- keepAliveMsecs: httpAgent.keepAliveMsecs
368
- });
369
- }
370
- writeRequestBodyPromise = writeRequestBody(req, request, effectiveRequestTimeout, this.externalAgent).catch((e) => {
371
- clearTimeouts();
372
- return _reject(e);
373
- });
374
- });
375
- }
376
- updateHttpClientConfig(key, value) {
377
- this.config = undefined;
378
- this.configProvider = this.configProvider.then((config) => {
379
- return {
380
- ...config,
381
- [key]: value
382
- };
383
- });
384
- }
385
- httpHandlerConfigs() {
386
- return this.config ?? {};
387
- }
388
- resolveDefaultConfig(options) {
389
- const { requestTimeout, connectionTimeout, socketTimeout, socketAcquisitionWarningTimeout, httpAgent, httpsAgent, throwOnRequestTimeout, logger } = options || {};
390
- const keepAlive = true;
391
- const maxSockets = 50;
392
- return {
393
- connectionTimeout,
394
- requestTimeout,
395
- socketTimeout,
396
- socketAcquisitionWarningTimeout,
397
- throwOnRequestTimeout,
398
- httpAgentProvider: async () => {
399
- const { Agent, request } = await import("node:http");
400
- hRequest = request;
401
- hAgent = Agent;
402
- if (httpAgent instanceof hAgent || typeof httpAgent?.destroy === "function") {
403
- this.externalAgent = true;
404
- return httpAgent;
405
- }
406
- return new hAgent({ keepAlive, maxSockets, ...httpAgent });
407
- },
408
- httpsAgent: (() => {
409
- if (httpsAgent instanceof node_https.Agent || typeof httpsAgent?.destroy === "function") {
410
- this.externalAgent = true;
411
- return httpsAgent;
412
- }
413
- return new node_https.Agent({ keepAlive, maxSockets, ...httpsAgent });
414
- })(),
415
- logger
416
- };
417
- }
418
- }
419
- var ids = new Uint16Array(1);
420
-
421
- class ClientHttp2SessionRef {
422
- id = ids[0]++;
423
- total = 0;
424
- max = 0;
425
- session;
426
- refs = 0;
427
- constructor(session) {
428
- session.unref();
429
- this.session = session;
430
- }
431
- retain() {
432
- if (this.session.destroyed) {
433
- throw new Error("@smithy/node-http-handler - cannot acquire reference to destroyed session.");
434
- }
435
- this.refs += 1;
436
- this.total += 1;
437
- this.max = Math.max(this.refs, this.max);
438
- this.session.ref();
439
- }
440
- free() {
441
- if (this.session.destroyed) {
442
- return;
443
- }
444
- this.refs -= 1;
445
- if (this.refs === 0) {
446
- this.session.unref();
447
- }
448
- if (this.refs < 0) {
449
- throw new Error("@smithy/node-http-handler - ClientHttp2Session refcount at zero, cannot decrement.");
450
- }
451
- }
452
- deref() {
453
- return this.session;
454
- }
455
- close() {
456
- if (!this.session.closed) {
457
- this.session.close();
458
- }
459
- }
460
- destroy() {
461
- this.refs = 0;
462
- if (!this.session.destroyed) {
463
- this.session.destroy();
464
- }
465
- }
466
- useCount() {
467
- return this.refs;
468
- }
469
- }
470
-
471
- class NodeHttp2ConnectionPool {
472
- sessions = [];
473
- maxConcurrency = 0;
474
- constructor(sessions) {
475
- this.sessions = (sessions ?? []).map((session) => new ClientHttp2SessionRef(session));
476
- }
477
- poll() {
478
- let cleanup = false;
479
- for (const session of this.sessions) {
480
- if (session.deref().destroyed) {
481
- cleanup = true;
482
- continue;
483
- }
484
- if (!this.maxConcurrency || session.useCount() < this.maxConcurrency) {
485
- return session;
486
- }
487
- }
488
- if (cleanup) {
489
- for (const session of this.sessions) {
490
- if (session.deref().destroyed) {
491
- this.remove(session);
492
- }
493
- }
494
- }
495
- }
496
- offerLast(ref) {
497
- this.sessions.push(ref);
498
- }
499
- remove(ref) {
500
- const ix = this.sessions.indexOf(ref);
501
- if (ix > -1) {
502
- this.sessions.splice(ix, 1);
503
- }
504
- }
505
- [Symbol.iterator]() {
506
- return this.sessions[Symbol.iterator]();
507
- }
508
- setMaxConcurrency(maxConcurrency) {
509
- this.maxConcurrency = maxConcurrency;
510
- }
511
- destroy(ref) {
512
- this.remove(ref);
513
- ref.destroy();
514
- }
515
- }
516
-
517
- class NodeHttp2ConnectionManager {
518
- config;
519
- connectOptions;
520
- connectionPools = new Map;
521
- constructor(config) {
522
- this.config = config;
523
- if (this.config.maxConcurrency && this.config.maxConcurrency <= 0) {
524
- throw new RangeError("maxConcurrency must be greater than zero.");
525
- }
526
- }
527
- lease(requestContext, connectionConfiguration) {
528
- const url = this.getUrlString(requestContext);
529
- const pool = this.getPool(url);
530
- if (!this.config.disableConcurrency && !connectionConfiguration.isEventStream) {
531
- const available = pool.poll();
532
- if (available) {
533
- available.retain();
534
- return available;
535
- }
536
- }
537
- const ref = new ClientHttp2SessionRef(this.connect(url));
538
- const session = ref.deref();
539
- if (this.config.maxConcurrency) {
540
- session.settings({ maxConcurrentStreams: this.config.maxConcurrency }, (err) => {
541
- if (err) {
542
- throw new Error("Fail to set maxConcurrentStreams to " + this.config.maxConcurrency + "when creating new session for " + requestContext.destination.toString());
543
- }
544
- });
545
- }
546
- const graceful = () => {
547
- this.removeFromPoolAndClose(url, ref);
548
- };
549
- const ensureDestroyed = () => {
550
- this.removeFromPoolAndCheckedDestroy(url, ref);
551
- };
552
- session.on("goaway", graceful);
553
- session.on("error", ensureDestroyed);
554
- session.on("frameError", ensureDestroyed);
555
- session.on("close", ensureDestroyed);
556
- if (connectionConfiguration.requestTimeout) {
557
- session.setTimeout(connectionConfiguration.requestTimeout, ensureDestroyed);
558
- }
559
- pool.offerLast(ref);
560
- ref.retain();
561
- return ref;
562
- }
563
- release(_requestContext, ref) {
564
- ref.free();
565
- }
566
- createIsolatedSession(requestContext, connectionConfiguration) {
567
- const url = this.getUrlString(requestContext);
568
- const ref = new ClientHttp2SessionRef(this.connect(url));
569
- const session = ref.deref();
570
- session.settings({ maxConcurrentStreams: 1 });
571
- const ensureDestroyed = () => {
572
- ref.destroy();
573
- };
574
- session.on("error", ensureDestroyed);
575
- session.on("frameError", ensureDestroyed);
576
- session.on("close", ensureDestroyed);
577
- if (connectionConfiguration.requestTimeout) {
578
- session.setTimeout(connectionConfiguration.requestTimeout, ensureDestroyed);
579
- }
580
- ref.retain();
581
- return ref;
582
- }
583
- destroy() {
584
- for (const [url, connectionPool] of this.connectionPools) {
585
- for (const session of [...connectionPool]) {
586
- session.destroy();
587
- }
588
- this.connectionPools.delete(url);
589
- }
590
- }
591
- setMaxConcurrentStreams(maxConcurrentStreams) {
592
- if (maxConcurrentStreams && maxConcurrentStreams <= 0) {
593
- throw new RangeError("maxConcurrentStreams must be greater than zero.");
594
- }
595
- this.config.maxConcurrency = maxConcurrentStreams;
596
- for (const pool of this.connectionPools.values()) {
597
- pool.setMaxConcurrency(maxConcurrentStreams);
598
- }
599
- }
600
- setDisableConcurrentStreams(disableConcurrentStreams) {
601
- this.config.disableConcurrency = disableConcurrentStreams;
602
- }
603
- setNodeHttp2ConnectOptions(nodeHttp2ConnectOptions) {
604
- this.connectOptions = nodeHttp2ConnectOptions;
605
- }
606
- debug() {
607
- const pools = {};
608
- for (const [url, pool] of this.connectionPools) {
609
- const sessions = [];
610
- for (const ref of pool) {
611
- sessions.push({
612
- id: ref.id,
613
- active: ref.useCount(),
614
- maxConcurrent: ref.max,
615
- totalRequests: ref.total
616
- });
617
- }
618
- pools[url] = { sessions };
619
- }
620
- return pools;
621
- }
622
- removeFromPoolAndClose(authority, ref) {
623
- this.connectionPools.get(authority)?.remove(ref);
624
- ref.close();
625
- }
626
- removeFromPoolAndCheckedDestroy(authority, ref) {
627
- this.connectionPools.get(authority)?.remove(ref);
628
- ref.destroy();
629
- }
630
- getPool(url) {
631
- if (!this.connectionPools.has(url)) {
632
- const pool = new NodeHttp2ConnectionPool;
633
- if (this.config.maxConcurrency) {
634
- pool.setMaxConcurrency(this.config.maxConcurrency);
635
- }
636
- this.connectionPools.set(url, pool);
637
- }
638
- return this.connectionPools.get(url);
639
- }
640
- getUrlString(request) {
641
- return request.destination.toString();
642
- }
643
- connect(url) {
644
- return this.connectOptions === undefined ? http2.connect(url) : http2.connect(url, this.connectOptions);
645
- }
646
- }
647
-
648
- class NodeHttp2Handler {
649
- config;
650
- configProvider;
651
- metadata = { handlerProtocol: "h2" };
652
- connectionManager = new NodeHttp2ConnectionManager({});
653
- static create(instanceOrOptions) {
654
- if (typeof instanceOrOptions?.handle === "function") {
655
- return instanceOrOptions;
656
- }
657
- return new NodeHttp2Handler(instanceOrOptions);
658
- }
659
- constructor(options) {
660
- this.configProvider = new Promise((resolve, reject) => {
661
- if (typeof options === "function") {
662
- options().then((opts) => {
663
- resolve(opts || {});
664
- }).catch(reject);
665
- } else {
666
- resolve(options || {});
667
- }
668
- });
669
- }
670
- destroy() {
671
- this.connectionManager.destroy();
672
- }
673
- async handle(request, { abortSignal, requestTimeout, isEventStream } = {}) {
674
- if (!this.config) {
675
- this.config = await this.configProvider;
676
- const { disableConcurrentStreams: disableConcurrentStreams2, maxConcurrentStreams, nodeHttp2ConnectOptions } = this.config;
677
- this.connectionManager.setDisableConcurrentStreams(disableConcurrentStreams2 ?? false);
678
- if (maxConcurrentStreams) {
679
- this.connectionManager.setMaxConcurrentStreams(maxConcurrentStreams);
680
- }
681
- if (nodeHttp2ConnectOptions) {
682
- this.connectionManager.setNodeHttp2ConnectOptions(nodeHttp2ConnectOptions);
683
- }
684
- }
685
- const { requestTimeout: configRequestTimeout, disableConcurrentStreams } = this.config;
686
- const useIsolatedSession = disableConcurrentStreams || isEventStream;
687
- const effectiveRequestTimeout = requestTimeout ?? configRequestTimeout;
688
- return new Promise((_resolve, _reject) => {
689
- let fulfilled = false;
690
- let writeRequestBodyPromise = undefined;
691
- const resolve = async (arg) => {
692
- await writeRequestBodyPromise;
693
- _resolve(arg);
694
- };
695
- const reject = async (arg) => {
696
- await writeRequestBodyPromise;
697
- _reject(arg);
698
- };
699
- if (abortSignal?.aborted) {
700
- fulfilled = true;
701
- const abortError = buildAbortError(abortSignal);
702
- reject(abortError);
703
- return;
704
- }
705
- const { hostname, method, port, protocol, query } = request;
706
- let auth = "";
707
- if (request.username != null || request.password != null) {
708
- const username = request.username ?? "";
709
- const password = request.password ?? "";
710
- auth = `${username}:${password}@`;
711
- }
712
- const authority = `${protocol}//${auth}${hostname}${port ? `:${port}` : ""}`;
713
- const requestContext = { destination: new URL(authority) };
714
- const connectConfig = {
715
- requestTimeout: this.config?.sessionTimeout,
716
- isEventStream
717
- };
718
- const ref = useIsolatedSession ? this.connectionManager.createIsolatedSession(requestContext, connectConfig) : this.connectionManager.lease(requestContext, connectConfig);
719
- const session = ref.deref();
720
- const rejectWithDestroy = (err) => {
721
- if (useIsolatedSession) {
722
- ref.destroy();
723
- }
724
- fulfilled = true;
725
- reject(err);
726
- };
727
- const queryString = query ? protocols.buildQueryString(query) : "";
728
- let path = request.path;
729
- if (queryString) {
730
- path += `?${queryString}`;
731
- }
732
- if (request.fragment) {
733
- path += `#${request.fragment}`;
734
- }
735
- const clientHttp2Stream = session.request({
736
- ...request.headers,
737
- [http2.constants.HTTP2_HEADER_PATH]: path,
738
- [http2.constants.HTTP2_HEADER_METHOD]: method
739
- });
740
- if (effectiveRequestTimeout) {
741
- clientHttp2Stream.setTimeout(effectiveRequestTimeout, () => {
742
- clientHttp2Stream.close();
743
- const timeoutError = new Error(`Stream timed out because of no activity for ${effectiveRequestTimeout} ms`);
744
- timeoutError.name = "TimeoutError";
745
- rejectWithDestroy(timeoutError);
746
- });
747
- }
748
- if (abortSignal) {
749
- const onAbort = () => {
750
- clientHttp2Stream.close();
751
- const abortError = buildAbortError(abortSignal);
752
- rejectWithDestroy(abortError);
753
- };
754
- if (typeof abortSignal.addEventListener === "function") {
755
- const signal = abortSignal;
756
- signal.addEventListener("abort", onAbort, { once: true });
757
- clientHttp2Stream.once("close", () => signal.removeEventListener("abort", onAbort));
758
- } else {
759
- abortSignal.onabort = onAbort;
760
- }
761
- }
762
- clientHttp2Stream.on("frameError", (type, code, id) => {
763
- rejectWithDestroy(new Error(`Frame type id ${type} in stream id ${id} has failed with code ${code}.`));
764
- });
765
- clientHttp2Stream.on("error", rejectWithDestroy);
766
- clientHttp2Stream.on("aborted", () => {
767
- rejectWithDestroy(new Error(`HTTP/2 stream is abnormally aborted in mid-communication with result code ${clientHttp2Stream.rstCode}.`));
768
- });
769
- clientHttp2Stream.on("response", (headers) => {
770
- const httpResponse = new protocols.HttpResponse({
771
- statusCode: headers[":status"] ?? -1,
772
- headers: getTransformedHeaders(headers),
773
- body: clientHttp2Stream
774
- });
775
- fulfilled = true;
776
- resolve({ response: httpResponse });
777
- if (useIsolatedSession) {
778
- session.close();
779
- }
780
- });
781
- clientHttp2Stream.on("close", () => {
782
- if (useIsolatedSession) {
783
- ref.destroy();
784
- } else {
785
- this.connectionManager.release(requestContext, ref);
786
- }
787
- if (!fulfilled) {
788
- rejectWithDestroy(new Error("Unexpected error: http2 request did not get a response"));
789
- }
790
- });
791
- writeRequestBodyPromise = writeRequestBody(clientHttp2Stream, request, effectiveRequestTimeout);
792
- });
793
- }
794
- updateHttpClientConfig(key, value) {
795
- this.config = undefined;
796
- this.configProvider = this.configProvider.then((config) => {
797
- return {
798
- ...config,
799
- [key]: value
800
- };
801
- });
802
- }
803
- httpHandlerConfigs() {
804
- return this.config ?? {};
805
- }
806
- }
807
-
808
- class Collector extends node_stream.Writable {
809
- bufferedBytes = [];
810
- _write(chunk, encoding, callback) {
811
- this.bufferedBytes.push(chunk);
812
- callback();
813
- }
814
- }
815
- var streamCollector = (stream) => {
816
- if (isReadableStreamInstance(stream)) {
817
- return collectReadableStream(stream);
818
- }
819
- return new Promise((resolve, reject) => {
820
- const collector = new Collector;
821
- stream.pipe(collector);
822
- stream.on("error", (err) => {
823
- collector.end();
824
- reject(err);
825
- });
826
- collector.on("error", reject);
827
- collector.on("finish", function() {
828
- const bytes = new Uint8Array(Buffer.concat(this.bufferedBytes));
829
- resolve(bytes);
830
- });
831
- });
832
- };
833
- var isReadableStreamInstance = (stream) => typeof ReadableStream === "function" && stream instanceof ReadableStream;
834
- async function collectReadableStream(stream) {
835
- const chunks = [];
836
- const reader = stream.getReader();
837
- let isDone = false;
838
- let length = 0;
839
- while (!isDone) {
840
- const { done, value } = await reader.read();
841
- if (value) {
842
- chunks.push(value);
843
- length += value.length;
844
- }
845
- isDone = done;
846
- }
847
- const collected = new Uint8Array(length);
848
- let offset = 0;
849
- for (const chunk of chunks) {
850
- collected.set(chunk, offset);
851
- offset += chunk.length;
852
- }
853
- return collected;
854
- }
855
- exports.DEFAULT_REQUEST_TIMEOUT = DEFAULT_REQUEST_TIMEOUT;
856
- exports.NodeHttp2Handler = NodeHttp2Handler;
857
- exports.NodeHttpHandler = NodeHttpHandler;
858
- exports.streamCollector = streamCollector;
859
- });
860
-
861
- export { require_dist_cjs };