@seedance3/cli 0.0.0-stage → 0.1.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/dist/config.js ADDED
@@ -0,0 +1,38 @@
1
+ import { createHash } from "node:crypto";
2
+ import { homedir } from "node:os";
3
+ import path from "node:path";
4
+ import { CliError } from "./errors.js";
5
+ /** Kept in step with package.json by test/version.test.ts. */
6
+ export const CLI_VERSION = "0.1.1";
7
+ export const CLI_NAME = "Seedance3 CLI";
8
+ export const PACKAGE_NAME = "@seedance3/cli";
9
+ // The bare domain answers with a redirect, which would drop the bearer
10
+ // token, so the default is the www origin.
11
+ const DEFAULT_SITE_URL = "https://www.seedances3.com";
12
+ /**
13
+ * The website the CLI talks to. SEEDANCE3_BASE_URL points it at another
14
+ * deployment (a preview); only https, or http on localhost, is accepted.
15
+ */
16
+ export function resolveSiteOrigin(env = process.env) {
17
+ const raw = env.SEEDANCE3_BASE_URL?.trim() || DEFAULT_SITE_URL;
18
+ let url;
19
+ try {
20
+ url = new URL(raw);
21
+ }
22
+ catch {
23
+ throw new CliError("invalid_config", `SEEDANCE3_BASE_URL is not a valid URL: ${raw}`);
24
+ }
25
+ const local = url.hostname === "localhost" || url.hostname === "127.0.0.1";
26
+ if (url.protocol !== "https:" && !(local && url.protocol === "http:")) {
27
+ throw new CliError("invalid_config", "SEEDANCE3_BASE_URL must use https (http is allowed only for localhost).");
28
+ }
29
+ return url.origin;
30
+ }
31
+ /** Where credentials and caches live: ~/.seedance3, or SEEDANCE3_CONFIG_DIR. */
32
+ export function resolveConfigDir(env = process.env) {
33
+ return env.SEEDANCE3_CONFIG_DIR?.trim() || path.join(homedir(), ".seedance3");
34
+ }
35
+ /** A short, filesystem-safe key per site, so previews keep their own login. */
36
+ export function siteKey(origin) {
37
+ return createHash("sha256").update(origin).digest("hex").slice(0, 16);
38
+ }
@@ -0,0 +1,35 @@
1
+ import { CLI_NAME, CLI_VERSION } from "./config.js";
2
+ /**
3
+ * Shows this sign-in as "Seedance3 CLI" on the website's API page. The
4
+ * website names an app's connection after the client name of its MCP
5
+ * `initialize` message, so the CLI sends one. Best effort: a failure only
6
+ * leaves the default name.
7
+ */
8
+ export async function nameConnection(params) {
9
+ try {
10
+ const token = await params.tokens.accessToken();
11
+ await (params.fetchImpl ?? fetch)(new URL("/api/mcp", params.origin), {
12
+ method: "POST",
13
+ headers: {
14
+ authorization: `Bearer ${token}`,
15
+ "content-type": "application/json",
16
+ accept: "application/json, text/event-stream",
17
+ },
18
+ body: JSON.stringify({
19
+ jsonrpc: "2.0",
20
+ id: 1,
21
+ method: "initialize",
22
+ params: {
23
+ protocolVersion: "2025-06-18",
24
+ capabilities: {},
25
+ clientInfo: { name: CLI_NAME, version: CLI_VERSION },
26
+ },
27
+ }),
28
+ redirect: "error",
29
+ signal: AbortSignal.timeout(15_000),
30
+ });
31
+ }
32
+ catch {
33
+ // Naming is cosmetic.
34
+ }
35
+ }
@@ -0,0 +1,125 @@
1
+ import { spawn } from "node:child_process";
2
+ import { CliError } from "./errors.js";
3
+ function isCredentials(value) {
4
+ return (!!value &&
5
+ typeof value === "object" &&
6
+ typeof value.accessToken === "string");
7
+ }
8
+ export class FileVault {
9
+ files;
10
+ key;
11
+ kind = "file";
12
+ constructor(files, key) {
13
+ this.files = files;
14
+ this.key = key;
15
+ }
16
+ get name() {
17
+ return `credentials-${this.key}.json`;
18
+ }
19
+ async read() {
20
+ const value = await this.files.readJson(this.name);
21
+ return isCredentials(value) ? value : null;
22
+ }
23
+ async write(credentials) {
24
+ await this.files.writeJson(this.name, credentials);
25
+ }
26
+ async remove() {
27
+ await this.files.remove(this.name);
28
+ }
29
+ }
30
+ const KEYCHAIN_SERVICE = "seedance3-cli";
31
+ const SECURITY = "/usr/bin/security";
32
+ // `security` exits with 44 when the item does not exist.
33
+ const KEYCHAIN_NOT_FOUND = 44;
34
+ const runCommand = (file, args, input) => new Promise((resolve, reject) => {
35
+ const child = spawn(file, args, { stdio: ["pipe", "pipe", "ignore"] });
36
+ const chunks = [];
37
+ child.stdout.on("data", (chunk) => chunks.push(chunk));
38
+ child.once("error", reject);
39
+ child.once("close", (code) => resolve({ code, stdout: Buffer.concat(chunks).toString("utf8").trim() }));
40
+ child.stdin.on("error", () => undefined);
41
+ child.stdin.end(input ?? "");
42
+ });
43
+ function keychainUnavailable() {
44
+ return new CliError("keychain_unavailable", "The macOS keychain is locked or unavailable.", "Unlock it, or sign in with `seedance3 auth login --credential-store file`.");
45
+ }
46
+ /**
47
+ * macOS keychain item per site. The secret is written through `security -i`
48
+ * on stdin so it never appears in the process list.
49
+ */
50
+ export class KeychainVault {
51
+ key;
52
+ run;
53
+ kind = "keychain";
54
+ constructor(key, run = runCommand) {
55
+ this.key = key;
56
+ this.run = run;
57
+ }
58
+ async read() {
59
+ const result = await this.run(SECURITY, [
60
+ "find-generic-password",
61
+ "-s",
62
+ KEYCHAIN_SERVICE,
63
+ "-a",
64
+ this.key,
65
+ "-w",
66
+ ]);
67
+ if (result.code === KEYCHAIN_NOT_FOUND)
68
+ return null;
69
+ if (result.code !== 0)
70
+ throw keychainUnavailable();
71
+ try {
72
+ const value = JSON.parse(Buffer.from(result.stdout, "base64url").toString("utf8"));
73
+ return isCredentials(value) ? value : null;
74
+ }
75
+ catch {
76
+ return null;
77
+ }
78
+ }
79
+ async write(credentials) {
80
+ // base64url keeps the value free of spaces and quotes for `security -i`.
81
+ const data = Buffer.from(JSON.stringify(credentials)).toString("base64url");
82
+ const result = await this.run(SECURITY, ["-i"], `add-generic-password -U -s ${KEYCHAIN_SERVICE} -a ${this.key} -w ${data}\n`);
83
+ if (result.code !== 0)
84
+ throw keychainUnavailable();
85
+ }
86
+ async remove() {
87
+ const result = await this.run(SECURITY, [
88
+ "delete-generic-password",
89
+ "-s",
90
+ KEYCHAIN_SERVICE,
91
+ "-a",
92
+ this.key,
93
+ ]);
94
+ if (result.code !== 0 && result.code !== KEYCHAIN_NOT_FOUND) {
95
+ throw keychainUnavailable();
96
+ }
97
+ }
98
+ }
99
+ const STORE_CHOICE_FILE = "credential-store.json";
100
+ /**
101
+ * The vault for this site. The choice made at `auth login` is remembered;
102
+ * without one, macOS uses the keychain and Linux a private file.
103
+ */
104
+ export async function selectVault(params) {
105
+ const platform = params.platform ?? process.platform;
106
+ let kind = params.choice;
107
+ if (kind) {
108
+ await params.files.writeJson(STORE_CHOICE_FILE, { store: kind });
109
+ }
110
+ else {
111
+ const saved = await params.files.readJson(STORE_CHOICE_FILE);
112
+ kind =
113
+ saved?.store === "file" || saved?.store === "keychain"
114
+ ? saved.store
115
+ : platform === "darwin"
116
+ ? "keychain"
117
+ : "file";
118
+ }
119
+ if (kind === "keychain" && platform !== "darwin") {
120
+ throw new CliError("keychain_unavailable", "The keychain store is only available on macOS.", "Use `seedance3 auth login --credential-store file`.");
121
+ }
122
+ return kind === "keychain"
123
+ ? new KeychainVault(params.key)
124
+ : new FileVault(params.files, params.key);
125
+ }
package/dist/errors.js ADDED
@@ -0,0 +1,57 @@
1
+ /**
2
+ * An error the CLI reports to the user. `code` is stable and machine
3
+ * readable (agents branch on it); `message` says what went wrong and `hint`
4
+ * what to do next.
5
+ */
6
+ export class CliError extends Error {
7
+ code;
8
+ hint;
9
+ details;
10
+ constructor(code, message, hint, details) {
11
+ super(message);
12
+ this.code = code;
13
+ this.hint = hint;
14
+ this.details = details;
15
+ this.name = "CliError";
16
+ }
17
+ }
18
+ export const SIGN_IN_HINT = "Run `seedance3 auth login` to sign in.";
19
+ /**
20
+ * The TypeErrors Node's fetch rejects with when the connection fails:
21
+ * "fetch failed" before any response (DNS lookup, connection, TLS or a
22
+ * reset), "terminated" when it drops while the body is being read.
23
+ */
24
+ export function isConnectionFailure(error) {
25
+ return (error instanceof TypeError &&
26
+ (error.message === "fetch failed" || error.message === "terminated"));
27
+ }
28
+ /**
29
+ * A connection failure as a network_error. The default hint suits commands
30
+ * that are safe to run again; a command that spends credits passes its own.
31
+ */
32
+ export function networkError(error, hint = "Check the internet connection or proxy, then run the command again.") {
33
+ // Node names the cause (ENOTFOUND, UND_ERR_SOCKET…) only here.
34
+ const cause = error.cause?.code;
35
+ return new CliError("network_error", `The network connection failed${typeof cause === "string" ? ` (${cause})` : ""}.`, hint);
36
+ }
37
+ /** The error with this hint if it is a connection failure, else unchanged. */
38
+ export function withNetworkHint(error, hint) {
39
+ return isConnectionFailure(error) ? networkError(error, hint) : error;
40
+ }
41
+ /** The JSON a failed command prints on stderr. */
42
+ export function errorPayload(error) {
43
+ if (isConnectionFailure(error))
44
+ return errorPayload(networkError(error));
45
+ if (error instanceof CliError) {
46
+ return {
47
+ error: {
48
+ code: error.code,
49
+ message: error.message,
50
+ ...(error.hint ? { hint: error.hint } : {}),
51
+ ...(error.details !== undefined ? { details: error.details } : {}),
52
+ },
53
+ };
54
+ }
55
+ const message = error instanceof Error ? error.message : String(error);
56
+ return { error: { code: "internal_error", message } };
57
+ }
package/dist/files.js ADDED
@@ -0,0 +1,89 @@
1
+ import { randomBytes } from "node:crypto";
2
+ import { chmod, mkdir, open, readFile, rename, rm, stat, } from "node:fs/promises";
3
+ import path from "node:path";
4
+ const LOCK_WAIT_MS = 15_000;
5
+ const LOCK_STALE_MS = 60_000;
6
+ const LOCK_POLL_MS = 100;
7
+ /**
8
+ * Private JSON files in the config directory. The directory is 0700 and
9
+ * every file 0600; writes go through a temporary file and a rename, so a
10
+ * crash never leaves half a credential behind.
11
+ */
12
+ export class ConfigFiles {
13
+ dir;
14
+ constructor(dir) {
15
+ this.dir = dir;
16
+ }
17
+ file(name) {
18
+ if (!/^[\w.-]+$/.test(name))
19
+ throw new Error(`Invalid config name: ${name}`);
20
+ return path.join(this.dir, name);
21
+ }
22
+ async ensureDir() {
23
+ await mkdir(this.dir, { recursive: true, mode: 0o700 });
24
+ await chmod(this.dir, 0o700);
25
+ }
26
+ async readJson(name) {
27
+ try {
28
+ return JSON.parse(await readFile(this.file(name), "utf8"));
29
+ }
30
+ catch (error) {
31
+ if (error.code === "ENOENT")
32
+ return null;
33
+ throw error;
34
+ }
35
+ }
36
+ async writeJson(name, value) {
37
+ await this.ensureDir();
38
+ const target = this.file(name);
39
+ const temp = `${target}.${process.pid}.${randomBytes(4).toString("hex")}.tmp`;
40
+ const handle = await open(temp, "wx", 0o600);
41
+ try {
42
+ await handle.writeFile(`${JSON.stringify(value, null, 2)}\n`);
43
+ }
44
+ finally {
45
+ await handle.close();
46
+ }
47
+ await rename(temp, target);
48
+ }
49
+ async remove(name) {
50
+ await rm(this.file(name), { force: true });
51
+ }
52
+ /**
53
+ * Runs `action` while holding an exclusive lock file, so two CLI processes
54
+ * (an agent often runs several) never refresh the same token at once.
55
+ */
56
+ async withLock(name, action) {
57
+ await this.ensureDir();
58
+ const lock = this.file(`${name}.lock`);
59
+ const deadline = Date.now() + LOCK_WAIT_MS;
60
+ for (;;) {
61
+ try {
62
+ const handle = await open(lock, "wx", 0o600);
63
+ await handle.close();
64
+ break;
65
+ }
66
+ catch (error) {
67
+ if (error.code !== "EEXIST")
68
+ throw error;
69
+ const age = await stat(lock)
70
+ .then((info) => Date.now() - info.mtimeMs)
71
+ .catch(() => 0);
72
+ if (age > LOCK_STALE_MS) {
73
+ await rm(lock, { force: true });
74
+ continue;
75
+ }
76
+ if (Date.now() > deadline) {
77
+ throw new Error(`Timed out waiting for ${lock}`);
78
+ }
79
+ await new Promise((resolve) => setTimeout(resolve, LOCK_POLL_MS));
80
+ }
81
+ }
82
+ try {
83
+ return await action();
84
+ }
85
+ finally {
86
+ await rm(lock, { force: true });
87
+ }
88
+ }
89
+ }
package/dist/media.js ADDED
@@ -0,0 +1,223 @@
1
+ import { open, stat } from "node:fs/promises";
2
+ import path from "node:path";
3
+ import { CliError } from "./errors.js";
4
+ // Extensions both the upload route and the generation API accept, with the
5
+ // content type the upload route expects for each.
6
+ const MEDIA_TYPES = {
7
+ ".jpg": { kind: "image", mimeType: "image/jpeg" },
8
+ ".jpeg": { kind: "image", mimeType: "image/jpeg" },
9
+ ".png": { kind: "image", mimeType: "image/png" },
10
+ ".webp": { kind: "image", mimeType: "image/webp" },
11
+ ".bmp": { kind: "image", mimeType: "image/bmp" },
12
+ ".tiff": { kind: "image", mimeType: "image/tiff" },
13
+ ".mp4": { kind: "video", mimeType: "video/mp4" },
14
+ ".mov": { kind: "video", mimeType: "video/quicktime" },
15
+ ".avi": { kind: "video", mimeType: "video/x-msvideo" },
16
+ ".webm": { kind: "video", mimeType: "video/webm" },
17
+ ".mkv": { kind: "video", mimeType: "video/x-matroska" },
18
+ ".mp3": { kind: "audio", mimeType: "audio/mpeg" },
19
+ ".wav": { kind: "audio", mimeType: "audio/wav" },
20
+ ".aac": { kind: "audio", mimeType: "audio/aac" },
21
+ ".ogg": { kind: "audio", mimeType: "audio/ogg" },
22
+ ".flac": { kind: "audio", mimeType: "audio/flac" },
23
+ ".m4a": { kind: "audio", mimeType: "audio/mp4" },
24
+ };
25
+ export const SUPPORTED_EXTENSIONS = Object.keys(MEDIA_TYPES);
26
+ const HEADER_BYTES = 512 * 1024;
27
+ async function readAt(handle, position, length) {
28
+ const buffer = Buffer.alloc(length);
29
+ const { bytesRead } = await handle.read(buffer, 0, length, position);
30
+ return buffer.subarray(0, bytesRead);
31
+ }
32
+ export function pngDimensions(header) {
33
+ if (header.length < 24 || header.readUInt32BE(0) !== 0x89504e47)
34
+ return null;
35
+ return { width: header.readUInt32BE(16), height: header.readUInt32BE(20) };
36
+ }
37
+ export function jpegDimensions(header) {
38
+ if (header.length < 4 || header[0] !== 0xff || header[1] !== 0xd8) {
39
+ return null;
40
+ }
41
+ let offset = 2;
42
+ while (offset + 9 < header.length) {
43
+ if (header[offset] !== 0xff) {
44
+ offset += 1;
45
+ continue;
46
+ }
47
+ const marker = header[offset + 1];
48
+ // Start-of-frame markers carry the size; DHT, JPG and DAC do not.
49
+ if (marker >= 0xc0 &&
50
+ marker <= 0xcf &&
51
+ marker !== 0xc4 &&
52
+ marker !== 0xc8 &&
53
+ marker !== 0xcc) {
54
+ return {
55
+ height: header.readUInt16BE(offset + 5),
56
+ width: header.readUInt16BE(offset + 7),
57
+ };
58
+ }
59
+ offset += 2 + header.readUInt16BE(offset + 2);
60
+ }
61
+ return null;
62
+ }
63
+ export function webpDimensions(header) {
64
+ if (header.length < 30 ||
65
+ header.toString("ascii", 0, 4) !== "RIFF" ||
66
+ header.toString("ascii", 8, 12) !== "WEBP") {
67
+ return null;
68
+ }
69
+ const chunk = header.toString("ascii", 12, 16);
70
+ if (chunk === "VP8X") {
71
+ return {
72
+ width: 1 + header.readUIntLE(24, 3),
73
+ height: 1 + header.readUIntLE(27, 3),
74
+ };
75
+ }
76
+ if (chunk === "VP8L") {
77
+ const bits = header.readUInt32LE(21);
78
+ return { width: 1 + (bits & 0x3fff), height: 1 + ((bits >> 14) & 0x3fff) };
79
+ }
80
+ if (chunk === "VP8 ") {
81
+ return {
82
+ width: header.readUInt16LE(26) & 0x3fff,
83
+ height: header.readUInt16LE(28) & 0x3fff,
84
+ };
85
+ }
86
+ return null;
87
+ }
88
+ async function readBoxes(handle, start, end) {
89
+ const boxes = [];
90
+ let offset = start;
91
+ while (offset + 8 <= end && boxes.length < 1024) {
92
+ const head = await readAt(handle, offset, 16);
93
+ if (head.length < 8)
94
+ break;
95
+ let size = head.readUInt32BE(0);
96
+ let header = 8;
97
+ if (size === 1 && head.length >= 16) {
98
+ size = Number(head.readBigUInt64BE(8));
99
+ header = 16;
100
+ }
101
+ else if (size === 0) {
102
+ size = end - offset;
103
+ }
104
+ if (size < header)
105
+ break;
106
+ boxes.push({
107
+ type: head.toString("ascii", 4, 8),
108
+ start: offset,
109
+ size,
110
+ header,
111
+ });
112
+ offset += size;
113
+ }
114
+ return boxes;
115
+ }
116
+ /**
117
+ * Duration and picture size of an MP4/MOV/M4A file from its `moov` box,
118
+ * wherever in the file it sits. Only box headers and two small boxes are read.
119
+ */
120
+ export async function isoMediaInfo(handle, fileSize) {
121
+ const moov = (await readBoxes(handle, 0, fileSize)).find((box) => box.type === "moov");
122
+ if (!moov)
123
+ return {};
124
+ const children = await readBoxes(handle, moov.start + moov.header, moov.start + moov.size);
125
+ const result = {};
126
+ const mvhd = children.find((box) => box.type === "mvhd");
127
+ if (mvhd) {
128
+ const body = await readAt(handle, mvhd.start + mvhd.header, 32);
129
+ const version = body[0];
130
+ const timescale = version === 1 ? body.readUInt32BE(20) : body.readUInt32BE(12);
131
+ const duration = version === 1 ? Number(body.readBigUInt64BE(24)) : body.readUInt32BE(16);
132
+ if (timescale > 0)
133
+ result.durationSeconds = duration / timescale;
134
+ }
135
+ for (const trak of children.filter((box) => box.type === "trak")) {
136
+ const tkhd = (await readBoxes(handle, trak.start + trak.header, trak.start + trak.size)).find((box) => box.type === "tkhd");
137
+ if (!tkhd)
138
+ continue;
139
+ const body = await readAt(handle, tkhd.start + tkhd.header, Math.min(96, tkhd.size - tkhd.header));
140
+ // Width and height are 16.16 fixed point at the end of the box.
141
+ const sizeOffset = body[0] === 1 ? 88 : 76;
142
+ if (body.length < sizeOffset + 8)
143
+ continue;
144
+ const width = body.readUInt32BE(sizeOffset) >>> 16;
145
+ const height = body.readUInt32BE(sizeOffset + 4) >>> 16;
146
+ if (width > 0 && height > 0) {
147
+ result.width = width;
148
+ result.height = height;
149
+ break;
150
+ }
151
+ }
152
+ return result;
153
+ }
154
+ export function wavDurationSeconds(header) {
155
+ if (header.length < 12 ||
156
+ header.toString("ascii", 0, 4) !== "RIFF" ||
157
+ header.toString("ascii", 8, 12) !== "WAVE") {
158
+ return undefined;
159
+ }
160
+ let byteRate = 0;
161
+ let offset = 12;
162
+ while (offset + 8 <= header.length) {
163
+ const id = header.toString("ascii", offset, offset + 4);
164
+ const size = header.readUInt32LE(offset + 4);
165
+ if (id === "fmt " && offset + 16 <= header.length) {
166
+ byteRate = header.readUInt32LE(offset + 16);
167
+ }
168
+ else if (id === "data") {
169
+ return byteRate > 0 ? size / byteRate : undefined;
170
+ }
171
+ offset += 8 + size + (size % 2);
172
+ }
173
+ return undefined;
174
+ }
175
+ /** Type, size and (where the header tells) dimensions or duration of a file. */
176
+ export async function inspectMediaFile(filePath) {
177
+ const type = MEDIA_TYPES[path.extname(filePath).toLowerCase()];
178
+ if (!type) {
179
+ throw new CliError("unsupported_file", `${path.basename(filePath)} is not a supported file type.`, `Use one of: ${SUPPORTED_EXTENSIONS.join(", ")}.`);
180
+ }
181
+ let info;
182
+ try {
183
+ info = await stat(filePath);
184
+ }
185
+ catch {
186
+ throw new CliError("file_not_found", `File not found: ${filePath}`);
187
+ }
188
+ if (!info.isFile()) {
189
+ throw new CliError("file_not_found", `Not a file: ${filePath}`);
190
+ }
191
+ const media = {
192
+ path: filePath,
193
+ fileName: path.basename(filePath),
194
+ size: info.size,
195
+ ...type,
196
+ };
197
+ const handle = await open(filePath, "r");
198
+ try {
199
+ const ext = path.extname(filePath).toLowerCase();
200
+ if (type.kind === "image") {
201
+ const header = await readAt(handle, 0, Math.min(HEADER_BYTES, info.size));
202
+ const dimensions = pngDimensions(header) ??
203
+ jpegDimensions(header) ??
204
+ webpDimensions(header);
205
+ if (dimensions)
206
+ Object.assign(media, dimensions);
207
+ }
208
+ else if (ext === ".mp4" || ext === ".mov" || ext === ".m4a") {
209
+ Object.assign(media, await isoMediaInfo(handle, info.size));
210
+ }
211
+ else if (ext === ".wav") {
212
+ const header = await readAt(handle, 0, Math.min(64 * 1024, info.size));
213
+ media.durationSeconds = wavDurationSeconds(header);
214
+ }
215
+ }
216
+ catch {
217
+ // An unreadable header only skips the local checks; the server checks too.
218
+ }
219
+ finally {
220
+ await handle.close();
221
+ }
222
+ return media;
223
+ }
@@ -0,0 +1,21 @@
1
+ import { isConnectionFailure } from "./errors.js";
2
+ const RETRY_DELAYS_MS = [1_000, 3_000];
3
+ export const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
4
+ /**
5
+ * Sends a request that is safe to repeat, retrying it when the connection
6
+ * fails. Some networks drop the odd connection to the website or the CDN,
7
+ * and a second attempt usually gets through.
8
+ */
9
+ export async function retryConnectionFailures(send, wait) {
10
+ for (let attempt = 0;; attempt++) {
11
+ try {
12
+ return await send();
13
+ }
14
+ catch (error) {
15
+ const delay = RETRY_DELAYS_MS[attempt];
16
+ if (delay === undefined || !isConnectionFailure(error))
17
+ throw error;
18
+ await wait(delay);
19
+ }
20
+ }
21
+ }