@acedatacloud/piece-fish-audio 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/get-task.d.ts +3 -0
- package/dist/src/lib/actions/get-task.js +31 -0
- package/dist/src/lib/actions/synthesize-speech.d.ts +6 -0
- package/dist/src/lib/actions/synthesize-speech.js +72 -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 +25 -0
- package/dist/src/lib/common/client.js +133 -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
|
+
# Fish Audio for Activepieces
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Synthesize speech through Ace Data Cloud and retrieve an asynchronous Fish Audio task by the **same task ID**. The Piece has **Synthesize Fish Audio speech** and **Get Fish Audio task** actions. [中文指南](README.zh-CN.md)
|
|
4
|
+
|
|
5
|
+
**Distribution:** Install `@acedatacloud/piece-fish-audio@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-fish-audio` and version `0.1.0`. Search for **Fish Audio by Ace Data Cloud** when adding a flow action, then check the Ace Data Cloud logo and both actions.
|
|
10
|
+
|
|
11
|
+
Create a connection using an Ace Data Cloud API key with access to `/fish/tts` and `/fish/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 synthesis.
|
|
12
|
+
|
|
13
|
+
## First flow
|
|
14
|
+
|
|
15
|
+
1. Add **Synthesize Fish Audio speech**. Enter the text, select `s2-pro` and `mp3`, and optionally enter a saved or public **Reference voice ID**. The Piece sends the model in the `model` request header, not the JSON body.
|
|
16
|
+
2. The action requests asynchronous synthesis and does not retry the paid request. If it returns `task_id`, save that ID; if the API returns a direct `audio_url`, the action returns `succeeded` and the final URL immediately.
|
|
17
|
+
3. For an asynchronous task, add **Get Fish Audio task** and map **Task ID** from the first action. Query the same ID until `status=succeeded` or `failed`. Do not rerun synthesis while polling. A direct final audio response needs no lookup.
|
|
18
|
+
4. Open a URL in `media_urls` only when `success=true`. Task lookup does not create or bill another speech request.
|
|
19
|
+
|
|
20
|
+
The [credential-free quickstart flow](https://raw.githubusercontent.com/AceDataCloud/FishAudioActivepieces/main/examples/fish-audio-quickstart.json) imports with both connections empty and the task-ID mapping intact. Configure your own connection before running. The sample follows the asynchronous task path and has synthesis retries disabled.
|
|
21
|
+
|
|
22
|
+
This first Piece supports text-to-speech with three published engines, MP3/WAV output and an optional existing voice ID. It does not yet expose voice creation, one-shot references, prosody controls, or the full Fish Audio API. Synthesis cost depends on the current price and text length.
|
|
23
|
+
|
|
24
|
+
An isolated Activepieces CE 0.92.2 instance accepted the build archive and ran **Get Fish Audio task** against an existing completed task. The flow returned `succeeded` and one final audio URL. The synthesis action has not submitted a new paid request in this validation.
|
|
25
|
+
|
|
26
|
+
## Troubleshoot
|
|
27
|
+
|
|
28
|
+
| Result | Action |
|
|
29
|
+
| --- | --- |
|
|
30
|
+
| 401 / 403 | Check the API key, Fish Audio access, and Allowed APIs for both paths. |
|
|
31
|
+
| 400 | Check text, format, and reference voice ID. |
|
|
32
|
+
| `pending` | Wait and query the same task ID; do not rerun synthesis. |
|
|
33
|
+
| 429 | Reduce concurrency and wait; avoid automatic paid retries. |
|
|
34
|
+
| Synthesis timeout or 5xx | Inspect request history before another submission. |
|
|
35
|
+
| `failed` or missing task | Check the task ID and retention window. |
|
|
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/FishAudioActivepieces) · [Support](https://github.com/AceDataCloud/FishAudioActivepieces/issues) · dev@acedata.cloud.
|
package/README.zh-CN.md
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
# Fish Audio for Activepieces
|
|
2
|
+
|
|
3
|
+
通过 Ace Data Cloud 合成语音,并按**同一个任务 ID**查询 Fish Audio 异步任务。Piece 提供 **Synthesize Fish Audio speech** 和 **Get Fish Audio task** 两个动作。[English](README.md)
|
|
4
|
+
|
|
5
|
+
**分发方式:**在 Activepieces 实例中将 `@acedatacloud/piece-fish-audio@0.1.0` 作为自定义 Piece 安装。公开 npm 包不会自动进入 Activepieces 共享目录。
|
|
6
|
+
|
|
7
|
+
## 安装与连接
|
|
8
|
+
|
|
9
|
+
Activepieces 0.92.2+ 中进入 **Platform Admin → Catalogue → Pieces → Install Piece → NPM Registry**,填写 `@acedatacloud/piece-fish-audio` 和版本 `0.1.0`。在流程中搜索 **Fish Audio by Ace Data Cloud**,核对 Ace Data Cloud Logo 和两个动作。
|
|
10
|
+
|
|
11
|
+
创建连接时使用同时有 `/fish/tts` 与 `/fish/tasks` 权限的 Ace Data Cloud API Key。只填写 Key 本身,不加 `Bearer `;Key 留在连接中,不写入流程导出。合成前查看当前[价格](https://platform.acedata.cloud/models)与余额。
|
|
12
|
+
|
|
13
|
+
## 首次流程
|
|
14
|
+
|
|
15
|
+
1. 添加 **Synthesize Fish Audio speech**,填写文本,选择 `s2-pro`、`mp3`,可选填现有或公开声音的 **Reference voice ID**。Piece 把模型放在 `model` 请求头,而不是 JSON 请求体。
|
|
16
|
+
2. 动作请求异步合成,不重试付费请求。若返回 `task_id`,保存它;若 API 直接返回 `audio_url`,动作立即返回 `succeeded` 和最终链接。
|
|
17
|
+
3. 对异步任务添加 **Get Fish Audio task**,把 **Task ID** 映射为上一动作输出。只查询同一 ID,直到 `status=succeeded` 或 `failed`;轮询不重跑合成。直接得到最终音频时无需查询。
|
|
18
|
+
4. 仅当 `success=true` 时打开 `media_urls`。查询任务不会再次创建语音或计费。
|
|
19
|
+
|
|
20
|
+
[无密钥首跑流程](https://raw.githubusercontent.com/AceDataCloud/FishAudioActivepieces/main/examples/fish-audio-quickstart.json) 导入后两个连接均为空,任务 ID 映射保留。运行前请配置自己的连接。样例走异步任务路径,并已关闭合成动作的自动重试。
|
|
21
|
+
|
|
22
|
+
首版支持三个公开语音引擎、MP3/WAV 输出和可选的现有声音 ID;尚未涵盖创建声音、一次性参考音频、韵律控制或 Fish Audio 全部 API。合成费用取决于当前价格和文本长度。
|
|
23
|
+
|
|
24
|
+
隔离的 Activepieces CE 0.92.2 实例已接受构建归档,并通过 **Get Fish Audio task** 查询既有完成任务;流程返回 `succeeded` 和 1 个最终音频 URL。本轮未通过合成动作提交新的付费请求。
|
|
25
|
+
|
|
26
|
+
## 排障
|
|
27
|
+
|
|
28
|
+
| 现象 | 处理 |
|
|
29
|
+
| --- | --- |
|
|
30
|
+
| 401 / 403 | 核对 Key、Fish Audio 权限和两个路径的 Allowed APIs。 |
|
|
31
|
+
| 400 | 核对文本、格式和声音 ID。 |
|
|
32
|
+
| `pending` | 等待并查询同一任务 ID,不重跑合成。 |
|
|
33
|
+
| 429 | 降低并发,避免自动重试付费请求。 |
|
|
34
|
+
| 合成超时或 5xx | 先查请求历史,再考虑再次提交。 |
|
|
35
|
+
| `failed` 或任务不存在 | 检查任务 ID 和保留期限。 |
|
|
36
|
+
|
|
37
|
+
Piece 只向 `https://api.acedata.cloud` 发送所选输入和 API Key,仅在终态返回媒体 URL,并过滤内部路由字段。[源码](https://github.com/AceDataCloud/FishAudioActivepieces) · [支持](https://github.com/AceDataCloud/FishAudioActivepieces/issues) · dev@acedata.cloud。
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const fishAudio: 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.fishAudio = void 0;
|
|
4
|
+
const pieces_framework_1 = require("@activepieces/pieces-framework");
|
|
5
|
+
const synthesize_speech_1 = require("./lib/actions/synthesize-speech");
|
|
6
|
+
const get_task_1 = require("./lib/actions/get-task");
|
|
7
|
+
const auth_1 = require("./lib/auth");
|
|
8
|
+
exports.fishAudio = (0, pieces_framework_1.createPiece)({
|
|
9
|
+
displayName: 'Fish Audio by Ace Data Cloud',
|
|
10
|
+
description: 'Synthesize Fish Audio speech 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.fishAudioAuth,
|
|
15
|
+
actions: [synthesize_speech_1.synthesizeSpeech, get_task_1.getTask],
|
|
16
|
+
triggers: [],
|
|
17
|
+
});
|
|
@@ -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 Fish Audio task',
|
|
10
|
+
description: 'Retrieve one existing task ID. Pending previews are not final audio.',
|
|
11
|
+
auth: auth_1.fishAudioAuth,
|
|
12
|
+
props: {
|
|
13
|
+
taskId: pieces_framework_1.Property.ShortText({
|
|
14
|
+
displayName: 'Task ID',
|
|
15
|
+
description: 'Map the task_id output from Synthesize Fish Audio speech. 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.fishAudioClient.post({
|
|
25
|
+
token: context.auth.secret_text,
|
|
26
|
+
path: '/fish/tasks',
|
|
27
|
+
body: { id: taskId },
|
|
28
|
+
});
|
|
29
|
+
return client_1.fishAudioClient.normalizeTask({ body: response, taskId });
|
|
30
|
+
},
|
|
31
|
+
});
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export declare const synthesizeSpeech: import("@activepieces/pieces-framework").IAction<import("@activepieces/pieces-framework").SecretTextProperty<true>, {
|
|
2
|
+
text: import("@activepieces/pieces-framework").LongTextProperty<true>;
|
|
3
|
+
model: import("@activepieces/pieces-framework").StaticDropdownProperty<string, true>;
|
|
4
|
+
format: import("@activepieces/pieces-framework").StaticDropdownProperty<string, true>;
|
|
5
|
+
referenceId: import("@activepieces/pieces-framework").ShortTextProperty<false>;
|
|
6
|
+
}>;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.synthesizeSpeech = 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.synthesizeSpeech = (0, pieces_framework_1.createAction)({
|
|
8
|
+
name: 'synthesize_speech',
|
|
9
|
+
displayName: 'Synthesize Fish Audio speech',
|
|
10
|
+
description: 'Submit one text-to-speech request. Async responses return a task ID; a direct audio response is already final.',
|
|
11
|
+
auth: auth_1.fishAudioAuth,
|
|
12
|
+
props: {
|
|
13
|
+
text: pieces_framework_1.Property.LongText({
|
|
14
|
+
displayName: 'Text to speak',
|
|
15
|
+
description: 'Words to synthesize. Billing depends on the text length.',
|
|
16
|
+
required: true,
|
|
17
|
+
}),
|
|
18
|
+
model: pieces_framework_1.Property.StaticDropdown({
|
|
19
|
+
displayName: 'Engine',
|
|
20
|
+
description: 'Sent in the model request header, not the JSON body.',
|
|
21
|
+
required: true,
|
|
22
|
+
defaultValue: 's2-pro',
|
|
23
|
+
options: { options: [
|
|
24
|
+
{ label: 'S2 Pro', value: 's2-pro' },
|
|
25
|
+
{ label: 'S2.1 Pro', value: 's2.1-pro' },
|
|
26
|
+
{ label: 'S1', value: 's1' },
|
|
27
|
+
] },
|
|
28
|
+
}),
|
|
29
|
+
format: pieces_framework_1.Property.StaticDropdown({
|
|
30
|
+
displayName: 'Audio format',
|
|
31
|
+
required: true,
|
|
32
|
+
defaultValue: 'mp3',
|
|
33
|
+
options: { options: [
|
|
34
|
+
{ label: 'MP3', value: 'mp3' },
|
|
35
|
+
{ label: 'WAV', value: 'wav' },
|
|
36
|
+
] },
|
|
37
|
+
}),
|
|
38
|
+
referenceId: pieces_framework_1.Property.ShortText({
|
|
39
|
+
displayName: 'Reference voice ID',
|
|
40
|
+
description: 'Optional public or saved Fish voice model ID.',
|
|
41
|
+
required: false,
|
|
42
|
+
}),
|
|
43
|
+
},
|
|
44
|
+
async run(context) {
|
|
45
|
+
const { text, model, format, referenceId } = context.propsValue;
|
|
46
|
+
if (!text.trim()) {
|
|
47
|
+
throw new Error('Text to speak is required.');
|
|
48
|
+
}
|
|
49
|
+
const response = await client_1.fishAudioClient.post({
|
|
50
|
+
token: context.auth.secret_text,
|
|
51
|
+
path: '/fish/tts',
|
|
52
|
+
model,
|
|
53
|
+
body: {
|
|
54
|
+
text,
|
|
55
|
+
format,
|
|
56
|
+
...(referenceId?.trim() ? { reference_id: referenceId.trim() } : {}),
|
|
57
|
+
async: true,
|
|
58
|
+
callback_url: 'https://api.acedata.cloud/health',
|
|
59
|
+
},
|
|
60
|
+
});
|
|
61
|
+
const taskId = client_1.fishAudioClient.taskIdFromSubmission(response);
|
|
62
|
+
if (taskId) {
|
|
63
|
+
return { task_id: taskId, status: 'pending', success: false, media_urls: [] };
|
|
64
|
+
}
|
|
65
|
+
const direct = response !== null && typeof response === 'object' && !Array.isArray(response)
|
|
66
|
+
? response.audio_url : undefined;
|
|
67
|
+
if (typeof direct === 'string' && direct.startsWith('https://')) {
|
|
68
|
+
return { task_id: '', status: 'succeeded', success: true, media_urls: [direct] };
|
|
69
|
+
}
|
|
70
|
+
throw new Error('No task ID or final audio URL was returned. Inspect request history before submitting again.');
|
|
71
|
+
},
|
|
72
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const fishAudioAuth: import("@activepieces/pieces-framework").SecretTextProperty<true>;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.fishAudioAuth = void 0;
|
|
4
|
+
const pieces_framework_1 = require("@activepieces/pieces-framework");
|
|
5
|
+
exports.fishAudioAuth = pieces_framework_1.PieceAuth.SecretText({
|
|
6
|
+
displayName: 'Ace Data Cloud API key',
|
|
7
|
+
description: 'Use an API key with Fish Audio access from https://platform.acedata.cloud/console/applications. Enter only the key, without Bearer.',
|
|
8
|
+
required: true,
|
|
9
|
+
});
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
declare function post({ token, path, body, model, }: {
|
|
2
|
+
token: string;
|
|
3
|
+
path: '/fish/tts' | '/fish/tasks';
|
|
4
|
+
body: Record<string, unknown>;
|
|
5
|
+
model?: string;
|
|
6
|
+
}): Promise<unknown>;
|
|
7
|
+
declare function normalizeTask({ body, taskId }: {
|
|
8
|
+
body: unknown;
|
|
9
|
+
taskId: string;
|
|
10
|
+
}): TaskResult;
|
|
11
|
+
declare function taskIdFromSubmission(body: unknown): string;
|
|
12
|
+
export declare const fishAudioClient: {
|
|
13
|
+
post: typeof post;
|
|
14
|
+
normalizeTask: typeof normalizeTask;
|
|
15
|
+
taskIdFromSubmission: typeof taskIdFromSubmission;
|
|
16
|
+
};
|
|
17
|
+
export type TaskResult = {
|
|
18
|
+
task_id: string;
|
|
19
|
+
status: 'pending' | 'succeeded' | 'failed';
|
|
20
|
+
success: boolean;
|
|
21
|
+
trace_id: string;
|
|
22
|
+
media_urls: string[];
|
|
23
|
+
result: unknown;
|
|
24
|
+
};
|
|
25
|
+
export {};
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.fishAudioClient = void 0;
|
|
4
|
+
const pieces_common_1 = require("@activepieces/pieces-common");
|
|
5
|
+
async function post({ token, path, body, model, }) {
|
|
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
|
+
...(model ? { model } : {}),
|
|
13
|
+
},
|
|
14
|
+
body,
|
|
15
|
+
retries: 0,
|
|
16
|
+
});
|
|
17
|
+
return response.body;
|
|
18
|
+
}
|
|
19
|
+
function normalizeTask({ body, taskId }) {
|
|
20
|
+
const envelope = record(body);
|
|
21
|
+
if (Object.keys(envelope).length === 0) {
|
|
22
|
+
throw new Error('Task not found. Check the task ID and its retention window.');
|
|
23
|
+
}
|
|
24
|
+
const payload = parsePayload('response' in envelope ? envelope.response : body);
|
|
25
|
+
const values = record(payload);
|
|
26
|
+
const states = collectStates(payload);
|
|
27
|
+
const failed = states.some((state) => FAILED_STATES.has(state)) || hasFailure(payload) || Boolean(envelope.error);
|
|
28
|
+
const unfinished = 'finished_at' in envelope && envelope.finished_at === null;
|
|
29
|
+
const finished = !unfinished &&
|
|
30
|
+
!failed &&
|
|
31
|
+
((states.length > 0 && states.every((state) => COMPLETE_STATES.has(state))) ||
|
|
32
|
+
Boolean(envelope.finished_at && hasContent(payload)));
|
|
33
|
+
const traceId = stringValue(values.trace_id) || stringValue(envelope.trace_id);
|
|
34
|
+
return {
|
|
35
|
+
task_id: taskId,
|
|
36
|
+
status: failed ? 'failed' : finished ? 'succeeded' : 'pending',
|
|
37
|
+
success: finished,
|
|
38
|
+
trace_id: traceId,
|
|
39
|
+
media_urls: finished ? collectMediaUrls(payload) : [],
|
|
40
|
+
result: sanitize(payload),
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
function taskIdFromSubmission(body) {
|
|
44
|
+
const value = record(body);
|
|
45
|
+
const nestedTask = record(value.task);
|
|
46
|
+
return stringValue(value.task_id) || stringValue(nestedTask.id);
|
|
47
|
+
}
|
|
48
|
+
function parsePayload(value) {
|
|
49
|
+
if (typeof value !== 'string') {
|
|
50
|
+
return value;
|
|
51
|
+
}
|
|
52
|
+
try {
|
|
53
|
+
return JSON.parse(value);
|
|
54
|
+
}
|
|
55
|
+
catch {
|
|
56
|
+
return {};
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
function record(value) {
|
|
60
|
+
return value !== null && typeof value === 'object' && !Array.isArray(value)
|
|
61
|
+
? Object.fromEntries(Object.entries(value))
|
|
62
|
+
: {};
|
|
63
|
+
}
|
|
64
|
+
function stringValue(value) {
|
|
65
|
+
return typeof value === 'string' ? value : '';
|
|
66
|
+
}
|
|
67
|
+
function collectStates(value) {
|
|
68
|
+
if (Array.isArray(value)) {
|
|
69
|
+
return value.flatMap(collectStates);
|
|
70
|
+
}
|
|
71
|
+
if (value === null || typeof value !== 'object') {
|
|
72
|
+
return [];
|
|
73
|
+
}
|
|
74
|
+
const item = record(value);
|
|
75
|
+
return [
|
|
76
|
+
...['state', 'status'].flatMap((key) => {
|
|
77
|
+
const state = stringValue(item[key]);
|
|
78
|
+
return state ? [state.toLowerCase()] : [];
|
|
79
|
+
}),
|
|
80
|
+
...['data', 'content', 'task'].flatMap((key) => collectStates(item[key])),
|
|
81
|
+
];
|
|
82
|
+
}
|
|
83
|
+
function hasFailure(value) {
|
|
84
|
+
if (Array.isArray(value)) {
|
|
85
|
+
return value.some(hasFailure);
|
|
86
|
+
}
|
|
87
|
+
if (value === null || typeof value !== 'object') {
|
|
88
|
+
return false;
|
|
89
|
+
}
|
|
90
|
+
const item = record(value);
|
|
91
|
+
return Boolean(item.error) ||
|
|
92
|
+
(item.success === false && !['pending', 'running', 'processing'].includes(stringValue(item.status || item.state).toLowerCase())) ||
|
|
93
|
+
['data', 'content', 'task'].some((key) => hasFailure(item[key]));
|
|
94
|
+
}
|
|
95
|
+
function collectMediaUrls(value) {
|
|
96
|
+
if (Array.isArray(value)) {
|
|
97
|
+
return [...new Set(value.flatMap(collectMediaUrls))];
|
|
98
|
+
}
|
|
99
|
+
if (value === null || typeof value !== 'object') {
|
|
100
|
+
return [];
|
|
101
|
+
}
|
|
102
|
+
const item = record(value);
|
|
103
|
+
const urls = Object.entries(item).flatMap(([key, child]) => {
|
|
104
|
+
if (['audio_url', 'file_url', 'url'].includes(key) && typeof child === 'string') {
|
|
105
|
+
return child.startsWith('https://') ? [child] : [];
|
|
106
|
+
}
|
|
107
|
+
return collectMediaUrls(child);
|
|
108
|
+
});
|
|
109
|
+
return [...new Set(urls)];
|
|
110
|
+
}
|
|
111
|
+
function hasContent(value) {
|
|
112
|
+
return Array.isArray(value) ? value.length > 0 : Object.keys(record(value)).length > 0;
|
|
113
|
+
}
|
|
114
|
+
function sanitize(value) {
|
|
115
|
+
if (Array.isArray(value)) {
|
|
116
|
+
return value.map(sanitize);
|
|
117
|
+
}
|
|
118
|
+
if (value === null || typeof value !== 'object') {
|
|
119
|
+
return value;
|
|
120
|
+
}
|
|
121
|
+
return Object.fromEntries(Object.entries(value)
|
|
122
|
+
.filter(([key]) => !SENSITIVE_KEYS.has(key.toLowerCase()) && !SENSITIVE_KEY_PATTERN.test(key))
|
|
123
|
+
.map(([key, child]) => [key, key === 'error' ? 'Task failed; inspect its task or trace ID.' : sanitize(child)]));
|
|
124
|
+
}
|
|
125
|
+
exports.fishAudioClient = { post, normalizeTask, taskIdFromSubmission };
|
|
126
|
+
const COMPLETE_STATES = new Set(['complete', 'completed', 'succeeded', 'succeed', 'success', 'finished']);
|
|
127
|
+
const FAILED_STATES = new Set(['failed', 'error', 'cancelled', 'canceled', 'rejected']);
|
|
128
|
+
const SENSITIVE_KEYS = new Set([
|
|
129
|
+
'request', 'request_body', 'user_id', 'actor_user_id', 'credential_id', 'authorization_id',
|
|
130
|
+
'application_id', 'api_key', 'access_token', 'refresh_token', 'authorization', 'headers',
|
|
131
|
+
'supplier', 'supplier_id', 'provider_route', 'upstream', 'upstream_model', 'actual_model', 'secret',
|
|
132
|
+
]);
|
|
133
|
+
const SENSITIVE_KEY_PATTERN = /(^internal(?:_|$)|supplier|upstream|(?:^|_)secret(?:_|$))/i;
|
package/package.json
CHANGED
|
@@ -1,6 +1,30 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@acedatacloud/piece-fish-audio",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Fish Audio text-to-speech 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/FishAudioActivepieces.git"
|
|
19
|
+
},
|
|
20
|
+
"homepage": "https://github.com/AceDataCloud/FishAudioActivepieces#readme",
|
|
21
|
+
"bugs": "https://github.com/AceDataCloud/FishAudioActivepieces/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
|
+
}
|