@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/LICENSE +22 -0
- package/README.md +105 -2
- package/dist/api.js +105 -0
- package/dist/checks.js +91 -0
- package/dist/cli.js +334 -0
- package/dist/config.js +38 -0
- package/dist/connection-name.js +35 -0
- package/dist/credentials.js +125 -0
- package/dist/errors.js +57 -0
- package/dist/files.js +89 -0
- package/dist/media.js +223 -0
- package/dist/network.js +21 -0
- package/dist/oauth.js +274 -0
- package/dist/requests.js +138 -0
- package/dist/schema.js +79 -0
- package/dist/service.js +237 -0
- package/dist/session.js +320 -0
- package/dist/update-check.js +49 -0
- package/dist/upload.js +203 -0
- package/package.json +34 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
Copyright (c) 2026 seedances3.com. All rights reserved.
|
|
2
|
+
|
|
3
|
+
The Seedance3 CLI (@seedance3/cli) is proprietary software. It is not
|
|
4
|
+
open source.
|
|
5
|
+
|
|
6
|
+
You may install it from the official npm package and use it, free of
|
|
7
|
+
charge, with your Seedance 3.0 AI account, including in scripts and
|
|
8
|
+
automation. Your use of the service, and what you may do with the content
|
|
9
|
+
you generate, including any commercial use, is governed by the Terms of
|
|
10
|
+
Use at https://www.seedances3.com/terms-of-use and your plan.
|
|
11
|
+
|
|
12
|
+
You may not copy, modify, merge, publish, distribute, sublicense or sell
|
|
13
|
+
the software or any part of it, or create works derived from it, except
|
|
14
|
+
as needed to install and run it as described above.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
21
|
+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
22
|
+
DEALINGS IN THE SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,106 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Seedance3 CLI
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Generate Seedance videos and AI images with your [Seedance 3.0 AI](https://www.seedances3.com) account, from the terminal or from an AI agent that runs commands (Claude Code, Codex, Cursor, OpenCode).
|
|
4
|
+
|
|
5
|
+
Generations spend the same credits as the website, at the same prices.
|
|
6
|
+
|
|
7
|
+
## Install and sign in
|
|
8
|
+
|
|
9
|
+
Requires Node.js 22 or newer on macOS or Linux (Windows: use WSL).
|
|
10
|
+
|
|
11
|
+
```sh
|
|
12
|
+
npm install -g @seedance3/cli
|
|
13
|
+
seedance3 auth login
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
`auth login` opens your browser; sign in and allow access. No API key or password is entered in the terminal. On macOS the sign-in is stored in the keychain; elsewhere in a private file under `~/.seedance3`. On a machine without a browser, run `seedance3 auth login --no-browser`, open the link it prints on any device, allow access, and paste back the address the browser ends on (that page will not load; that is expected).
|
|
17
|
+
|
|
18
|
+
## Generate
|
|
19
|
+
|
|
20
|
+
Write the request as JSON: `model` plus that model's fields (`seedance3 model <id>` lists them). URL fields accept files on your computer.
|
|
21
|
+
|
|
22
|
+
```json
|
|
23
|
+
{
|
|
24
|
+
"model": "seedance2",
|
|
25
|
+
"mode": "image-to-video",
|
|
26
|
+
"quality_tier": "fast",
|
|
27
|
+
"prompt": "The product turns slowly on a white table",
|
|
28
|
+
"duration": "5",
|
|
29
|
+
"resolution": "720p",
|
|
30
|
+
"image_url": "./product.png"
|
|
31
|
+
}
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
```sh
|
|
35
|
+
seedance3 estimate --input request.json # credit cost; nothing is charged
|
|
36
|
+
seedance3 create --input request.json --max-credits 95 --wait
|
|
37
|
+
seedance3 download TASK_ID --output product.mp4
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
A Kling 4.0 prompt can name its references: `@image_1`, `@video_1` (numbered in URL order), `@first_frame`, `@keyframe_1`, `@last_frame`, or `@` plus a subject's or voice's `name`. Any other `@` mention is rejected before charging. Files inside subjects and voices can be local too:
|
|
41
|
+
|
|
42
|
+
```json
|
|
43
|
+
{
|
|
44
|
+
"model": "kling4",
|
|
45
|
+
"type": "reference-to-video",
|
|
46
|
+
"prompt": "@Mia walks along the street in @image_1",
|
|
47
|
+
"duration": 5,
|
|
48
|
+
"resolution": "720p",
|
|
49
|
+
"image_urls": ["./street.png"],
|
|
50
|
+
"elements": [
|
|
51
|
+
{ "name": "Mia", "image_urls": ["./mia-front.png", "./mia-side.png"] }
|
|
52
|
+
]
|
|
53
|
+
}
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
To upscale an existing image or video, use the `image-upscale` or `video-upscale` model. The source can be a file on your computer:
|
|
57
|
+
|
|
58
|
+
```json
|
|
59
|
+
{
|
|
60
|
+
"model": "video-upscale",
|
|
61
|
+
"video_url": "./clip.mp4",
|
|
62
|
+
"tier": "standard",
|
|
63
|
+
"target_resolution": "1080p"
|
|
64
|
+
}
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
A video is priced per second of the source, so run `estimate` first.
|
|
68
|
+
|
|
69
|
+
- `estimate` uploads local files so the price is exact; `create` reuses those uploads.
|
|
70
|
+
- `create` prints a request ID on stderr. If a call is interrupted, rerun with `--request-id <id>`: it returns the same task and is never charged twice.
|
|
71
|
+
- With `--max-credits`, nothing is submitted if the price is higher.
|
|
72
|
+
- `download` never overwrites an existing file.
|
|
73
|
+
|
|
74
|
+
## Commands
|
|
75
|
+
|
|
76
|
+
| Command | What it does |
|
|
77
|
+
| -------------------------------------------- | ------------------------------------------------------------------- |
|
|
78
|
+
| `auth login` / `auth status` / `auth logout` | Sign in, check, sign out (disconnects this computer on the website) |
|
|
79
|
+
| `account` | Credit balance |
|
|
80
|
+
| `models` / `model <id>` | Available models / one model's request fields |
|
|
81
|
+
| `estimate --input <file>` | Price a request without charging |
|
|
82
|
+
| `create --input <file>` | Generate (spends credits) |
|
|
83
|
+
| `upload <file>...` | Upload files and print their URLs |
|
|
84
|
+
| `tasks` / `task <id>` / `wait <id>` | Follow tasks; a wait timeout does not cancel the task |
|
|
85
|
+
| `download <id>` | Save a completed task's results |
|
|
86
|
+
|
|
87
|
+
Results are JSON on stdout; progress and errors go to stderr. Errors carry a `code`, a `message` and a `hint`.
|
|
88
|
+
|
|
89
|
+
## Use from an agent
|
|
90
|
+
|
|
91
|
+
Agents that run commands on your computer (Claude Code, Codex, Cursor, OpenCode) can use the CLI directly: ask them to estimate first, then create with `--max-credits` set to the quoted price.
|
|
92
|
+
|
|
93
|
+
To connect an agent through MCP instead, add the website's MCP server (see the guide below). It can use files on your computer too.
|
|
94
|
+
|
|
95
|
+
## Environment
|
|
96
|
+
|
|
97
|
+
| Variable | Purpose |
|
|
98
|
+
| --------------------------- | ------------------------------------------------------------ |
|
|
99
|
+
| `SEEDANCE3_CONFIG_DIR` | Where sign-in and caches are stored (default `~/.seedance3`) |
|
|
100
|
+
| `SEEDANCE3_NO_UPDATE_CHECK` | Turn off the daily new-version notice |
|
|
101
|
+
|
|
102
|
+
Guide: https://www.seedances3.com/cli
|
|
103
|
+
|
|
104
|
+
## License
|
|
105
|
+
|
|
106
|
+
Proprietary, not open source. Free to install and use with your Seedance 3.0 AI account; the terms are in the LICENSE file of the package. What you may do with generated content, including commercial use, follows the [Terms of Use](https://www.seedances3.com/terms-of-use) and your plan.
|
package/dist/api.js
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { CLI_VERSION } from "./config.js";
|
|
2
|
+
import { CliError, SIGN_IN_HINT } from "./errors.js";
|
|
3
|
+
import { retryConnectionFailures, sleep } from "./network.js";
|
|
4
|
+
const REQUEST_TIMEOUT_MS = 120_000;
|
|
5
|
+
// A video quote or submit inspects reference media and can take minutes.
|
|
6
|
+
const SLOW_REQUEST_TIMEOUT_MS = 330_000;
|
|
7
|
+
/** Hints for the public API's documented error codes. */
|
|
8
|
+
function hintFor(code, origin) {
|
|
9
|
+
switch (code) {
|
|
10
|
+
case "unauthorized":
|
|
11
|
+
return SIGN_IN_HINT;
|
|
12
|
+
case "purchase_required":
|
|
13
|
+
return `This needs a purchase. Buy credits or a plan at ${origin}/pricing.`;
|
|
14
|
+
case "insufficient_credits":
|
|
15
|
+
return `Top up at ${origin}/pricing. The CLI does not buy credits.`;
|
|
16
|
+
case "credits_frozen":
|
|
17
|
+
return "The account's credits are frozen. Contact support.";
|
|
18
|
+
case "rate_limited":
|
|
19
|
+
return "Wait a minute before retrying; do not loop.";
|
|
20
|
+
case "idempotency_conflict":
|
|
21
|
+
return "This request ID is in use. Check `seedance3 tasks` before generating again.";
|
|
22
|
+
case "service_busy":
|
|
23
|
+
return "Retry in a few minutes with the same request ID.";
|
|
24
|
+
case "invalid_request":
|
|
25
|
+
return "Fix the field named in the message. `seedance3 model <id>` lists the fields.";
|
|
26
|
+
case "not_found":
|
|
27
|
+
return "Check the task ID, or list tasks with `seedance3 tasks`.";
|
|
28
|
+
default:
|
|
29
|
+
return undefined;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
function errorFromResponse(status, body, origin) {
|
|
33
|
+
// v1 answers { error: { code, message } }; the upload routes { error }.
|
|
34
|
+
const raw = body?.error;
|
|
35
|
+
if (raw && typeof raw === "object") {
|
|
36
|
+
const { code, message, ...details } = raw;
|
|
37
|
+
const errorCode = typeof code === "string" ? code : `http_${status}`;
|
|
38
|
+
return new CliError(errorCode, typeof message === "string"
|
|
39
|
+
? message
|
|
40
|
+
: `Request failed (HTTP ${status}).`, hintFor(errorCode, origin), Object.keys(details).length > 0 ? details : undefined);
|
|
41
|
+
}
|
|
42
|
+
const code = status === 401
|
|
43
|
+
? "unauthorized"
|
|
44
|
+
: status === 429
|
|
45
|
+
? "rate_limited"
|
|
46
|
+
: `http_${status}`;
|
|
47
|
+
return new CliError(code, typeof raw === "string" ? raw : `Request failed (HTTP ${status}).`, hintFor(code, origin));
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Calls the website as the signed-in user. A 401 gets one token refresh and
|
|
51
|
+
* one retry, and a GET is retried when the connection fails; anything else
|
|
52
|
+
* is reported as a CliError.
|
|
53
|
+
*/
|
|
54
|
+
export class ApiClient {
|
|
55
|
+
origin;
|
|
56
|
+
tokens;
|
|
57
|
+
fetchImpl;
|
|
58
|
+
wait;
|
|
59
|
+
constructor(origin, tokens, fetchImpl = fetch, wait = sleep) {
|
|
60
|
+
this.origin = origin;
|
|
61
|
+
this.tokens = tokens;
|
|
62
|
+
this.fetchImpl = fetchImpl;
|
|
63
|
+
this.wait = wait;
|
|
64
|
+
}
|
|
65
|
+
async request(request) {
|
|
66
|
+
let token = await this.tokens.accessToken();
|
|
67
|
+
let response = await this.send(request, token);
|
|
68
|
+
if (response.status === 401) {
|
|
69
|
+
token = await this.tokens.refresh(token);
|
|
70
|
+
response = await this.send(request, token);
|
|
71
|
+
}
|
|
72
|
+
const body = await response.json().catch(() => null);
|
|
73
|
+
if (!response.ok) {
|
|
74
|
+
throw errorFromResponse(response.status, body, this.origin);
|
|
75
|
+
}
|
|
76
|
+
return body;
|
|
77
|
+
}
|
|
78
|
+
send(request, token) {
|
|
79
|
+
// Only a GET is safe to repeat here; a submit retries with its
|
|
80
|
+
// Idempotency-Key in SeedanceService.create.
|
|
81
|
+
return request.method === "GET"
|
|
82
|
+
? retryConnectionFailures(() => this.sendOnce(request, token), this.wait)
|
|
83
|
+
: this.sendOnce(request, token);
|
|
84
|
+
}
|
|
85
|
+
sendOnce(request, token) {
|
|
86
|
+
const headers = {
|
|
87
|
+
accept: "application/json",
|
|
88
|
+
authorization: `Bearer ${token}`,
|
|
89
|
+
"user-agent": `seedance3-cli/${CLI_VERSION}`,
|
|
90
|
+
};
|
|
91
|
+
if (request.body !== undefined)
|
|
92
|
+
headers["content-type"] = "application/json";
|
|
93
|
+
if (request.idempotencyKey) {
|
|
94
|
+
headers["idempotency-key"] = request.idempotencyKey;
|
|
95
|
+
}
|
|
96
|
+
return this.fetchImpl(new URL(request.path, this.origin), {
|
|
97
|
+
method: request.method,
|
|
98
|
+
headers,
|
|
99
|
+
body: request.body === undefined ? undefined : JSON.stringify(request.body),
|
|
100
|
+
// Never follow a redirect: it would carry the bearer token elsewhere.
|
|
101
|
+
redirect: "error",
|
|
102
|
+
signal: AbortSignal.timeout(request.slow ? SLOW_REQUEST_TIMEOUT_MS : REQUEST_TIMEOUT_MS),
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
}
|
package/dist/checks.js
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { CliError } from "./errors.js";
|
|
2
|
+
const MB = 1024 * 1024;
|
|
3
|
+
// The upload route's per-file ceiling (lib/s3-upload-policy.ts).
|
|
4
|
+
const UPLOAD_MAX_BYTES = 100 * MB;
|
|
5
|
+
// Seedance 2.0 reference limits, as the website enforces them
|
|
6
|
+
// (lib/constants/seedance.ts, lib/seedance-reference-constraints.ts). The
|
|
7
|
+
// server checks again; these only spare uploading a file it would refuse.
|
|
8
|
+
const SEEDANCE2 = {
|
|
9
|
+
imageMaxBytes: 30 * MB,
|
|
10
|
+
mediaMaxBytes: 50 * MB,
|
|
11
|
+
maxImages: 9,
|
|
12
|
+
maxVideos: 3,
|
|
13
|
+
maxAudio: 3,
|
|
14
|
+
maxFiles: 12,
|
|
15
|
+
// The website enlarges smaller images before submitting; the public API
|
|
16
|
+
// does not, so the CLI asks for a larger image instead.
|
|
17
|
+
minImageEdge: 300,
|
|
18
|
+
minAspectRatio: 0.4,
|
|
19
|
+
maxAspectRatio: 2.5,
|
|
20
|
+
minVideoSeconds: 1.8,
|
|
21
|
+
maxTimedSeconds: 15.3,
|
|
22
|
+
maxVideoPixels: 927_408,
|
|
23
|
+
};
|
|
24
|
+
function mb(bytes) {
|
|
25
|
+
return `${(bytes / MB).toFixed(1)} MB`;
|
|
26
|
+
}
|
|
27
|
+
/** Problems with the local files of one request, in plain sentences. */
|
|
28
|
+
export function findMediaProblems(model, files) {
|
|
29
|
+
const problems = [];
|
|
30
|
+
for (const file of files) {
|
|
31
|
+
if (file.size === 0)
|
|
32
|
+
problems.push(`${file.fileName} is empty.`);
|
|
33
|
+
if (file.size > UPLOAD_MAX_BYTES) {
|
|
34
|
+
problems.push(`${file.fileName} is ${mb(file.size)}; files must be under ${mb(UPLOAD_MAX_BYTES)}.`);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
if (model !== "seedance2")
|
|
38
|
+
return problems;
|
|
39
|
+
const count = (kind) => files.filter((file) => file.kind === kind).length;
|
|
40
|
+
if (count("image") > SEEDANCE2.maxImages) {
|
|
41
|
+
problems.push(`At most ${SEEDANCE2.maxImages} images are allowed.`);
|
|
42
|
+
}
|
|
43
|
+
if (count("video") > SEEDANCE2.maxVideos) {
|
|
44
|
+
problems.push(`At most ${SEEDANCE2.maxVideos} videos are allowed.`);
|
|
45
|
+
}
|
|
46
|
+
if (count("audio") > SEEDANCE2.maxAudio) {
|
|
47
|
+
problems.push(`At most ${SEEDANCE2.maxAudio} audio files are allowed.`);
|
|
48
|
+
}
|
|
49
|
+
if (files.length > SEEDANCE2.maxFiles) {
|
|
50
|
+
problems.push(`At most ${SEEDANCE2.maxFiles} reference files are allowed.`);
|
|
51
|
+
}
|
|
52
|
+
let timedSeconds = 0;
|
|
53
|
+
for (const file of files) {
|
|
54
|
+
const limit = file.kind === "image" ? SEEDANCE2.imageMaxBytes : SEEDANCE2.mediaMaxBytes;
|
|
55
|
+
if (file.size > limit) {
|
|
56
|
+
problems.push(`${file.fileName} is ${mb(file.size)}; ${file.kind} files must be under ${mb(limit)}.`);
|
|
57
|
+
}
|
|
58
|
+
if (file.kind === "image" && file.width && file.height) {
|
|
59
|
+
if (Math.min(file.width, file.height) < SEEDANCE2.minImageEdge) {
|
|
60
|
+
problems.push(`${file.fileName} is ${file.width}×${file.height}; use an image at least ${SEEDANCE2.minImageEdge}px on each side.`);
|
|
61
|
+
}
|
|
62
|
+
const ratio = file.width / file.height;
|
|
63
|
+
if (ratio < SEEDANCE2.minAspectRatio ||
|
|
64
|
+
ratio > SEEDANCE2.maxAspectRatio) {
|
|
65
|
+
problems.push(`${file.fileName} has an aspect ratio of ${ratio.toFixed(2)}; it must be between ${SEEDANCE2.minAspectRatio} and ${SEEDANCE2.maxAspectRatio}.`);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
if (file.kind === "video" && file.width && file.height) {
|
|
69
|
+
if (file.width * file.height > SEEDANCE2.maxVideoPixels) {
|
|
70
|
+
problems.push(`${file.fileName} is ${file.width}×${file.height}; reference videos can be at most about 720p.`);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
if (file.kind !== "image" && file.durationSeconds !== undefined) {
|
|
74
|
+
if (file.kind === "video" &&
|
|
75
|
+
file.durationSeconds < SEEDANCE2.minVideoSeconds) {
|
|
76
|
+
problems.push(`${file.fileName} is ${file.durationSeconds.toFixed(1)} s; reference videos must be at least ${SEEDANCE2.minVideoSeconds} s.`);
|
|
77
|
+
}
|
|
78
|
+
timedSeconds += file.durationSeconds;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
if (timedSeconds > SEEDANCE2.maxTimedSeconds) {
|
|
82
|
+
problems.push(`Reference videos and audio total ${timedSeconds.toFixed(1)} s; the limit is about 15 s.`);
|
|
83
|
+
}
|
|
84
|
+
return problems;
|
|
85
|
+
}
|
|
86
|
+
export function assertMediaAcceptable(model, files) {
|
|
87
|
+
const problems = findMediaProblems(model, files);
|
|
88
|
+
if (problems.length > 0) {
|
|
89
|
+
throw new CliError("invalid_file", problems.join(" "), "Replace the file and try again. Nothing was uploaded or charged.", { problems });
|
|
90
|
+
}
|
|
91
|
+
}
|
package/dist/cli.js
ADDED
|
@@ -0,0 +1,334 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { execFile } from "node:child_process";
|
|
3
|
+
import { realpathSync } from "node:fs";
|
|
4
|
+
import { createInterface } from "node:readline/promises";
|
|
5
|
+
import { fileURLToPath } from "node:url";
|
|
6
|
+
import { parseArgs } from "node:util";
|
|
7
|
+
import { ApiClient } from "./api.js";
|
|
8
|
+
import { assertMediaAcceptable } from "./checks.js";
|
|
9
|
+
import { CLI_VERSION, resolveConfigDir, resolveSiteOrigin, siteKey, } from "./config.js";
|
|
10
|
+
import { nameConnection } from "./connection-name.js";
|
|
11
|
+
import { CliError, errorPayload, withNetworkHint } from "./errors.js";
|
|
12
|
+
import { ConfigFiles } from "./files.js";
|
|
13
|
+
import { inspectMediaFile } from "./media.js";
|
|
14
|
+
import { readRequestFile, resolveLocalPath, SUPPORTED_MODELS, } from "./requests.js";
|
|
15
|
+
import { describeModel } from "./schema.js";
|
|
16
|
+
import { newRequestId, SeedanceService, TERMINAL_STATUSES } from "./service.js";
|
|
17
|
+
import { Session } from "./session.js";
|
|
18
|
+
import { checkForUpdate } from "./update-check.js";
|
|
19
|
+
import { Uploader } from "./upload.js";
|
|
20
|
+
const HELP = `Seedance3 CLI ${CLI_VERSION} — generate with your Seedance 3.0 AI account.
|
|
21
|
+
|
|
22
|
+
Usage: seedance3 <command> [options]
|
|
23
|
+
|
|
24
|
+
Sign-in
|
|
25
|
+
auth login [--credential-store keychain|file]
|
|
26
|
+
Sign in through your browser.
|
|
27
|
+
auth login --no-browser
|
|
28
|
+
Sign in with a browser on another device, then paste
|
|
29
|
+
back the address it ends on (or pass it later with
|
|
30
|
+
auth login --redirect-url <address>).
|
|
31
|
+
auth status Show whether this computer is signed in.
|
|
32
|
+
auth logout Sign out and disconnect this computer's access.
|
|
33
|
+
|
|
34
|
+
Account and models
|
|
35
|
+
account Credit balance.
|
|
36
|
+
models Models you can generate with.
|
|
37
|
+
model <id> Request fields of one model.
|
|
38
|
+
|
|
39
|
+
Generate
|
|
40
|
+
estimate --input <request.json>
|
|
41
|
+
Credit cost, no charge. Local files are uploaded.
|
|
42
|
+
create --input <request.json> [--max-credits <n>] [--request-id <id>]
|
|
43
|
+
[--wait] [--timeout <seconds>]
|
|
44
|
+
Spends credits. Prints the request ID on stderr.
|
|
45
|
+
upload <file>... [--model <id>]
|
|
46
|
+
Upload local files and print their URLs.
|
|
47
|
+
|
|
48
|
+
Tasks
|
|
49
|
+
tasks [--limit <n>] Recent tasks, newest first.
|
|
50
|
+
task <id> One task.
|
|
51
|
+
wait <id> [--timeout <seconds>]
|
|
52
|
+
Wait until a task finishes (it keeps running on timeout).
|
|
53
|
+
download <id> [--output <path>]
|
|
54
|
+
Save a completed task's results. Never overwrites.
|
|
55
|
+
|
|
56
|
+
Results are JSON on stdout; progress and errors go to stderr.
|
|
57
|
+
Guide: https://www.seedances3.com/cli`;
|
|
58
|
+
const defaultIo = {
|
|
59
|
+
stdout: (text) => process.stdout.write(`${text}\n`),
|
|
60
|
+
stderr: (text) => process.stderr.write(`${text}\n`),
|
|
61
|
+
};
|
|
62
|
+
function openInBrowser(url) {
|
|
63
|
+
const command = process.platform === "darwin" ? "open" : "xdg-open";
|
|
64
|
+
return new Promise((resolve) => {
|
|
65
|
+
execFile(command, [url], { timeout: 10_000 }, (error) => resolve(!error));
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
const COMMAND_LINE_OPTIONS = {
|
|
69
|
+
help: { type: "boolean", short: "h" },
|
|
70
|
+
version: { type: "boolean", short: "v" },
|
|
71
|
+
input: { type: "string", short: "i" },
|
|
72
|
+
output: { type: "string", short: "o" },
|
|
73
|
+
wait: { type: "boolean" },
|
|
74
|
+
timeout: { type: "string" },
|
|
75
|
+
"request-id": { type: "string" },
|
|
76
|
+
"max-credits": { type: "string" },
|
|
77
|
+
limit: { type: "string" },
|
|
78
|
+
model: { type: "string" },
|
|
79
|
+
"no-browser": { type: "boolean" },
|
|
80
|
+
"redirect-url": { type: "string" },
|
|
81
|
+
"credential-store": { type: "string" },
|
|
82
|
+
};
|
|
83
|
+
/**
|
|
84
|
+
* One line typed by the user, read from a terminal; null when stdin is not a
|
|
85
|
+
* terminal, as when an agent runs the CLI and cannot answer a prompt.
|
|
86
|
+
*/
|
|
87
|
+
async function readLineFromTerminal(prompt) {
|
|
88
|
+
if (!process.stdin.isTTY)
|
|
89
|
+
return null;
|
|
90
|
+
const reader = createInterface({
|
|
91
|
+
input: process.stdin,
|
|
92
|
+
output: process.stderr,
|
|
93
|
+
});
|
|
94
|
+
try {
|
|
95
|
+
return await reader.question(prompt);
|
|
96
|
+
}
|
|
97
|
+
finally {
|
|
98
|
+
reader.close();
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
const PROGRESS_INTERVAL_MS = 30_000;
|
|
102
|
+
function formatElapsed(ms) {
|
|
103
|
+
const seconds = Math.round(ms / 1000);
|
|
104
|
+
const minutes = Math.floor(seconds / 60);
|
|
105
|
+
return minutes > 0 ? `${minutes}m${seconds % 60}s` : `${seconds}s`;
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* While a task runs, one line on stderr every 30 seconds, so a person
|
|
109
|
+
* watching a video that takes minutes sees it is still going rather than
|
|
110
|
+
* stopping the command and submitting again.
|
|
111
|
+
*/
|
|
112
|
+
export function progressLogger(id, log, now = Date.now) {
|
|
113
|
+
const started = now();
|
|
114
|
+
let lastLogged = started;
|
|
115
|
+
return (task) => {
|
|
116
|
+
const time = now();
|
|
117
|
+
if (time - lastLogged < PROGRESS_INTERVAL_MS)
|
|
118
|
+
return;
|
|
119
|
+
lastLogged = time;
|
|
120
|
+
log(`Task ${id} is still ${task.status} (${formatElapsed(time - started)})…`);
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
function positiveInteger(value, name) {
|
|
124
|
+
if (value === undefined)
|
|
125
|
+
return undefined;
|
|
126
|
+
const number = Number(value);
|
|
127
|
+
if (!Number.isInteger(number) || number <= 0) {
|
|
128
|
+
throw new CliError("usage", `${name} must be a positive whole number.`);
|
|
129
|
+
}
|
|
130
|
+
return number;
|
|
131
|
+
}
|
|
132
|
+
function requireArg(value, usage) {
|
|
133
|
+
if (!value)
|
|
134
|
+
throw new CliError("usage", `Usage: seedance3 ${usage}`);
|
|
135
|
+
return value;
|
|
136
|
+
}
|
|
137
|
+
function parseCommandLine(argv) {
|
|
138
|
+
try {
|
|
139
|
+
return parseArgs({
|
|
140
|
+
args: argv,
|
|
141
|
+
allowPositionals: true,
|
|
142
|
+
strict: true,
|
|
143
|
+
options: COMMAND_LINE_OPTIONS,
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
catch (error) {
|
|
147
|
+
throw new CliError("usage", error instanceof Error ? error.message : String(error), "Run `seedance3 --help`.");
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
export async function main(argv, io = defaultIo) {
|
|
151
|
+
const { values, positionals } = parseCommandLine(argv);
|
|
152
|
+
const [command, ...rest] = positionals;
|
|
153
|
+
if (values.version) {
|
|
154
|
+
io.stdout(CLI_VERSION);
|
|
155
|
+
return 0;
|
|
156
|
+
}
|
|
157
|
+
if (values.help || !command || command === "help") {
|
|
158
|
+
io.stdout(HELP);
|
|
159
|
+
return 0;
|
|
160
|
+
}
|
|
161
|
+
const origin = resolveSiteOrigin();
|
|
162
|
+
const files = new ConfigFiles(resolveConfigDir());
|
|
163
|
+
const session = new Session(origin, files);
|
|
164
|
+
const api = new ApiClient(origin, session);
|
|
165
|
+
const log = (message) => io.stderr(message);
|
|
166
|
+
const uploader = new Uploader(api, files, `uploads-${siteKey(origin)}.json`, log);
|
|
167
|
+
const service = new SeedanceService(api, uploader);
|
|
168
|
+
const print = (value) => io.stdout(JSON.stringify(value, null, 2));
|
|
169
|
+
const update = checkForUpdate({ files });
|
|
170
|
+
switch (`${command}${command === "auth" ? ` ${rest[0] ?? ""}` : ""}`) {
|
|
171
|
+
case "auth login": {
|
|
172
|
+
const store = values["credential-store"];
|
|
173
|
+
if (store !== undefined && store !== "keychain" && store !== "file") {
|
|
174
|
+
throw new CliError("usage", "--credential-store must be keychain or file.");
|
|
175
|
+
}
|
|
176
|
+
const result = await session.login({
|
|
177
|
+
credentialStore: store,
|
|
178
|
+
noBrowser: values["no-browser"],
|
|
179
|
+
redirectUrl: values["redirect-url"],
|
|
180
|
+
openBrowser: openInBrowser,
|
|
181
|
+
readLine: readLineFromTerminal,
|
|
182
|
+
log,
|
|
183
|
+
});
|
|
184
|
+
if (result.status === "pending") {
|
|
185
|
+
print({ signed_in: false, waiting_for: "--redirect-url" });
|
|
186
|
+
break;
|
|
187
|
+
}
|
|
188
|
+
await nameConnection({ origin, tokens: session });
|
|
189
|
+
print({
|
|
190
|
+
signed_in: true,
|
|
191
|
+
site: origin,
|
|
192
|
+
credential_store: await session.credentialStoreKind(),
|
|
193
|
+
});
|
|
194
|
+
break;
|
|
195
|
+
}
|
|
196
|
+
case "auth status":
|
|
197
|
+
print({
|
|
198
|
+
signed_in: await session.isSignedIn(),
|
|
199
|
+
site: origin,
|
|
200
|
+
credential_store: await session.credentialStoreKind(),
|
|
201
|
+
});
|
|
202
|
+
break;
|
|
203
|
+
case "auth logout": {
|
|
204
|
+
const result = await session.logout();
|
|
205
|
+
if (result.wasSignedIn && !result.disconnected) {
|
|
206
|
+
log(`Signed out here, but the website did not confirm the disconnection. Disconnect "Seedance3 CLI" at ${origin}/app/api if needed.`);
|
|
207
|
+
}
|
|
208
|
+
print({
|
|
209
|
+
signed_in: false,
|
|
210
|
+
was_signed_in: result.wasSignedIn,
|
|
211
|
+
disconnected: result.disconnected,
|
|
212
|
+
});
|
|
213
|
+
break;
|
|
214
|
+
}
|
|
215
|
+
case "account":
|
|
216
|
+
print(await service.balance());
|
|
217
|
+
break;
|
|
218
|
+
case "models":
|
|
219
|
+
print({ data: await service.models() });
|
|
220
|
+
break;
|
|
221
|
+
case "model": {
|
|
222
|
+
const id = requireArg(rest[0], "model <id>");
|
|
223
|
+
const model = (await service.models()).find((item) => item.id === id);
|
|
224
|
+
if (!model) {
|
|
225
|
+
throw new CliError("invalid_request", `Model "${id}" is not available in the CLI.`, `Use one of: ${SUPPORTED_MODELS.join(", ")}.`);
|
|
226
|
+
}
|
|
227
|
+
print(await describeModel({ origin, model }));
|
|
228
|
+
break;
|
|
229
|
+
}
|
|
230
|
+
case "estimate": {
|
|
231
|
+
const request = await readRequestFile(requireArg(values.input, "estimate --input <request.json>"));
|
|
232
|
+
print(await service.quote(request));
|
|
233
|
+
break;
|
|
234
|
+
}
|
|
235
|
+
case "create": {
|
|
236
|
+
const request = await readRequestFile(requireArg(values.input, "create --input <request.json>"));
|
|
237
|
+
// Options are checked before anything is submitted, so a mistyped one
|
|
238
|
+
// never fails after credits were spent.
|
|
239
|
+
const maxCredits = positiveInteger(values["max-credits"], "--max-credits");
|
|
240
|
+
const timeoutSeconds = positiveInteger(values.timeout, "--timeout") ?? 900;
|
|
241
|
+
const requestId = values["request-id"] ?? newRequestId();
|
|
242
|
+
log(`Request ID: ${requestId} (rerun with --request-id ${requestId} to retry without a second charge)`);
|
|
243
|
+
// Running this command again as it is would submit, and charge, a
|
|
244
|
+
// second generation; a dropped connection says how to go on instead.
|
|
245
|
+
const task = await service
|
|
246
|
+
.create(request, { requestId, maxCredits })
|
|
247
|
+
.catch((error) => {
|
|
248
|
+
throw withNetworkHint(error, `Check the connection, then run the command again with --request-id ${requestId}: one request ID is charged only once.`);
|
|
249
|
+
});
|
|
250
|
+
if (!values.wait) {
|
|
251
|
+
// A repeated request ID answers with the first submission's
|
|
252
|
+
// response, whose status can be long out of date; show the task as
|
|
253
|
+
// it is now. If that read fails, the submission's answer still holds.
|
|
254
|
+
const current = TERMINAL_STATUSES.has(task.status)
|
|
255
|
+
? task
|
|
256
|
+
: await service.task(task.id).catch(() => task);
|
|
257
|
+
print({ ...task, ...current, request_id: requestId });
|
|
258
|
+
break;
|
|
259
|
+
}
|
|
260
|
+
log(`Task ${task.id} submitted; waiting for the result…`);
|
|
261
|
+
const finished = await service
|
|
262
|
+
.wait(task.id, {
|
|
263
|
+
timeoutSeconds,
|
|
264
|
+
onPoll: progressLogger(task.id, log),
|
|
265
|
+
})
|
|
266
|
+
.catch((error) => {
|
|
267
|
+
throw withNetworkHint(error, `Task ${task.id} was submitted and keeps running. Check the connection, then follow it with \`seedance3 wait ${task.id}\`; do not submit it again.`);
|
|
268
|
+
});
|
|
269
|
+
print({ ...finished, request_id: requestId });
|
|
270
|
+
break;
|
|
271
|
+
}
|
|
272
|
+
case "upload": {
|
|
273
|
+
if (rest.length === 0)
|
|
274
|
+
throw new CliError("usage", "Usage: seedance3 upload <file>...");
|
|
275
|
+
const media = await Promise.all(rest.map((file) => inspectMediaFile(resolveLocalPath(file, process.cwd()))));
|
|
276
|
+
assertMediaAcceptable(values.model ?? "", media);
|
|
277
|
+
const urls = await uploader.upload(media);
|
|
278
|
+
print({
|
|
279
|
+
files: media.map((file, index) => ({
|
|
280
|
+
path: file.path,
|
|
281
|
+
url: urls[index],
|
|
282
|
+
})),
|
|
283
|
+
});
|
|
284
|
+
break;
|
|
285
|
+
}
|
|
286
|
+
case "tasks":
|
|
287
|
+
print(await service.tasks(positiveInteger(values.limit, "--limit")));
|
|
288
|
+
break;
|
|
289
|
+
case "task":
|
|
290
|
+
print(await service.task(requireArg(rest[0], "task <id>")));
|
|
291
|
+
break;
|
|
292
|
+
case "wait": {
|
|
293
|
+
const id = requireArg(rest[0], "wait <id>");
|
|
294
|
+
print(await service.wait(id, {
|
|
295
|
+
timeoutSeconds: positiveInteger(values.timeout, "--timeout") ?? 900,
|
|
296
|
+
onPoll: progressLogger(id, log),
|
|
297
|
+
}));
|
|
298
|
+
break;
|
|
299
|
+
}
|
|
300
|
+
case "download": {
|
|
301
|
+
const id = requireArg(rest[0], "download <id> [--output <path>]");
|
|
302
|
+
const { files: saved } = await service.download(id, values.output);
|
|
303
|
+
print({ id, files: saved });
|
|
304
|
+
break;
|
|
305
|
+
}
|
|
306
|
+
default:
|
|
307
|
+
throw new CliError("usage", `Unknown command: ${positionals.join(" ")}`, "Run `seedance3 --help`.");
|
|
308
|
+
}
|
|
309
|
+
const notice = await update;
|
|
310
|
+
if (notice)
|
|
311
|
+
log(notice);
|
|
312
|
+
return 0;
|
|
313
|
+
}
|
|
314
|
+
async function run() {
|
|
315
|
+
try {
|
|
316
|
+
process.exitCode = await main(process.argv.slice(2));
|
|
317
|
+
}
|
|
318
|
+
catch (error) {
|
|
319
|
+
process.stderr.write(`${JSON.stringify(errorPayload(error), null, 2)}\n`);
|
|
320
|
+
process.exitCode =
|
|
321
|
+
error instanceof CliError && error.code === "usage" ? 2 : 1;
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
function isEntryPoint() {
|
|
325
|
+
try {
|
|
326
|
+
return (realpathSync(process.argv[1] ?? "") ===
|
|
327
|
+
realpathSync(fileURLToPath(import.meta.url)));
|
|
328
|
+
}
|
|
329
|
+
catch {
|
|
330
|
+
return false;
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
if (isEntryPoint())
|
|
334
|
+
void run();
|