@acedatacloud/piece-fish-audio 0.1.4 → 0.1.6

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/README.md CHANGED
@@ -2,16 +2,16 @@
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
4
 
5
- **Distribution:** Install `@acedatacloud/piece-fish-audio@0.1.1` as a custom Piece in your Activepieces instance. A public npm package does not automatically enter the shared Activepieces catalog.
5
+ **Distribution:** Install `@acedatacloud/piece-fish-audio` (this source targets `0.1.6`; check npm for the published version) as a custom Piece in your Activepieces instance. A public npm package does not automatically enter the shared Activepieces catalog.
6
6
 
7
7
  ## Install and connect
8
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.4`. Search for **Fish Audio** when adding a flow action, then check the Ace Data Cloud logo and both actions.
9
+ In Activepieces 0.92.2+, open **Platform Admin → Catalogue → Pieces → Install Piece → NPM Registry**. Enter `@acedatacloud/piece-fish-audio` and the published version (this release targets `0.1.6`). Search for **Fish Audio** when adding a flow action, then check the Fish Audio icon and both actions.
10
10
 
11
- 1. Register or sign in at [Ace Data Cloud Applications](https://platform.acedata.cloud/console/applications?utm_source=opensource&utm_medium=referral&utm_campaign=evergreen). If you have no General application, choose **Initialize General Application**.
12
- 2. Open a General application or an application with **Fish Audio** access. A General key can access the services your account is entitled to use; a service-specific key is limited to that service.
13
- 3. Use the application's copy button, or choose **Manage Keys → Create** to create a separate key named `Activepieces Fish Audio`. Set expiry and usage limits as needed. If you restrict **Allowed APIs**, include both `/fish/tts` and `/fish/tasks`, then copy the key.
14
- 4. Create an Activepieces connection and enter only the API key, without `Bearer `. A `platform-...` management token is not a generation API key. Keep the key in the connection, never in a flow export. Check current [pricing](https://platform.acedata.cloud/models?utm_source=opensource&utm_medium=referral&utm_campaign=evergreen) and balance before synthesis.
11
+ 1. Register or sign in at [Ace Data Cloud Applications](https://platform.acedata.cloud/console/applications?utm_source=opensource&utm_medium=referral&utm_campaign=evergreen). The page prepares your **General Application** card automatically. If the card has no key, select **Create API Key** first.
12
+ 2. Use the **General Application** card and confirm your account has **Fish Audio** access. A General key can access the services your account is entitled to use; a service-specific key is limited to that service.
13
+ 3. Click the copy button beside **API KEY** on the application card, or choose **Manage Keys → Create** to create a separate key named `Activepieces Fish Audio`. Set expiry and usage limits as needed. If you restrict **Allowed APIs**, include both `/fish/tts` and `/fish/tasks`, then copy the key.
14
+ 4. Create an Activepieces connection and enter only the API key, without `Bearer `. A `platform-...` management token is not a generation API key. Keep the key in the connection, never in a flow export. Check current [pricing](https://platform.acedata.cloud/models?utm_source=opensource&utm_medium=referral&utm_campaign=evergreen) before synthesis. If the General Application balance is low, click **Top Up** on that card.
15
15
 
16
16
  ## First flow
17
17
 
@@ -26,6 +26,8 @@ This first Piece supports text-to-speech with three published engines, MP3/WAV o
26
26
 
27
27
  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.
28
28
 
29
+ Pending previews are withheld from `result` and `media_urls`. A completed task without a final media URL is reported as failed; inspect the original task and trace.
30
+
29
31
  ## Troubleshoot
30
32
 
31
33
  | Result | Action |
package/README.zh-CN.md CHANGED
@@ -2,16 +2,16 @@
2
2
 
3
3
  通过 Ace Data Cloud 合成语音,并按**同一个任务 ID**查询 Fish Audio 异步任务。Piece 提供 **Synthesize Fish Audio speech** 和 **Get Fish Audio task** 两个动作。[English](README.md)
4
4
 
5
- **分发方式:**在 Activepieces 实例中将 `@acedatacloud/piece-fish-audio@0.1.1` 作为自定义 Piece 安装。公开 npm 包不会自动进入 Activepieces 共享目录。
5
+ **分发方式:**在 Activepieces 实例中将 `@acedatacloud/piece-fish-audio`(本源码目标为 `0.1.6`,已发布版本请查看 npm) 作为自定义 Piece 安装。公开 npm 包不会自动进入 Activepieces 共享目录。
6
6
 
7
7
  ## 安装与连接
8
8
 
9
- Activepieces 0.92.2+ 中进入 **Platform Admin → Catalogue → Pieces → Install Piece → NPM Registry**,填写 `@acedatacloud/piece-fish-audio` 和版本 `0.1.4`。在流程中搜索 **Fish Audio**,核对 Ace Data Cloud Logo 和两个动作。
9
+ Activepieces 0.92.2+ 中进入 **Platform Admin → Catalogue → Pieces → Install Piece → NPM Registry**,填写 `@acedatacloud/piece-fish-audio` 和已发布版本(本次目标为 `0.1.6`)。在流程中搜索 **Fish Audio**,核对 Fish Audio 图标和两个动作。
10
10
 
11
- 1. 在 [Ace Data Cloud Applications](https://platform.acedata.cloud/console/applications?utm_source=opensource&utm_medium=referral&utm_campaign=evergreen) 注册或登录。若没有通用应用,点击 **Initialize General Application**。
12
- 2. 打开通用应用或具备 **Fish Audio** 权限的应用。通用 Key 可访问账号已获授权的服务;专用 Key 仅限对应服务。
13
- 3. 使用应用卡片的复制按钮,或通过 **Manage Keys → Create** 创建名为 `Activepieces Fish Audio` 的独立 Key,按需设置有效期与用量限制。若启用 **Allowed APIs**,应同时包含 `/fish/tts` 与 `/fish/tasks`,创建后复制 Key。
14
- 4. 创建 Activepieces 连接,只填写 API Key 本身,不加 `Bearer `。`platform-...` 管理 Token 不是生成 API Key。Key 留在连接中,不写入流程导出。合成前查看当前[价格](https://platform.acedata.cloud/models?utm_source=opensource&utm_medium=referral&utm_campaign=evergreen)与余额。
11
+ 1. 在 [Ace Data Cloud Applications](https://platform.acedata.cloud/console/applications?utm_source=opensource&utm_medium=referral&utm_campaign=evergreen) 注册或登录。页面会自动准备好**通用应用**卡片。若卡片尚无 Key,请先选择**创建 API Key**。
12
+ 2. 使用**通用应用**卡片,并确认账号具备 **Fish Audio** 权限。通用 Key 可访问账号已获授权的服务;专用 Key 仅限对应服务。
13
+ 3. 点击应用卡片上 **API KEY** 旁的复制按钮,或通过 **Manage Keys → Create** 创建名为 `Activepieces Fish Audio` 的独立 Key,按需设置有效期与用量限制。若启用 **Allowed APIs**,应同时包含 `/fish/tts` 与 `/fish/tasks`,创建后复制 Key。
14
+ 4. 创建 Activepieces 连接,只填写 API Key 本身,不加 `Bearer `。`platform-...` 管理 Token 不是生成 API Key。Key 留在连接中,不写入流程导出。合成前查看当前[价格](https://platform.acedata.cloud/models?utm_source=opensource&utm_medium=referral&utm_campaign=evergreen)。通用应用余额不足时,点击该卡片上的**充值**。
15
15
 
16
16
  ## 首次流程
17
17
 
@@ -26,6 +26,8 @@ Activepieces 0.92.2+ 中进入 **Platform Admin → Catalogue → Pieces → Ins
26
26
 
27
27
  隔离的 Activepieces CE 0.92.2 实例已接受构建归档,并通过 **Get Fish Audio task** 查询既有完成任务;流程返回 `succeeded` 和 1 个最终音频 URL。本轮未通过合成动作提交新的付费请求。
28
28
 
29
+ 待完成的预览不会出现在 `result` 或 `media_urls`;已结束但没有最终媒体 URL 的任务会报告失败,请检查原任务和 trace。
30
+
29
31
  ## 排障
30
32
 
31
33
  | 现象 | 处理 |
@@ -24,7 +24,7 @@ exports.getTask = (0, pieces_framework_1.createAction)({
24
24
  const response = await client_1.fishAudioClient.post({
25
25
  token: context.auth.secret_text,
26
26
  path: '/fish/tasks',
27
- body: { id: taskId },
27
+ body: { action: 'retrieve', id: taskId },
28
28
  });
29
29
  return client_1.fishAudioClient.normalizeTask({ body: response, taskId });
30
30
  },
@@ -58,6 +58,10 @@ exports.synthesizeSpeech = (0, pieces_framework_1.createAction)({
58
58
  callback_url: 'https://api.acedata.cloud/health',
59
59
  },
60
60
  });
61
+ if (response !== null && typeof response === 'object' && !Array.isArray(response) &&
62
+ (response.success === false || response.error)) {
63
+ throw new Error('The speech request was not accepted. Inspect request history before submitting again.');
64
+ }
61
65
  const taskId = client_1.fishAudioClient.taskIdFromSubmission(response);
62
66
  if (taskId) {
63
67
  return { task_id: taskId, status: 'pending', success: false, media_urls: [] };
@@ -4,6 +4,6 @@ exports.fishAudioAuth = void 0;
4
4
  const pieces_framework_1 = require("@activepieces/pieces-framework");
5
5
  exports.fishAudioAuth = pieces_framework_1.PieceAuth.SecretText({
6
6
  displayName: 'Ace Data Cloud API key',
7
- description: 'Register or sign in at [Applications](https://platform.acedata.cloud/console/applications?utm_source=activepieces&utm_medium=referral&utm_campaign=evergreen). If needed choose Initialize General Application, then copy the key or use Manage Keys → Create for a dedicated Activepieces key. Check service permissions, balance, current pricing and Allowed APIs in the guide. Paste only the API key without Bearer; a platform management token is not a generation key.',
7
+ description: 'Register or sign in at [Applications](https://platform.acedata.cloud/console/applications?utm_source=activepieces&utm_medium=referral&utm_campaign=evergreen). On the General Application card, select Create API Key first if no key appears. Then click the copy button beside API KEY. For a separate key, use Manage Keys → Create. Check service permissions, current pricing and Allowed APIs. If the General Application balance is low, click Top Up on that card. Paste only the API key without Bearer; a platform management token is not a generation key.',
8
8
  required: true,
9
9
  });
@@ -1,11 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.fishAudioClient = void 0;
4
- const pieces_common_1 = require("@activepieces/pieces-common");
5
4
  const secure_http_1 = require("../secure-http");
6
5
  async function post({ token, path, body, model, }) {
7
6
  const response = await secure_http_1.httpClient.sendRequest({
8
- method: pieces_common_1.HttpMethod.POST,
7
+ method: 'POST',
9
8
  url: `https://api.acedata.cloud${path}`,
