@acedatacloud/piece-seedance 0.0.0-stage → 0.1.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.
- package/LICENSE +21 -0
- package/README.md +36 -2
- package/README.zh-CN.md +37 -0
- package/dist/src/index.d.ts +1 -0
- package/dist/src/index.js +17 -0
- package/dist/src/lib/actions/generate-video.d.ts +8 -0
- package/dist/src/lib/actions/generate-video.js +90 -0
- package/dist/src/lib/actions/get-task.d.ts +3 -0
- package/dist/src/lib/actions/get-task.js +31 -0
- package/dist/src/lib/auth.d.ts +1 -0
- package/dist/src/lib/auth.js +9 -0
- package/dist/src/lib/common/client.d.ts +24 -0
- package/dist/src/lib/common/client.js +129 -0
- package/package.json +28 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Ace Data Cloud
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,37 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Seedance for Activepieces
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Create a Seedance text-to-video task and retrieve the **same task ID** through Ace Data Cloud. The Piece has two actions: **Create Seedance video task** and **Get Seedance task**. A task ID means the request was accepted, not that the video is ready. [中文指南](README.zh-CN.md)
|
|
4
|
+
|
|
5
|
+
**Distribution:** Install `@acedatacloud/piece-seedance@0.1.0` as a custom Piece in your Activepieces instance. A public npm package does not automatically enter the shared Activepieces catalog.
|
|
6
|
+
|
|
7
|
+
## Install and connect
|
|
8
|
+
|
|
9
|
+
In Activepieces 0.92.2+, open **Platform Admin → Catalogue → Pieces → Install Piece → NPM Registry**. Enter `@acedatacloud/piece-seedance` and version `0.1.0`. Search for **Seedance by Ace Data Cloud** when adding a flow action, then check the logo and both actions.
|
|
10
|
+
|
|
11
|
+
Create a connection using an Ace Data Cloud API key with access to `/seedance/videos` and `/seedance/tasks`. Enter only the key, without `Bearer `. Keep it in the connection, never in a flow export. Check current [pricing](https://platform.acedata.cloud/models) and balance before generating.
|
|
12
|
+
|
|
13
|
+
## First flow
|
|
14
|
+
|
|
15
|
+
1. Add **Create Seedance video task**. Enter a text description. For a small first run, choose `doubao-seedance-2-0-mini-260615`, `480p`, 4 seconds, `16:9`, and leave **Generate audio** off.
|
|
16
|
+
2. Run creation **once** and save `task_id`. The action uses `callback_url` for asynchronous submission and has no HTTP retry. If a timeout or 5xx occurs, inspect request history before trying again: a task may already exist.
|
|
17
|
+
3. Add **Get Seedance task** and map **Task ID** from the creation output. Query that same ID until `status=succeeded` or `failed`. Pending media is not returned as final video.
|
|
18
|
+
4. Open a URL in `media_urls` only when `success=true`. A task lookup does not create or bill another video.
|
|
19
|
+
|
|
20
|
+
The [credential-free quickstart flow](https://raw.githubusercontent.com/AceDataCloud/SeedanceActivepieces/main/examples/seedance-quickstart.json) imports with both connections empty and the same task-ID mapping intact. Add your own connection before running. Creation retries are disabled in the sample.
|
|
21
|
+
|
|
22
|
+
The Piece offers three Seedance 2.0 text-to-video models and the common `480p`/`720p`, 4–15 second range. It does not claim to expose image/video/audio reference, edit, extend, or every advanced Seedance operation. Audio generation and model choice can change price.
|
|
23
|
+
|
|
24
|
+
An isolated Activepieces CE 0.92.2 instance accepted the build archive and ran **Get Seedance task** against an existing completed task. The flow returned `succeeded` and one final video URL. The creation action has not submitted a new paid video in this validation.
|
|
25
|
+
|
|
26
|
+
## Troubleshoot
|
|
27
|
+
|
|
28
|
+
| Result | Action |
|
|
29
|
+
| --- | --- |
|
|
30
|
+
| 401 / 403 | Check the API key, Seedance access, and Allowed APIs for both paths. |
|
|
31
|
+
| 400 | Check the model, text, duration, resolution, and ratio. |
|
|
32
|
+
| `pending` | Wait and query the same task ID; do not rerun creation. |
|
|
33
|
+
| 429 | Reduce concurrency and wait; avoid automatic paid retries. |
|
|
34
|
+
| Creation timeout or 5xx | Inspect request history before another submission. |
|
|
35
|
+
| `failed` | Use the task or trace ID to inspect the failed request. |
|
|
36
|
+
|
|
37
|
+
The Piece sends selected inputs and the API key only to `https://api.acedata.cloud`. It exposes final media URLs and removes internal routing fields from task output. [Source](https://github.com/AceDataCloud/SeedanceActivepieces) · [Support](https://github.com/AceDataCloud/SeedanceActivepieces/issues) · dev@acedata.cloud.
|
package/README.zh-CN.md
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
# Seedance for Activepieces
|
|
2
|
+
|
|
3
|
+
通过 Ace Data Cloud 创建 Seedance 文生视频任务,并按**同一个任务 ID**查询结果。Piece 提供 **Create Seedance video task** 与 **Get Seedance task** 两个动作。拿到任务 ID 不代表视频已经完成。[English](README.md)
|
|
4
|
+
|
|
5
|
+
**分发方式:**在 Activepieces 实例中将 `@acedatacloud/piece-seedance@0.1.0` 作为自定义 Piece 安装。公开 npm 包不会自动进入 Activepieces 共享目录。
|
|
6
|
+
|
|
7
|
+
## 安装与连接
|
|
8
|
+
|
|
9
|
+
Activepieces 0.92.2+ 中进入 **Platform Admin → Catalogue → Pieces → Install Piece → NPM Registry**,填写 `@acedatacloud/piece-seedance` 和版本 `0.1.0`。在流程中搜索 **Seedance by Ace Data Cloud**,核对 Logo 和两个动作。
|
|
10
|
+
|
|
11
|
+
创建连接时使用同时有 `/seedance/videos` 与 `/seedance/tasks` 权限的 Ace Data Cloud API Key。只填写 Key 本身,不加 `Bearer `;Key 留在连接中,不写入流程导出。生成前查看当前[价格](https://platform.acedata.cloud/models)与余额。
|
|
12
|
+
|
|
13
|
+
## 首次流程
|
|
14
|
+
|
|
15
|
+
1. 添加 **Create Seedance video task** 并填写文本描述。首次小样例可选 `doubao-seedance-2-0-mini-260615`、`480p`、4 秒、`16:9`,关闭 **Generate audio**。
|
|
16
|
+
2. **只运行一次**创建动作,保存输出的 `task_id`。动作使用 `callback_url` 异步提交,不设置 HTTP 重试。若超时或返回 5xx,先查请求历史再考虑重提;任务可能已被接收。
|
|
17
|
+
3. 添加 **Get Seedance task**,将 **Task ID** 映射为创建动作输出。只查询同一个 ID,直到 `status=succeeded` 或 `failed`。pending 时不展示最终视频链接。
|
|
18
|
+
4. 仅当 `success=true` 时打开 `media_urls`。查询不会再次创建视频或计费。
|
|
19
|
+
|
|
20
|
+
[无密钥首跑流程](https://raw.githubusercontent.com/AceDataCloud/SeedanceActivepieces/main/examples/seedance-quickstart.json) 导入后两个连接均为空,任务 ID 映射保留。运行前请配置自己的连接;样例已关闭创建动作的自动重试。
|
|
21
|
+
|
|
22
|
+
Piece 提供三个 Seedance 2.0 文生视频模型,以及通用的 `480p`/`720p`、4–15 秒选项。它尚未涵盖图片/视频/音频参考、编辑、延长等高级操作。音频生成与模型选择可能影响价格。
|
|
23
|
+
|
|
24
|
+
隔离的 Activepieces CE 0.92.2 实例已接受构建归档,并通过 **Get Seedance task** 查询既有完成任务;流程返回 `succeeded` 和 1 个最终视频 URL。本轮未通过创建动作提交新的付费视频任务。
|
|
25
|
+
|
|
26
|
+
## 排障
|
|
27
|
+
|
|
28
|
+
| 现象 | 处理 |
|
|
29
|
+
| --- | --- |
|
|
30
|
+
| 401 / 403 | 核对 Key、Seedance 权限和两个路径的 Allowed APIs。 |
|
|
31
|
+
| 400 | 核对模型、文本、时长、分辨率和画幅比例。 |
|
|
32
|
+
| `pending` | 等待并查询同一任务 ID,不重跑创建。 |
|
|
33
|
+
| 429 | 降低并发,避免自动重试付费创建。 |
|
|
34
|
+
| 创建超时或 5xx | 先检查请求历史,再考虑再次提交。 |
|
|
35
|
+
| `failed` | 用任务或 Trace ID 查失败原因。 |
|
|
36
|
+
|
|
37
|
+
Piece 只向 `https://api.acedata.cloud` 发送所选输入和 API Key,仅在终态返回媒体 URL,并过滤内部路由字段。[源码](https://github.com/AceDataCloud/SeedanceActivepieces) · [支持](https://github.com/AceDataCloud/SeedanceActivepieces/issues) · dev@acedata.cloud。
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const seedance: import("@activepieces/pieces-framework").Piece<import("@activepieces/pieces-framework").SecretTextProperty<true>>;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.seedance = void 0;
|
|
4
|
+
const pieces_framework_1 = require("@activepieces/pieces-framework");
|
|
5
|
+
const generate_video_1 = require("./lib/actions/generate-video");
|
|
6
|
+
const get_task_1 = require("./lib/actions/get-task");
|
|
7
|
+
const auth_1 = require("./lib/auth");
|
|
8
|
+
exports.seedance = (0, pieces_framework_1.createPiece)({
|
|
9
|
+
displayName: 'Seedance by Ace Data Cloud',
|
|
10
|
+
description: 'Create Seedance videos and retrieve the same task through Ace Data Cloud.',
|
|
11
|
+
logoUrl: 'https://cdn.acedata.cloud/assets/logo.png',
|
|
12
|
+
authors: ['Ace Data Cloud'],
|
|
13
|
+
minimumSupportedRelease: '0.92.2',
|
|
14
|
+
auth: auth_1.seedanceAuth,
|
|
15
|
+
actions: [generate_video_1.generateVideo, get_task_1.getTask],
|
|
16
|
+
triggers: [],
|
|
17
|
+
});
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export declare const generateVideo: import("@activepieces/pieces-framework").IAction<import("@activepieces/pieces-framework").SecretTextProperty<true>, {
|
|
2
|
+
prompt: import("@activepieces/pieces-framework").LongTextProperty<true>;
|
|
3
|
+
model: import("@activepieces/pieces-framework").StaticDropdownProperty<string, true>;
|
|
4
|
+
resolution: import("@activepieces/pieces-framework").StaticDropdownProperty<string, true>;
|
|
5
|
+
duration: import("@activepieces/pieces-framework").NumberProperty<true>;
|
|
6
|
+
ratio: import("@activepieces/pieces-framework").StaticDropdownProperty<string, true>;
|
|
7
|
+
generateAudio: import("@activepieces/pieces-framework").CheckboxProperty<false>;
|
|
8
|
+
}>;
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.generateVideo = void 0;
|
|
4
|
+
const pieces_framework_1 = require("@activepieces/pieces-framework");
|
|
5
|
+
const auth_1 = require("../auth");
|
|
6
|
+
const client_1 = require("../common/client");
|
|
7
|
+
exports.generateVideo = (0, pieces_framework_1.createAction)({
|
|
8
|
+
name: 'generate_video',
|
|
9
|
+
displayName: 'Create Seedance video task',
|
|
10
|
+
description: 'Submit one text-to-video generation and return its task ID. This action does not wait for final video.',
|
|
11
|
+
auth: auth_1.seedanceAuth,
|
|
12
|
+
props: {
|
|
13
|
+
prompt: pieces_framework_1.Property.LongText({
|
|
14
|
+
displayName: 'Video description',
|
|
15
|
+
description: 'Describe the scene and motion. Use Get Seedance task with the returned task ID.',
|
|
16
|
+
required: true,
|
|
17
|
+
}),
|
|
18
|
+
model: pieces_framework_1.Property.StaticDropdown({
|
|
19
|
+
displayName: 'Model',
|
|
20
|
+
required: true,
|
|
21
|
+
defaultValue: 'doubao-seedance-2-0-mini-260615',
|
|
22
|
+
options: {
|
|
23
|
+
options: [
|
|
24
|
+
{ label: 'Seedance 2.0 Mini', value: 'doubao-seedance-2-0-mini-260615' },
|
|
25
|
+
{ label: 'Seedance 2.0 Fast', value: 'doubao-seedance-2-0-fast-260128' },
|
|
26
|
+
{ label: 'Seedance 2.0', value: 'doubao-seedance-2-0-260128' },
|
|
27
|
+
],
|
|
28
|
+
},
|
|
29
|
+
}),
|
|
30
|
+
resolution: pieces_framework_1.Property.StaticDropdown({
|
|
31
|
+
displayName: 'Resolution',
|
|
32
|
+
description: '480p and 720p are supported by all models offered here.',
|
|
33
|
+
required: true,
|
|
34
|
+
defaultValue: '480p',
|
|
35
|
+
options: { options: [
|
|
36
|
+
{ label: '480p', value: '480p' },
|
|
37
|
+
{ label: '720p', value: '720p' },
|
|
38
|
+
] },
|
|
39
|
+
}),
|
|
40
|
+
duration: pieces_framework_1.Property.Number({
|
|
41
|
+
displayName: 'Duration in seconds',
|
|
42
|
+
description: 'A whole number from 4 to 15 for the Seedance 2.0 models offered here.',
|
|
43
|
+
required: true,
|
|
44
|
+
defaultValue: 4,
|
|
45
|
+
}),
|
|
46
|
+
ratio: pieces_framework_1.Property.StaticDropdown({
|
|
47
|
+
displayName: 'Aspect ratio',
|
|
48
|
+
required: true,
|
|
49
|
+
defaultValue: '16:9',
|
|
50
|
+
options: { options: [
|
|
51
|
+
{ label: '16:9', value: '16:9' },
|
|
52
|
+
{ label: '9:16', value: '9:16' },
|
|
53
|
+
{ label: '1:1', value: '1:1' },
|
|
54
|
+
] },
|
|
55
|
+
}),
|
|
56
|
+
generateAudio: pieces_framework_1.Property.Checkbox({
|
|
57
|
+
displayName: 'Generate audio',
|
|
58
|
+
description: 'Optional audio generation can change the current price.',
|
|
59
|
+
required: false,
|
|
60
|
+
defaultValue: false,
|
|
61
|
+
}),
|
|
62
|
+
},
|
|
63
|
+
async run(context) {
|
|
64
|
+
const { prompt, model, resolution, duration, ratio, generateAudio } = context.propsValue;
|
|
65
|
+
if (!prompt.trim()) {
|
|
66
|
+
throw new Error('A video description is required.');
|
|
67
|
+
}
|
|
68
|
+
if (!Number.isInteger(duration) || duration < 4 || duration > 15) {
|
|
69
|
+
throw new Error('Duration must be a whole number from 4 to 15 seconds.');
|
|
70
|
+
}
|
|
71
|
+
const response = await client_1.seedanceClient.post({
|
|
72
|
+
token: context.auth.secret_text,
|
|
73
|
+
path: '/seedance/videos',
|
|
74
|
+
body: {
|
|
75
|
+
model,
|
|
76
|
+
content: [{ type: 'text', text: prompt }],
|
|
77
|
+
resolution,
|
|
78
|
+
duration,
|
|
79
|
+
ratio,
|
|
80
|
+
generate_audio: generateAudio ?? false,
|
|
81
|
+
callback_url: 'https://api.acedata.cloud/health',
|
|
82
|
+
},
|
|
83
|
+
});
|
|
84
|
+
const taskId = client_1.seedanceClient.taskIdFromSubmission(response);
|
|
85
|
+
if (!taskId) {
|
|
86
|
+
throw new Error('No task ID was returned. Inspect request history before submitting again.');
|
|
87
|
+
}
|
|
88
|
+
return { task_id: taskId, status: 'pending', success: false };
|
|
89
|
+
},
|
|
90
|
+
});
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getTask = void 0;
|
|
4
|
+
const pieces_framework_1 = require("@activepieces/pieces-framework");
|
|
5
|
+
const auth_1 = require("../auth");
|
|
6
|
+
const client_1 = require("../common/client");
|
|
7
|
+
exports.getTask = (0, pieces_framework_1.createAction)({
|
|
8
|
+
name: 'get_task',
|
|
9
|
+
displayName: 'Get Seedance task',
|
|
10
|
+
description: 'Retrieve one existing task ID. Pending previews are not final video.',
|
|
11
|
+
auth: auth_1.seedanceAuth,
|
|
12
|
+
props: {
|
|
13
|
+
taskId: pieces_framework_1.Property.ShortText({
|
|
14
|
+
displayName: 'Task ID',
|
|
15
|
+
description: 'Map the task_id output from Create Seedance video task. Query this same ID until it succeeds or fails.',
|
|
16
|
+
required: true,
|
|
17
|
+
}),
|
|
18
|
+
},
|
|
19
|
+
async run(context) {
|
|
20
|
+
const taskId = context.propsValue.taskId.trim();
|
|
21
|
+
if (!taskId) {
|
|
22
|
+
throw new Error('A task ID is required.');
|
|
23
|
+
}
|
|
24
|
+
const response = await client_1.seedanceClient.post({
|
|
25
|
+
token: context.auth.secret_text,
|
|
26
|
+
path: '/seedance/tasks',
|
|
27
|
+
body: { id: taskId },
|
|
28
|
+
});
|
|
29
|
+
return client_1.seedanceClient.normalizeTask({ body: response, taskId });
|
|
30
|
+
},
|
|
31
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const seedanceAuth: import("@activepieces/pieces-framework").SecretTextProperty<true>;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.seedanceAuth = void 0;
|
|
4
|
+
const pieces_framework_1 = require("@activepieces/pieces-framework");
|
|
5
|
+
exports.seedanceAuth = pieces_framework_1.PieceAuth.SecretText({
|
|
6
|
+
displayName: 'Ace Data Cloud API key',
|
|
7
|
+
description: 'Use an API key with Seedance access from https://platform.acedata.cloud/console/applications. Enter only the key, without Bearer.',
|
|
8
|
+
required: true,
|
|
9
|
+
});
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
declare function post({ token, path, body, }: {
|
|
2
|
+
token: string;
|
|
3
|
+
path: '/seedance/videos' | '/seedance/tasks';
|
|
4
|
+
body: Record<string, unknown>;
|
|
5
|
+
}): Promise<unknown>;
|
|
6
|
+
declare function normalizeTask({ body, taskId }: {
|
|
7
|
+
body: unknown;
|
|
8
|
+
taskId: string;
|
|
9
|
+
}): TaskResult;
|
|
10
|
+
declare function taskIdFromSubmission(body: unknown): string;
|
|
11
|
+
export declare const seedanceClient: {
|
|
12
|
+
post: typeof post;
|
|
13
|
+
normalizeTask: typeof normalizeTask;
|
|
14
|
+
taskIdFromSubmission: typeof taskIdFromSubmission;
|
|
15
|
+
};
|
|
16
|
+
export type TaskResult = {
|
|
17
|
+
task_id: string;
|
|
18
|
+
status: 'pending' | 'succeeded' | 'failed';
|
|
19
|
+
success: boolean;
|
|
20
|
+
trace_id: string;
|
|
21
|
+
media_urls: string[];
|
|
22
|
+
result: unknown;
|
|
23
|
+
};
|
|
24
|
+
export {};
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.seedanceClient = void 0;
|
|
4
|
+
const pieces_common_1 = require("@activepieces/pieces-common");
|
|
5
|
+
async function post({ token, path, body, }) {
|
|
6
|
+
const response = await pieces_common_1.httpClient.sendRequest({
|
|
7
|
+
method: pieces_common_1.HttpMethod.POST,
|
|
8
|
+
url: `https://api.acedata.cloud${path}`,
|
|
9
|
+
headers: {
|
|
10
|
+
Authorization: `Bearer ${token}`,
|
|
11
|
+
'Content-Type': 'application/json',
|
|
12
|
+
},
|
|
13
|
+
body,
|
|
14
|
+
retries: 0,
|
|
15
|
+
});
|
|
16
|
+
return response.body;
|
|
17
|
+
}
|
|
18
|
+
function normalizeTask({ body, taskId }) {
|
|
19
|
+
const envelope = record(body);
|
|
20
|
+
const payload = parsePayload('response' in envelope ? envelope.response : body);
|
|
21
|
+
const values = record(payload);
|
|
22
|
+
const states = collectStates(payload);
|
|
23
|
+
const failed = states.some((state) => FAILED_STATES.has(state)) || hasFailure(payload);
|
|
24
|
+
const unfinished = 'finished_at' in envelope && envelope.finished_at === null;
|
|
25
|
+
const finished = !unfinished &&
|
|
26
|
+
!failed &&
|
|
27
|
+
((states.length > 0 && states.every((state) => COMPLETE_STATES.has(state))) ||
|
|
28
|
+
Boolean(envelope.finished_at && hasContent(payload)));
|
|
29
|
+
const traceId = stringValue(values.trace_id) || stringValue(envelope.trace_id);
|
|
30
|
+
return {
|
|
31
|
+
task_id: taskId,
|
|
32
|
+
status: failed && !unfinished ? 'failed' : finished ? 'succeeded' : 'pending',
|
|
33
|
+
success: finished,
|
|
34
|
+
trace_id: traceId,
|
|
35
|
+
media_urls: finished ? collectMediaUrls(payload) : [],
|
|
36
|
+
result: sanitize(payload),
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
function taskIdFromSubmission(body) {
|
|
40
|
+
const value = record(body);
|
|
41
|
+
const nestedTask = record(value.task);
|
|
42
|
+
return stringValue(value.task_id) || stringValue(nestedTask.id);
|
|
43
|
+
}
|
|
44
|
+
function parsePayload(value) {
|
|
45
|
+
if (typeof value !== 'string') {
|
|
46
|
+
return value;
|
|
47
|
+
}
|
|
48
|
+
try {
|
|
49
|
+
return JSON.parse(value);
|
|
50
|
+
}
|
|
51
|
+
catch {
|
|
52
|
+
return {};
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
function record(value) {
|
|
56
|
+
return value !== null && typeof value === 'object' && !Array.isArray(value)
|
|
57
|
+
? Object.fromEntries(Object.entries(value))
|
|
58
|
+
: {};
|
|
59
|
+
}
|
|
60
|
+
function stringValue(value) {
|
|
61
|
+
return typeof value === 'string' ? value : '';
|
|
62
|
+
}
|
|
63
|
+
function collectStates(value) {
|
|
64
|
+
if (Array.isArray(value)) {
|
|
65
|
+
return value.flatMap(collectStates);
|
|
66
|
+
}
|
|
67
|
+
if (value === null || typeof value !== 'object') {
|
|
68
|
+
return [];
|
|
69
|
+
}
|
|
70
|
+
const item = record(value);
|
|
71
|
+
return [
|
|
72
|
+
...['state', 'status'].flatMap((key) => {
|
|
73
|
+
const state = stringValue(item[key]);
|
|
74
|
+
return state ? [state.toLowerCase()] : [];
|
|
75
|
+
}),
|
|
76
|
+
...['data', 'content', 'task'].flatMap((key) => collectStates(item[key])),
|
|
77
|
+
];
|
|
78
|
+
}
|
|
79
|
+
function hasFailure(value) {
|
|
80
|
+
if (Array.isArray(value)) {
|
|
81
|
+
return value.some(hasFailure);
|
|
82
|
+
}
|
|
83
|
+
if (value === null || typeof value !== 'object') {
|
|
84
|
+
return false;
|
|
85
|
+
}
|
|
86
|
+
const item = record(value);
|
|
87
|
+
return Boolean(item.error) ||
|
|
88
|
+
(item.success === false && !['pending', 'running', 'processing'].includes(stringValue(item.status || item.state).toLowerCase())) ||
|
|
89
|
+
['data', 'content', 'task'].some((key) => hasFailure(item[key]));
|
|
90
|
+
}
|
|
91
|
+
function collectMediaUrls(value) {
|
|
92
|
+
if (Array.isArray(value)) {
|
|
93
|
+
return [...new Set(value.flatMap(collectMediaUrls))];
|
|
94
|
+
}
|
|
95
|
+
if (value === null || typeof value !== 'object') {
|
|
96
|
+
return [];
|
|
97
|
+
}
|
|
98
|
+
const item = record(value);
|
|
99
|
+
const urls = Object.entries(item).flatMap(([key, child]) => {
|
|
100
|
+
if (['video_url', 'file_url', 'url'].includes(key) && typeof child === 'string') {
|
|
101
|
+
return child.startsWith('https://') ? [child] : [];
|
|
102
|
+
}
|
|
103
|
+
return collectMediaUrls(child);
|
|
104
|
+
});
|
|
105
|
+
return [...new Set(urls)];
|
|
106
|
+
}
|
|
107
|
+
function hasContent(value) {
|
|
108
|
+
return Array.isArray(value) ? value.length > 0 : Object.keys(record(value)).length > 0;
|
|
109
|
+
}
|
|
110
|
+
function sanitize(value) {
|
|
111
|
+
if (Array.isArray(value)) {
|
|
112
|
+
return value.map(sanitize);
|
|
113
|
+
}
|
|
114
|
+
if (value === null || typeof value !== 'object') {
|
|
115
|
+
return value;
|
|
116
|
+
}
|
|
117
|
+
return Object.fromEntries(Object.entries(value)
|
|
118
|
+
.filter(([key]) => !SENSITIVE_KEYS.has(key.toLowerCase()) && !SENSITIVE_KEY_PATTERN.test(key))
|
|
119
|
+
.map(([key, child]) => [key, key === 'error' ? 'Task failed; inspect its task or trace ID.' : sanitize(child)]));
|
|
120
|
+
}
|
|
121
|
+
exports.seedanceClient = { post, normalizeTask, taskIdFromSubmission };
|
|
122
|
+
const COMPLETE_STATES = new Set(['complete', 'completed', 'succeeded', 'succeed', 'success', 'finished']);
|
|
123
|
+
const FAILED_STATES = new Set(['failed', 'error', 'cancelled', 'canceled', 'rejected']);
|
|
124
|
+
const SENSITIVE_KEYS = new Set([
|
|
125
|
+
'request', 'request_body', 'user_id', 'actor_user_id', 'credential_id', 'authorization_id',
|
|
126
|
+
'application_id', 'api_key', 'access_token', 'refresh_token', 'authorization', 'headers',
|
|
127
|
+
'supplier', 'supplier_id', 'provider_route', 'upstream', 'upstream_model', 'actual_model', 'secret',
|
|
128
|
+
]);
|
|
129
|
+
const SENSITIVE_KEY_PATTERN = /(^internal(?:_|$)|supplier|upstream|(?:^|_)secret(?:_|$))/i;
|
package/package.json
CHANGED
|
@@ -1,6 +1,30 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@acedatacloud/piece-seedance",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Seedance video generation and task lookup through Ace Data Cloud for Activepieces",
|
|
5
|
+
"type": "commonjs",
|
|
6
|
+
"main": "./dist/src/index.js",
|
|
7
|
+
"types": "./dist/src/index.d.ts",
|
|
8
|
+
"files": [
|
|
9
|
+
"dist"
|
|
10
|
+
],
|
|
11
|
+
"scripts": {
|
|
12
|
+
"build": "tsc -p tsconfig.json",
|
|
13
|
+
"test": "npm run build && node --test test/*.test.cjs",
|
|
14
|
+
"pack:check": "npm pack --dry-run"
|
|
15
|
+
},
|
|
16
|
+
"repository": {
|
|
17
|
+
"type": "git",
|
|
18
|
+
"url": "git+https://github.com/AceDataCloud/SeedanceActivepieces.git"
|
|
19
|
+
},
|
|
20
|
+
"homepage": "https://github.com/AceDataCloud/SeedanceActivepieces#readme",
|
|
21
|
+
"bugs": "https://github.com/AceDataCloud/SeedanceActivepieces/issues",
|
|
22
|
+
"license": "MIT",
|
|
23
|
+
"dependencies": {
|
|
24
|
+
"@activepieces/pieces-common": "0.12.5",
|
|
25
|
+
"@activepieces/pieces-framework": "0.32.0"
|
|
26
|
+
},
|
|
27
|
+
"devDependencies": {
|
|
28
|
+
"typescript": "5.9.3"
|
|
29
|
+
}
|
|
30
|
+
}
|