@mindscraft/branch-video-agent-cli 0.3.3 → 0.3.4
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 +25 -25
- package/dist/commands/aiGateway.js +53 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -127,37 +127,37 @@ AI Gateway 图片生成示例:
|
|
|
127
127
|
'@ | npm exec --yes --package=@mindscraft/branch-video-agent-cli branch-video-agent -- ai-gateway image-generate -- --raw
|
|
128
128
|
```
|
|
129
129
|
|
|
130
|
-
AI Gateway 视频生成并等待示例:
|
|
131
|
-
|
|
132
|
-
```powershell
|
|
133
|
-
@'
|
|
130
|
+
AI Gateway 视频生成并等待示例:
|
|
131
|
+
|
|
132
|
+
```powershell
|
|
133
|
+
@'
|
|
134
134
|
{
|
|
135
135
|
"model": "doubao-seedance-2-0-260128",
|
|
136
136
|
"input": {
|
|
137
137
|
"prompt": "镜头推进到实验台,卡通猫老师点亮一个小灯泡"
|
|
138
138
|
}
|
|
139
139
|
}
|
|
140
|
-
'@ | npm exec --yes --package=@mindscraft/branch-video-agent-cli branch-video-agent -- ai-gateway video-create -- --wait --raw
|
|
141
|
-
```
|
|
142
|
-
|
|
143
|
-
AI Gateway Seed Audio 音频生成并等待示例:
|
|
144
|
-
|
|
145
|
-
```powershell
|
|
146
|
-
@'
|
|
147
|
-
{
|
|
148
|
-
"model": "seed-audio-1.0",
|
|
149
|
-
"text_prompt": "温柔的女声朗读:欢迎使用豆包语音合成服务。背景加入轻柔科技感铺底音乐。",
|
|
150
|
-
"audio_config": {
|
|
151
|
-
"format": "mp3",
|
|
152
|
-
"sample_rate": 24000
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
'@ | npm exec --yes --package=@mindscraft/branch-video-agent-cli branch-video-agent -- ai-gateway seed-audio-create -- --wait --raw
|
|
156
|
-
```
|
|
157
|
-
|
|
158
|
-
`tts-create` / `tts-get` 是 Seed Audio 的历史兼容别名;新脚本优先使用 `seed-audio-create` / `seed-audio-get`。
|
|
159
|
-
|
|
160
|
-
## 在仓库内构建发布包
|
|
140
|
+
'@ | npm exec --yes --package=@mindscraft/branch-video-agent-cli branch-video-agent -- ai-gateway video-create -- --wait --raw
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
AI Gateway Seed Audio 音频生成并等待示例:
|
|
144
|
+
|
|
145
|
+
```powershell
|
|
146
|
+
@'
|
|
147
|
+
{
|
|
148
|
+
"model": "seed-audio-1.0",
|
|
149
|
+
"text_prompt": "温柔的女声朗读:欢迎使用豆包语音合成服务。背景加入轻柔科技感铺底音乐。",
|
|
150
|
+
"audio_config": {
|
|
151
|
+
"format": "mp3",
|
|
152
|
+
"sample_rate": 24000
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
'@ | npm exec --yes --package=@mindscraft/branch-video-agent-cli branch-video-agent -- ai-gateway seed-audio-create -- --wait --raw
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
`tts-create` / `tts-get` 是 Seed Audio 的历史兼容别名;新脚本优先使用 `seed-audio-create` / `seed-audio-get`。
|
|
159
|
+
|
|
160
|
+
## 在仓库内构建发布包
|
|
161
161
|
|
|
162
162
|
从仓库根目录执行:
|
|
163
163
|
|
|
@@ -43,6 +43,39 @@ function extractFailureMessage(value) {
|
|
|
43
43
|
|| record.error
|
|
44
44
|
|| 'AI Gateway task failed');
|
|
45
45
|
}
|
|
46
|
+
function isJsonRecord(value) {
|
|
47
|
+
return Boolean(value) && typeof value === 'object' && !Array.isArray(value);
|
|
48
|
+
}
|
|
49
|
+
function isHttpUrl(value) {
|
|
50
|
+
return typeof value === 'string' && /^https?:\/\//i.test(value);
|
|
51
|
+
}
|
|
52
|
+
function extractMusicAudioUrl(value) {
|
|
53
|
+
if (Array.isArray(value)) {
|
|
54
|
+
for (const item of value) {
|
|
55
|
+
const audioUrl = extractMusicAudioUrl(item);
|
|
56
|
+
if (audioUrl)
|
|
57
|
+
return audioUrl;
|
|
58
|
+
}
|
|
59
|
+
return '';
|
|
60
|
+
}
|
|
61
|
+
if (!isJsonRecord(value))
|
|
62
|
+
return '';
|
|
63
|
+
for (const key of ['audioUrl', 'streamAudioUrl']) {
|
|
64
|
+
if (isHttpUrl(value[key]))
|
|
65
|
+
return String(value[key]);
|
|
66
|
+
}
|
|
67
|
+
for (const item of Object.values(value)) {
|
|
68
|
+
const audioUrl = extractMusicAudioUrl(item);
|
|
69
|
+
if (audioUrl)
|
|
70
|
+
return audioUrl;
|
|
71
|
+
}
|
|
72
|
+
return '';
|
|
73
|
+
}
|
|
74
|
+
function withStableMusicAudioUrl(data, audioUrl) {
|
|
75
|
+
return isJsonRecord(data)
|
|
76
|
+
? { ...data, audioUrl }
|
|
77
|
+
: { status: data, audioUrl };
|
|
78
|
+
}
|
|
46
79
|
async function waitForGatewayTask(context, submit, poll) {
|
|
47
80
|
const startedAt = context.runtime.now();
|
|
48
81
|
while (context.runtime.now() - startedAt <= context.flags.timeoutMs) {
|
|
@@ -191,7 +224,18 @@ export const aiGatewayCommands = {
|
|
|
191
224
|
}
|
|
192
225
|
const taskId = extractTaskId(result.data);
|
|
193
226
|
const queryOperation = normalizeOperation(getOptionalString(context.payload, 'queryOperation') || inferMusicQueryOperation(operation));
|
|
194
|
-
|
|
227
|
+
const waitResult = await waitForGatewayTask(context, result.data, () => getMusicStatus(context, queryOperation, taskId));
|
|
228
|
+
if (queryOperation !== 'query')
|
|
229
|
+
return waitResult;
|
|
230
|
+
const statusData = isJsonRecord(waitResult.data) ? waitResult.data.status : undefined;
|
|
231
|
+
const audioUrl = extractMusicAudioUrl(statusData);
|
|
232
|
+
if (!audioUrl) {
|
|
233
|
+
throw new CliCommandError('AI Gateway music task completed without an audio URL', 'VALIDATION_ERROR', waitResult.data, waitResult.requestId || null);
|
|
234
|
+
}
|
|
235
|
+
return {
|
|
236
|
+
...waitResult,
|
|
237
|
+
data: withStableMusicAudioUrl(waitResult.data, audioUrl),
|
|
238
|
+
};
|
|
195
239
|
},
|
|
196
240
|
'music-get': async ({ client, payload }) => {
|
|
197
241
|
const id = getRequiredString(payload, 'id');
|
|
@@ -200,6 +244,14 @@ export const aiGatewayCommands = {
|
|
|
200
244
|
method: 'GET',
|
|
201
245
|
query: { id },
|
|
202
246
|
});
|
|
247
|
+
const status = extractStatus(result.data);
|
|
248
|
+
const audioUrl = extractMusicAudioUrl(result.data);
|
|
249
|
+
if (gatewaySuccessStatuses.has(status) && operation === 'query' && !audioUrl) {
|
|
250
|
+
throw new CliCommandError('AI Gateway music task completed without an audio URL', 'VALIDATION_ERROR', result.data, result.requestId);
|
|
251
|
+
}
|
|
252
|
+
if (audioUrl) {
|
|
253
|
+
return { data: withStableMusicAudioUrl(result.data, audioUrl), requestId: result.requestId };
|
|
254
|
+
}
|
|
203
255
|
return { data: result.data, requestId: result.requestId };
|
|
204
256
|
},
|
|
205
257
|
};
|