10
9
  headers: {
11
10
  Authorization: `Bearer ${token}`,
@@ -19,26 +18,39 @@ async function post({ token, path, body, model, }) {
19
18
  }
20
19
  function normalizeTask({ body, taskId }) {
21
20
  const envelope = record(body);
22
- if (Object.keys(envelope).length === 0) {
23
- throw new Error('Task not found. Check the task ID and its retention window.');
21
+ const returnedTaskId = stringValue(envelope.id) || stringValue(envelope.task_id);
22
+ if (!returnedTaskId || !sameTaskId(returnedTaskId, taskId)) {
23
+ throw new Error('No matching task was returned. Check the original task ID.');
24
24
  }
25
25
  const payload = parsePayload('response' in envelope ? envelope.response : body);
26
26
  const values = record(payload);
27
+ const resultTaskId = stringValue(values.task_id);
28
+ if (resultTaskId && !sameTaskId(resultTaskId, taskId)) {
29
+ throw new Error('The response did not match the requested original task.');
30
+ }
31
+ const envelopeTrace = stringValue(envelope.trace_id);
32
+ const resultTrace = stringValue(values.trace_id);
33
+ if (envelopeTrace && resultTrace && envelopeTrace !== resultTrace) {
34
+ throw new Error('The response did not match the original task trace.');
35
+ }
27
36
  const states = collectStates(payload);
28
- const failed = states.some((state) => FAILED_STATES.has(state)) || hasFailure(payload) || Boolean(envelope.error);
29
- const unfinished = 'finished_at' in envelope && envelope.finished_at === null;
30
- const finished = !unfinished &&
31
- !failed &&
32
- ((states.length > 0 && states.every((state) => COMPLETE_STATES.has(state))) ||
33
- Boolean(envelope.finished_at && hasContent(payload)));
34
- const traceId = stringValue(values.trace_id) || stringValue(envelope.trace_id);
37
+ const envelopeState = stringValue(envelope.status) || stringValue(envelope.state);
38
+ if (envelopeState)
39
+ states.push(envelopeState.toLowerCase());
40
+ const failed = states.some((state) => FAILED_STATES.has(state)) || hasFailure(payload) ||
41
+ envelope.success === false || Boolean(envelope.error);
42
+ const hasFinish = envelope.finished_at !== undefined && envelope.finished_at !== null && envelope.finished_at !== '';
43
+ const completeStates = states.length === 0 || states.every((state) => COMPLETE_STATES.has(state));
44
+ const media = collectMediaUrls(payload);
45
+ const finished = hasFinish && !failed && completeStates && media.length > 0;
46
+ const noFinalMedia = hasFinish && !failed && completeStates && media.length === 0;
35
47
  return {
36
48
  task_id: taskId,
37
- status: failed ? 'failed' : finished ? 'succeeded' : 'pending',
49
+ status: failed || noFinalMedia ? 'failed' : finished ? 'succeeded' : 'pending',
38
50
  success: finished,
39
- trace_id: traceId,
40
- media_urls: finished ? collectMediaUrls(payload) : [],
41
- result: sanitize(payload),
51
+ trace_id: resultTrace || envelopeTrace,
52
+ media_urls: finished ? media : [],
53
+ result: finished ? sanitize(payload) : failed ? sanitizeFailure(payload) : {},
42
54
  };
43
55
  }
44
56
  function taskIdFromSubmission(body) {
@@ -65,6 +77,10 @@ function record(value) {
65
77
  function stringValue(value) {
66
78
  return typeof value === 'string' ? value : '';
67
79
  }
80
+ function sameTaskId(a, b) {
81
+ const uuid = /^[a-f0-9]{8}(?:-[a-f0-9]{4}){3}-[a-f0-9]{12}$/i;
82
+ return uuid.test(a) && uuid.test(b) ? a.toLowerCase() === b.toLowerCase() : a === b;
83
+ }
68
84
  function collectStates(value) {
69
85
  if (Array.isArray(value)) {
70
86
  return value.flatMap(collectStates);
@@ -109,9 +125,6 @@ function collectMediaUrls(value) {
109
125
  });
110
126
  return [...new Set(urls)];
111
127
  }
112
- function hasContent(value) {
113
- return Array.isArray(value) ? value.length > 0 : Object.keys(record(value)).length > 0;
114
- }
115
128
  function sanitize(value) {
116
129
  if (Array.isArray(value)) {
117
130
  return value.map(sanitize);
@@ -123,6 +136,14 @@ function sanitize(value) {
123
136
  .filter(([key]) => !SENSITIVE_KEYS.has(key.toLowerCase()) && !SENSITIVE_KEY_PATTERN.test(key))
124
137
  .map(([key, child]) => [key, key === 'error' ? 'Task failed; inspect its task or trace ID.' : sanitize(child)]));
125
138
  }
139
+ function sanitizeFailure(value) {
140
+ const item = record(value);
141
+ return {
142
+ ...(item.success === false ? { success: false } : {}),
143
+ ...(stringValue(item.task_id) ? { task_id: stringValue(item.task_id) } : {}),
144
+ ...(item.error ? { error: 'Task failed; inspect its task or trace ID.' } : {}),
145
+ };
146
+ }
126
147
  exports.fishAudioClient = { post, normalizeTask, taskIdFromSubmission };
127
148
  const COMPLETE_STATES = new Set(['complete', 'completed', 'succeeded', 'succeed', 'success', 'finished']);
128
149
  const FAILED_STATES = new Set(['failed', 'error', 'cancelled', 'canceled', 'rejected']);
@@ -37,7 +37,7 @@
37
37
  "pieceName": "@acedatacloud/piece-fish-audio",
38
38
  "actionName": "synthesize_speech",
39
39
  "sampleData": {},
40
- "pieceVersion": "0.1.4",
40
+ "pieceVersion": "0.1.6",
41
41
  "propertySettings": {
42
42
  "text": {
43
43
  "type": "MANUAL"
@@ -74,7 +74,7 @@
74
74
  "pieceName": "@acedatacloud/piece-fish-audio",
75
75
  "actionName": "get_task",
76
76
  "sampleData": {},
77
- "pieceVersion": "0.1.4",
77
+ "pieceVersion": "0.1.6",
78
78
  "propertySettings": {
79
79
  "taskId": {
80
80
  "type": "MANUAL"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@acedatacloud/piece-fish-audio",
3
- "version": "0.1.4",
3
+ "version": "0.1.6",
4
4
  "description": "Fish Audio text-to-speech and task lookup through Ace Data Cloud for Activepieces",
5
5
  "type": "commonjs",
6
6
  "main": "./dist/src/index.js",
@@ -24,7 +24,6 @@
24
24
  "bugs": "https://github.com/AceDataCloud/FishAudioActivepieces/issues",
25
25
  "license": "MIT",
26
26
  "dependencies": {
27
- "@activepieces/pieces-common": "0.12.5",
28
27
  "@activepieces/pieces-framework": "0.32.0"
29
28
  },
30
29
  "devDependencies": {