@inworld/cli 0.3.1 → 1.0.0-rc.2
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/dist/index.js +829 -305
- package/package.json +8 -2
- package/dist/index.js.map +0 -7
- package/dist/package.json +0 -49
- package/dist/proto/generated/portal/ai/inworld/language_codes/language_codes.pb.d.ts +0 -10
- package/dist/proto/generated/portal/ai/inworld/language_codes/language_codes.pb.d.ts.map +0 -1
- package/dist/proto/generated/portal/ai/inworld/language_codes/language_codes.pb.js +0 -16
- package/dist/proto/generated/portal/ai/inworld/language_codes/language_codes.pb.js.map +0 -1
- package/dist/proto/generated/portal/ai/inworld/studio/v1/errors.pb.d.ts +0 -13
- package/dist/proto/generated/portal/ai/inworld/studio/v1/errors.pb.d.ts.map +0 -1
- package/dist/proto/generated/portal/ai/inworld/studio/v1/errors.pb.js +0 -2
- package/dist/proto/generated/portal/ai/inworld/studio/v1/errors.pb.js.map +0 -1
- package/dist/proto/generated/portal/ai/inworld/studio/v1/operations.pb.d.ts +0 -7
- package/dist/proto/generated/portal/ai/inworld/studio/v1/operations.pb.d.ts.map +0 -1
- package/dist/proto/generated/portal/ai/inworld/studio/v1/operations.pb.js +0 -15
- package/dist/proto/generated/portal/ai/inworld/studio/v1/operations.pb.js.map +0 -1
- package/dist/proto/generated/portal/ai/inworld/studio/v1/remote/configuration/graph_configuration.pb.d.ts +0 -14
- package/dist/proto/generated/portal/ai/inworld/studio/v1/remote/configuration/graph_configuration.pb.d.ts.map +0 -1
- package/dist/proto/generated/portal/ai/inworld/studio/v1/remote/configuration/graph_configuration.pb.js +0 -7
- package/dist/proto/generated/portal/ai/inworld/studio/v1/remote/configuration/graph_configuration.pb.js.map +0 -1
- package/dist/proto/generated/portal/ai/inworld/studio/v1/remote/configuration/graphs.pb.d.ts +0 -116
- package/dist/proto/generated/portal/ai/inworld/studio/v1/remote/configuration/graphs.pb.d.ts.map +0 -1
- package/dist/proto/generated/portal/ai/inworld/studio/v1/remote/configuration/graphs.pb.js +0 -71
- package/dist/proto/generated/portal/ai/inworld/studio/v1/remote/configuration/graphs.pb.js.map +0 -1
- package/dist/proto/generated/portal/ai/inworld/studio/v1/remote/configuration/targeting.pb.d.ts +0 -14
- package/dist/proto/generated/portal/ai/inworld/studio/v1/remote/configuration/targeting.pb.d.ts.map +0 -1
- package/dist/proto/generated/portal/ai/inworld/studio/v1/remote/configuration/targeting.pb.js +0 -7
- package/dist/proto/generated/portal/ai/inworld/studio/v1/remote/configuration/targeting.pb.js.map +0 -1
- package/dist/proto/generated/portal/ai/inworld/studio/v1alpha/apikeys.pb.d.ts +0 -76
- package/dist/proto/generated/portal/ai/inworld/studio/v1alpha/apikeys.pb.d.ts.map +0 -1
- package/dist/proto/generated/portal/ai/inworld/studio/v1alpha/apikeys.pb.js +0 -40
- package/dist/proto/generated/portal/ai/inworld/studio/v1alpha/apikeys.pb.js.map +0 -1
- package/dist/proto/generated/portal/ai/inworld/studio/v1alpha/impression_event_data.pb.d.ts +0 -10
- package/dist/proto/generated/portal/ai/inworld/studio/v1alpha/impression_event_data.pb.d.ts.map +0 -1
- package/dist/proto/generated/portal/ai/inworld/studio/v1alpha/impression_event_data.pb.js +0 -7
- package/dist/proto/generated/portal/ai/inworld/studio/v1alpha/impression_event_data.pb.js.map +0 -1
- package/dist/proto/generated/portal/ai/inworld/studio/v1alpha/language_code.pb.d.ts +0 -7
- package/dist/proto/generated/portal/ai/inworld/studio/v1alpha/language_code.pb.d.ts.map +0 -1
- package/dist/proto/generated/portal/ai/inworld/studio/v1alpha/language_code.pb.js +0 -13
- package/dist/proto/generated/portal/ai/inworld/studio/v1alpha/language_code.pb.js.map +0 -1
- package/dist/proto/generated/portal/ai/inworld/studio/v1alpha/users.pb.d.ts +0 -115
- package/dist/proto/generated/portal/ai/inworld/studio/v1alpha/users.pb.d.ts.map +0 -1
- package/dist/proto/generated/portal/ai/inworld/studio/v1alpha/users.pb.js +0 -86
- package/dist/proto/generated/portal/ai/inworld/studio/v1alpha/users.pb.js.map +0 -1
- package/dist/proto/generated/portal/ai/inworld/studio/v1alpha/workspaces.pb.d.ts +0 -255
- package/dist/proto/generated/portal/ai/inworld/studio/v1alpha/workspaces.pb.d.ts.map +0 -1
- package/dist/proto/generated/portal/ai/inworld/studio/v1alpha/workspaces.pb.js +0 -88
- package/dist/proto/generated/portal/ai/inworld/studio/v1alpha/workspaces.pb.js.map +0 -1
- package/dist/proto/generated/portal/fetch.pb.d.ts +0 -26
- package/dist/proto/generated/portal/fetch.pb.d.ts.map +0 -1
- package/dist/proto/generated/portal/fetch.pb.js +0 -274
- package/dist/proto/generated/portal/fetch.pb.js.map +0 -1
- package/dist/src/auth/callback_server.d.ts +0 -41
- package/dist/src/auth/callback_server.d.ts.map +0 -1
- package/dist/src/auth/callback_server.js +0 -136
- package/dist/src/auth/callback_server.js.map +0 -1
- package/dist/src/auth/manager.d.ts +0 -97
- package/dist/src/auth/manager.d.ts.map +0 -1
- package/dist/src/auth/manager.js +0 -340
- package/dist/src/auth/manager.js.map +0 -1
- package/dist/src/auth/utils.d.ts +0 -45
- package/dist/src/auth/utils.d.ts.map +0 -1
- package/dist/src/auth/utils.js +0 -183
- package/dist/src/auth/utils.js.map +0 -1
- package/dist/src/commands/auth/disable_telemetry_command.d.ts +0 -3
- package/dist/src/commands/auth/disable_telemetry_command.d.ts.map +0 -1
- package/dist/src/commands/auth/enable_telemetry_command.d.ts +0 -3
- package/dist/src/commands/auth/enable_telemetry_command.d.ts.map +0 -1
- package/dist/src/commands/auth/login_ci_command.d.ts +0 -3
- package/dist/src/commands/auth/login_ci_command.d.ts.map +0 -1
- package/dist/src/commands/auth/login_ci_command.js +0 -41
- package/dist/src/commands/auth/login_ci_command.js.map +0 -1
- package/dist/src/commands/auth/login_command.d.ts +0 -4
- package/dist/src/commands/auth/login_command.d.ts.map +0 -1
- package/dist/src/commands/auth/login_command.js +0 -134
- package/dist/src/commands/auth/login_command.js.map +0 -1
- package/dist/src/commands/auth/logout_command.d.ts +0 -4
- package/dist/src/commands/auth/logout_command.d.ts.map +0 -1
- package/dist/src/commands/auth/logout_command.js +0 -54
- package/dist/src/commands/auth/logout_command.js.map +0 -1
- package/dist/src/commands/auth/print_access_token_command.d.ts +0 -3
- package/dist/src/commands/auth/print_access_token_command.d.ts.map +0 -1
- package/dist/src/commands/auth/print_access_token_command.js +0 -21
- package/dist/src/commands/auth/print_access_token_command.js.map +0 -1
- package/dist/src/commands/auth/print_api_key_command.d.ts +0 -3
- package/dist/src/commands/auth/print_api_key_command.d.ts.map +0 -1
- package/dist/src/commands/auth/print_api_key_command.js +0 -26
- package/dist/src/commands/auth/print_api_key_command.js.map +0 -1
- package/dist/src/commands/auth/status_command.d.ts +0 -4
- package/dist/src/commands/auth/status_command.d.ts.map +0 -1
- package/dist/src/commands/auth/status_command.js +0 -84
- package/dist/src/commands/auth/status_command.js.map +0 -1
- package/dist/src/commands/auth_command.d.ts +0 -3
- package/dist/src/commands/auth_command.d.ts.map +0 -1
- package/dist/src/commands/auth_command.js +0 -20
- package/dist/src/commands/auth_command.js.map +0 -1
- package/dist/src/commands/graph/graph_deploy_command.d.ts +0 -24
- package/dist/src/commands/graph/graph_deploy_command.d.ts.map +0 -1
- package/dist/src/commands/graph/graph_deploy_command.js +0 -191
- package/dist/src/commands/graph/graph_deploy_command.js.map +0 -1
- package/dist/src/commands/graph/graph_init_command.d.ts +0 -4
- package/dist/src/commands/graph/graph_init_command.d.ts.map +0 -1
- package/dist/src/commands/graph/graph_init_command.js +0 -376
- package/dist/src/commands/graph/graph_init_command.js.map +0 -1
- package/dist/src/commands/graph/graph_run_command.d.ts +0 -24
- package/dist/src/commands/graph/graph_run_command.d.ts.map +0 -1
- package/dist/src/commands/graph/graph_run_command.js +0 -50
- package/dist/src/commands/graph/graph_run_command.js.map +0 -1
- package/dist/src/commands/graph/graph_serve_command.d.ts +0 -4
- package/dist/src/commands/graph/graph_serve_command.d.ts.map +0 -1
- package/dist/src/commands/graph/graph_serve_command.js +0 -40
- package/dist/src/commands/graph/graph_serve_command.js.map +0 -1
- package/dist/src/commands/graph/graph_variant_command.d.ts +0 -3
- package/dist/src/commands/graph/graph_variant_command.d.ts.map +0 -1
- package/dist/src/commands/graph/graph_variant_command.js +0 -13
- package/dist/src/commands/graph/graph_variant_command.js.map +0 -1
- package/dist/src/commands/graph/graph_visualize_command.d.ts +0 -7
- package/dist/src/commands/graph/graph_visualize_command.d.ts.map +0 -1
- package/dist/src/commands/graph/graph_visualize_command.js +0 -35
- package/dist/src/commands/graph/graph_visualize_command.js.map +0 -1
- package/dist/src/commands/graph/variant/graph_variant_list_command.d.ts +0 -3
- package/dist/src/commands/graph/variant/graph_variant_list_command.d.ts.map +0 -1
- package/dist/src/commands/graph/variant/graph_variant_list_command.js +0 -25
- package/dist/src/commands/graph/variant/graph_variant_list_command.js.map +0 -1
- package/dist/src/commands/graph/variant/graph_variant_print_command.d.ts +0 -7
- package/dist/src/commands/graph/variant/graph_variant_print_command.d.ts.map +0 -1
- package/dist/src/commands/graph/variant/graph_variant_print_command.js +0 -45
- package/dist/src/commands/graph/variant/graph_variant_print_command.js.map +0 -1
- package/dist/src/commands/graph/variant/graph_variant_register_command.d.ts +0 -3
- package/dist/src/commands/graph/variant/graph_variant_register_command.d.ts.map +0 -1
- package/dist/src/commands/graph/variant/graph_variant_register_command.js +0 -45
- package/dist/src/commands/graph/variant/graph_variant_register_command.js.map +0 -1
- package/dist/src/commands/graph_command.d.ts +0 -3
- package/dist/src/commands/graph_command.d.ts.map +0 -1
- package/dist/src/commands/graph_command.js +0 -20
- package/dist/src/commands/graph_command.js.map +0 -1
- package/dist/src/commands/tts_commands.d.ts +0 -17
- package/dist/src/commands/tts_commands.d.ts.map +0 -1
- package/dist/src/commands/tts_commands.js +0 -568
- package/dist/src/commands/tts_commands.js.map +0 -1
- package/dist/src/commands/workspace_command.d.ts +0 -12
- package/dist/src/commands/workspace_command.d.ts.map +0 -1
- package/dist/src/commands/workspace_command.js +0 -33
- package/dist/src/commands/workspace_command.js.map +0 -1
- package/dist/src/constants.d.ts +0 -10
- package/dist/src/constants.d.ts.map +0 -1
- package/dist/src/constants.js +0 -30
- package/dist/src/constants.js.map +0 -1
- package/dist/src/grpc/core/InworldError.d.ts +0 -30
- package/dist/src/grpc/core/InworldError.d.ts.map +0 -1
- package/dist/src/grpc/core/InworldError.js +0 -46
- package/dist/src/grpc/core/InworldError.js.map +0 -1
- package/dist/src/grpc/core/statusCodes.d.ts +0 -122
- package/dist/src/grpc/core/statusCodes.d.ts.map +0 -1
- package/dist/src/grpc/core/statusCodes.js +0 -133
- package/dist/src/grpc/core/statusCodes.js.map +0 -1
- package/dist/src/index.d.ts +0 -2
- package/dist/src/index.d.ts.map +0 -1
- package/dist/src/services/analytics.d.ts +0 -45
- package/dist/src/services/analytics.d.ts.map +0 -1
- package/dist/src/services/deploy_service.d.ts +0 -4
- package/dist/src/services/deploy_service.d.ts.map +0 -1
- package/dist/src/services/deploy_service.js +0 -128
- package/dist/src/services/deploy_service.js.map +0 -1
- package/dist/src/services/graph_loader.d.ts +0 -7
- package/dist/src/services/graph_loader.d.ts.map +0 -1
- package/dist/src/services/graph_loader.js +0 -103
- package/dist/src/services/graph_loader.js.map +0 -1
- package/dist/src/services/graph_variant_service.d.ts +0 -12
- package/dist/src/services/graph_variant_service.d.ts.map +0 -1
- package/dist/src/services/graph_variant_service.js +0 -66
- package/dist/src/services/graph_variant_service.js.map +0 -1
- package/dist/src/services/tts_service.d.ts +0 -273
- package/dist/src/services/tts_service.d.ts.map +0 -1
- package/dist/src/services/tts_service.js +0 -299
- package/dist/src/services/tts_service.js.map +0 -1
- package/dist/src/services/update_checker.d.ts +0 -37
- package/dist/src/services/update_checker.d.ts.map +0 -1
- package/dist/src/services/workspace_service.d.ts +0 -47
- package/dist/src/services/workspace_service.d.ts.map +0 -1
- package/dist/src/services/workspace_service.js +0 -222
- package/dist/src/services/workspace_service.js.map +0 -1
- package/dist/src/templates/llm_tts/README.md +0 -161
- package/dist/src/templates/llm_tts/graph.d.ts +0 -2
- package/dist/src/templates/llm_tts/graph.d.ts.map +0 -1
- package/dist/src/templates/llm_tts/graph.ts +0 -30
- package/dist/src/templates/llm_tts/metadata.json +0 -41
- package/dist/src/utils/array.d.ts +0 -2
- package/dist/src/utils/array.d.ts.map +0 -1
- package/dist/src/utils/array.js +0 -4
- package/dist/src/utils/array.js.map +0 -1
- package/dist/src/utils/confirm.d.ts +0 -62
- package/dist/src/utils/confirm.d.ts.map +0 -1
- package/dist/src/utils/confirm.js +0 -90
- package/dist/src/utils/confirm.js.map +0 -1
- package/dist/src/utils/long_running_operations.d.ts +0 -38
- package/dist/src/utils/long_running_operations.d.ts.map +0 -1
- package/dist/src/utils/long_running_operations.js +0 -62
- package/dist/src/utils/long_running_operations.js.map +0 -1
- package/dist/src/utils/resource_name_helper.d.ts +0 -12
- package/dist/src/utils/resource_name_helper.d.ts.map +0 -1
- package/dist/src/utils/resource_name_helper.js +0 -29
- package/dist/src/utils/resource_name_helper.js.map +0 -1
- package/dist/src/utils/selector.d.ts +0 -62
- package/dist/src/utils/selector.d.ts.map +0 -1
- package/dist/src/utils/selector.js +0 -77
- package/dist/src/utils/selector.js.map +0 -1
- package/dist/src/utils/spinner.d.ts +0 -75
- package/dist/src/utils/spinner.d.ts.map +0 -1
- package/dist/src/utils/spinner.js +0 -178
- package/dist/src/utils/spinner.js.map +0 -1
- package/dist/src/utils/ui.d.ts +0 -27
- package/dist/src/utils/ui.d.ts.map +0 -1
- package/dist/src/utils/ui.js +0 -83
- package/dist/src/utils/ui.js.map +0 -1
- package/dist/templates/llm_tts/README.md +0 -155
- package/dist/templates/llm_tts/graph.ts +0 -29
- package/dist/templates/llm_tts/metadata.json +0 -41
package/dist/index.js
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
|
|
4
4
|
// src/index.ts
|
|
5
|
-
import
|
|
6
|
-
import { Command as
|
|
5
|
+
import chalk9 from "chalk";
|
|
6
|
+
import { Command as Command26 } from "commander";
|
|
7
7
|
|
|
8
8
|
// src/commands/auth/login_command.ts
|
|
9
9
|
import { exec } from "child_process";
|
|
@@ -17,20 +17,25 @@ import * as http from "http";
|
|
|
17
17
|
// package.json
|
|
18
18
|
var package_default = {
|
|
19
19
|
name: "@inworld/cli",
|
|
20
|
-
version: "0.
|
|
20
|
+
version: "1.0.0-rc.1",
|
|
21
21
|
type: "module",
|
|
22
22
|
main: "dist/index.js",
|
|
23
23
|
bin: {
|
|
24
24
|
inworld: "dist/index.js"
|
|
25
25
|
},
|
|
26
26
|
scripts: {
|
|
27
|
-
|
|
27
|
+
postversion: "npm install && git add ../../package-lock.json",
|
|
28
|
+
"copy:release-it-config": "node ../../scripts/copy-release-it-config.js",
|
|
29
|
+
build: "node esbuild.config.js && npm run copy:release-it-config",
|
|
28
30
|
"build:tsc": "tsc --project tsconfig.json",
|
|
29
31
|
"build:types": "tsc --emitDeclarationOnly",
|
|
30
32
|
"build:all": "npm run build && npm run build:types",
|
|
31
33
|
start: "node dist/index.js",
|
|
32
34
|
dev: "tsx src/index.ts"
|
|
33
35
|
},
|
|
36
|
+
engines: {
|
|
37
|
+
node: ">=20.0.0"
|
|
38
|
+
},
|
|
34
39
|
files: [
|
|
35
40
|
"dist/**/*"
|
|
36
41
|
],
|
|
@@ -57,6 +62,7 @@ var package_default = {
|
|
|
57
62
|
"jwt-decode": "^4.0.0",
|
|
58
63
|
mixpanel: "^0.18.1",
|
|
59
64
|
ora: "^8.2.0",
|
|
65
|
+
"play-sound": "^1.1.6",
|
|
60
66
|
semver: "^7.6.3",
|
|
61
67
|
tsx: "^4.20.5",
|
|
62
68
|
typescript: "^5.8.3"
|
|
@@ -108,7 +114,7 @@ var resolveTemplatesMetadataUrl = () => {
|
|
|
108
114
|
}
|
|
109
115
|
};
|
|
110
116
|
var TEMPLATES_METADATA_URL = resolveTemplatesMetadataUrl();
|
|
111
|
-
var RUNTIME_VERSION = "0.
|
|
117
|
+
var RUNTIME_VERSION = "0.9.0-rc.17";
|
|
112
118
|
var CLI_VERSION = package_default.version;
|
|
113
119
|
|
|
114
120
|
// src/utils/ui.ts
|
|
@@ -196,7 +202,7 @@ async function createCallbackServer(options = {}) {
|
|
|
196
202
|
allowedOrigins = ["http://localhost:3001", "https://cli.inworld.ai"],
|
|
197
203
|
firebaseApiKey = FIREBASE_API_KEY
|
|
198
204
|
} = options;
|
|
199
|
-
return new Promise((
|
|
205
|
+
return new Promise((resolve3, reject) => {
|
|
200
206
|
const httpServer = http.createServer(
|
|
201
207
|
{
|
|
202
208
|
keepAlive: false
|
|
@@ -249,7 +255,7 @@ async function createCallbackServer(options = {}) {
|
|
|
249
255
|
if (tokenResponse?.id_token) {
|
|
250
256
|
res.writeHead(200, { "Content-Type": "application/json" });
|
|
251
257
|
res.end(JSON.stringify({ success: true }));
|
|
252
|
-
|
|
258
|
+
resolve3({
|
|
253
259
|
server: httpServer,
|
|
254
260
|
token: tokenResponse.id_token,
|
|
255
261
|
refreshToken,
|
|
@@ -298,12 +304,12 @@ async function createCallbackServer(options = {}) {
|
|
|
298
304
|
});
|
|
299
305
|
}
|
|
300
306
|
function stopCallbackServer(server) {
|
|
301
|
-
return new Promise((
|
|
307
|
+
return new Promise((resolve3, reject) => {
|
|
302
308
|
server.close((err) => {
|
|
303
309
|
if (err) {
|
|
304
310
|
reject(err);
|
|
305
311
|
} else {
|
|
306
|
-
|
|
312
|
+
resolve3();
|
|
307
313
|
}
|
|
308
314
|
});
|
|
309
315
|
});
|
|
@@ -933,7 +939,7 @@ var checkLRO = async ({
|
|
|
933
939
|
pollOptions?.errorCallback?.(operationName, error);
|
|
934
940
|
throw error;
|
|
935
941
|
}
|
|
936
|
-
await new Promise((
|
|
942
|
+
await new Promise((resolve3) => setTimeout(resolve3, checkTimeout));
|
|
937
943
|
}
|
|
938
944
|
throw new Error(
|
|
939
945
|
`Operation timeout. Max number of checks reached ${checkLimit}`
|
|
@@ -1042,9 +1048,9 @@ async function retryableAuthenticatedInworldRequest(pb, req, options = {
|
|
|
1042
1048
|
minTimeout * Math.pow(backoffFactor, currentAttempt),
|
|
1043
1049
|
maxTimeout
|
|
1044
1050
|
);
|
|
1045
|
-
return new Promise((
|
|
1051
|
+
return new Promise((resolve3) => {
|
|
1046
1052
|
setTimeout(() => {
|
|
1047
|
-
|
|
1053
|
+
resolve3(retryRequest(currentAttempt + 1));
|
|
1048
1054
|
}, timeout);
|
|
1049
1055
|
});
|
|
1050
1056
|
} else {
|
|
@@ -1217,23 +1223,23 @@ async function confirm(options) {
|
|
|
1217
1223
|
input: process.stdin,
|
|
1218
1224
|
output: process.stdout
|
|
1219
1225
|
});
|
|
1220
|
-
return new Promise((
|
|
1226
|
+
return new Promise((resolve3) => {
|
|
1221
1227
|
rl.question(message, (answer) => {
|
|
1222
1228
|
rl.close();
|
|
1223
1229
|
const trimmedAnswer = answer.trim().toLowerCase();
|
|
1224
1230
|
if (trimmedAnswer === "y" || trimmedAnswer === "yes") {
|
|
1225
|
-
|
|
1231
|
+
resolve3(true);
|
|
1226
1232
|
return;
|
|
1227
1233
|
}
|
|
1228
1234
|
if (trimmedAnswer === "n" || trimmedAnswer === "no") {
|
|
1229
|
-
|
|
1235
|
+
resolve3(false);
|
|
1230
1236
|
return;
|
|
1231
1237
|
}
|
|
1232
1238
|
if (trimmedAnswer === "") {
|
|
1233
|
-
|
|
1239
|
+
resolve3(defaultValue);
|
|
1234
1240
|
return;
|
|
1235
1241
|
}
|
|
1236
|
-
|
|
1242
|
+
resolve3(false);
|
|
1237
1243
|
});
|
|
1238
1244
|
});
|
|
1239
1245
|
}
|
|
@@ -1255,6 +1261,9 @@ var getGraphVariantResourceName = (workspaceId, graphId, variantId) => {
|
|
|
1255
1261
|
var getWorkspaceResourceName = (workspaceId) => {
|
|
1256
1262
|
return `workspaces/${workspaceId}`;
|
|
1257
1263
|
};
|
|
1264
|
+
var ensureWorkspaceResourceName = (workspace) => {
|
|
1265
|
+
return workspace.startsWith("workspaces/") ? workspace : `workspaces/${workspace}`;
|
|
1266
|
+
};
|
|
1258
1267
|
|
|
1259
1268
|
// src/utils/selector.ts
|
|
1260
1269
|
import * as readline2 from "readline";
|
|
@@ -1280,16 +1289,13 @@ async function selectItem(options) {
|
|
|
1280
1289
|
printHeader(title);
|
|
1281
1290
|
items.forEach((item, idx) => {
|
|
1282
1291
|
const displayName = getDisplayName(item);
|
|
1283
|
-
|
|
1284
|
-
printListItem(
|
|
1285
|
-
`${idx + 1}. ${bright(displayName)} (ID: ${cyan(identifier)})`
|
|
1286
|
-
);
|
|
1292
|
+
printListItem(`${idx + 1}. ${bright(displayName)}`);
|
|
1287
1293
|
});
|
|
1288
1294
|
const rl = readline2.createInterface({
|
|
1289
1295
|
input: process.stdin,
|
|
1290
1296
|
output: process.stdout
|
|
1291
1297
|
});
|
|
1292
|
-
const question = (query) => new Promise((
|
|
1298
|
+
const question = (query) => new Promise((resolve3) => rl.question(query, resolve3));
|
|
1293
1299
|
let selectedItem = null;
|
|
1294
1300
|
try {
|
|
1295
1301
|
while (!selectedItem) {
|
|
@@ -1324,6 +1330,35 @@ async function selectItemOrExit(options) {
|
|
|
1324
1330
|
}
|
|
1325
1331
|
|
|
1326
1332
|
// src/services/workspace_service.ts
|
|
1333
|
+
function formatApiKeyScopes(scopes) {
|
|
1334
|
+
if (!scopes?.length) return "";
|
|
1335
|
+
const scopeMap = {
|
|
1336
|
+
"api.dsgnt.voices": "voices",
|
|
1337
|
+
"api.dsgnt.router": "router"
|
|
1338
|
+
};
|
|
1339
|
+
const accessMap = {
|
|
1340
|
+
r: "read",
|
|
1341
|
+
w: "write",
|
|
1342
|
+
rw: "read/write"
|
|
1343
|
+
};
|
|
1344
|
+
const labels = [];
|
|
1345
|
+
let hasVoices = false;
|
|
1346
|
+
let hasRouter = false;
|
|
1347
|
+
for (const scope of scopes) {
|
|
1348
|
+
const match = scope.match(/^([^:]+)::(\w+)/);
|
|
1349
|
+
if (!match) continue;
|
|
1350
|
+
const [, prefix, access] = match;
|
|
1351
|
+
const name = scopeMap[prefix];
|
|
1352
|
+
if (!name) continue;
|
|
1353
|
+
if (name === "voices") hasVoices = true;
|
|
1354
|
+
if (name === "router") hasRouter = true;
|
|
1355
|
+
const accessLabel = accessMap[access] || access;
|
|
1356
|
+
labels.push(`${name}:${accessLabel}`);
|
|
1357
|
+
}
|
|
1358
|
+
if (!hasVoices) labels.push("voices:read");
|
|
1359
|
+
if (!hasRouter) labels.push("router:read");
|
|
1360
|
+
return `[${labels.join(", ")}]`;
|
|
1361
|
+
}
|
|
1327
1362
|
var WorkspaceService = class {
|
|
1328
1363
|
/**
|
|
1329
1364
|
* Prompts user to select a workspace from available workspaces
|
|
@@ -1342,7 +1377,7 @@ var WorkspaceService = class {
|
|
|
1342
1377
|
items: workspaces,
|
|
1343
1378
|
getDisplayName: (ws) => ws.displayName || ws.name?.split("/").pop() || "unknown",
|
|
1344
1379
|
getIdentifier: (ws) => ws.name?.split("/").pop() || "unknown",
|
|
1345
|
-
prompt: "Enter the number
|
|
1380
|
+
prompt: "Enter the number of the workspace to activate:",
|
|
1346
1381
|
title: "Available workspaces:",
|
|
1347
1382
|
forceFirst,
|
|
1348
1383
|
noItemsMessage: "No workspaces found.",
|
|
@@ -1360,16 +1395,18 @@ var WorkspaceService = class {
|
|
|
1360
1395
|
return selectItemOrExit({
|
|
1361
1396
|
items: apiKeys,
|
|
1362
1397
|
getDisplayName: (apiKey) => {
|
|
1363
|
-
const
|
|
1398
|
+
const displayName = apiKey.displayName;
|
|
1399
|
+
const label = displayName || trimBase64Key(apiKey.key || "unknown");
|
|
1364
1400
|
const createdAt = apiKey.createTime ? new Date(apiKey.createTime).toLocaleDateString() : "unknown date";
|
|
1365
|
-
|
|
1401
|
+
const permissions = formatApiKeyScopes(apiKey.scopes);
|
|
1402
|
+
return `${label} (created: ${createdAt})${permissions ? ` ${permissions}` : ""}`;
|
|
1366
1403
|
},
|
|
1367
1404
|
getIdentifier: (apiKey) => apiKey.name?.split("/").pop() || "unknown",
|
|
1368
|
-
prompt: "Enter the number
|
|
1405
|
+
prompt: "Enter the number of the API key to use:",
|
|
1369
1406
|
title: "Available API keys:",
|
|
1370
1407
|
forceFirst,
|
|
1371
1408
|
noItemsMessage: "No API keys found.",
|
|
1372
|
-
invalidSelectionMessage: "Invalid selection. Please enter a valid number
|
|
1409
|
+
invalidSelectionMessage: "Invalid selection. Please enter a valid number."
|
|
1373
1410
|
});
|
|
1374
1411
|
}
|
|
1375
1412
|
static returnBase64 = (key, secret) => {
|
|
@@ -1447,8 +1484,9 @@ Selecting API key: ${chalk2.whiteBright(trimBase64Key(base64Key))}`
|
|
|
1447
1484
|
);
|
|
1448
1485
|
return;
|
|
1449
1486
|
}
|
|
1487
|
+
const parent = ensureWorkspaceResourceName(credentials.workspace);
|
|
1450
1488
|
const response = await authenticatedInworldRequest(ApiKeys.ListApiKeys, {
|
|
1451
|
-
parent
|
|
1489
|
+
parent,
|
|
1452
1490
|
pageSize: WORKSPACES_LIST_SIZE
|
|
1453
1491
|
});
|
|
1454
1492
|
const apiKeys = response?.apiKeys || [];
|
|
@@ -1459,11 +1497,13 @@ Selecting API key: ${chalk2.whiteBright(trimBase64Key(base64Key))}`
|
|
|
1459
1497
|
console.log();
|
|
1460
1498
|
printHeader(`API keys in workspace ${credentials.workspace}:`);
|
|
1461
1499
|
apiKeys.forEach((apiKey, idx) => {
|
|
1462
|
-
const
|
|
1500
|
+
const displayName = apiKey.displayName;
|
|
1501
|
+
const label = displayName || trimBase64Key(apiKey.key || "unknown");
|
|
1463
1502
|
const createdAt = apiKey.createTime ? new Date(apiKey.createTime).toLocaleDateString() : "unknown date";
|
|
1464
1503
|
const state = apiKey.state || "unknown";
|
|
1504
|
+
const permissions = formatApiKeyScopes(apiKey.scopes);
|
|
1465
1505
|
printListItem(
|
|
1466
|
-
`${idx + 1}. ${
|
|
1506
|
+
`${idx + 1}. ${label} (created: ${createdAt}, state: ${state})${permissions ? ` ${permissions}` : ""}`
|
|
1467
1507
|
);
|
|
1468
1508
|
});
|
|
1469
1509
|
}
|
|
@@ -1478,8 +1518,9 @@ Selecting API key: ${chalk2.whiteBright(trimBase64Key(base64Key))}`
|
|
|
1478
1518
|
);
|
|
1479
1519
|
return;
|
|
1480
1520
|
}
|
|
1521
|
+
const parent = ensureWorkspaceResourceName(credentials.workspace);
|
|
1481
1522
|
const response = await authenticatedInworldRequest(ApiKeys.ListApiKeys, {
|
|
1482
|
-
parent
|
|
1523
|
+
parent,
|
|
1483
1524
|
pageSize: WORKSPACES_LIST_SIZE
|
|
1484
1525
|
});
|
|
1485
1526
|
const apiKeys = response?.apiKeys || [];
|
|
@@ -1530,10 +1571,11 @@ Selecting API key: ${chalk2.whiteBright(trimBase64Key(base64Key))}`
|
|
|
1530
1571
|
return;
|
|
1531
1572
|
}
|
|
1532
1573
|
print("Generating new API key...");
|
|
1574
|
+
const parent = ensureWorkspaceResourceName(credentials.workspace);
|
|
1533
1575
|
const generateApiKeyResponse = await authenticatedInworldRequest(
|
|
1534
1576
|
ApiKeys.GenerateApiKey,
|
|
1535
1577
|
{
|
|
1536
|
-
parent
|
|
1578
|
+
parent
|
|
1537
1579
|
}
|
|
1538
1580
|
);
|
|
1539
1581
|
if (!generateApiKeyResponse) {
|
|
@@ -1558,6 +1600,56 @@ Selecting API key: ${chalk2.whiteBright(trimBase64Key(base64Key))}`
|
|
|
1558
1600
|
printListItem(`Key: ${generateApiKeyResponse.key}`);
|
|
1559
1601
|
printListItem(`Base64: ${base64Key}`);
|
|
1560
1602
|
}
|
|
1603
|
+
/**
|
|
1604
|
+
* Creates a new API key with predefined scope preset and activates it.
|
|
1605
|
+
* @param mode 'read' for read-only, 'write' for read/write voices & router
|
|
1606
|
+
* @param displayName Optional display name for the key
|
|
1607
|
+
*/
|
|
1608
|
+
static async createApiKey(mode, displayName) {
|
|
1609
|
+
const credentials = await authManager.getCredentials();
|
|
1610
|
+
if (!credentials?.workspace) {
|
|
1611
|
+
printError(
|
|
1612
|
+
'No workspace activated. Please run "inworld workspace activate" first.'
|
|
1613
|
+
);
|
|
1614
|
+
return;
|
|
1615
|
+
}
|
|
1616
|
+
const parent = ensureWorkspaceResourceName(credentials.workspace);
|
|
1617
|
+
const baseScopes = ["api.rt::x", "api.ml::x", "api.ops::x"];
|
|
1618
|
+
const scopes = mode === "write" ? [...baseScopes, "api.dsgnt.voices::rw", "api.dsgnt.router::rw"] : [...baseScopes, "api.dsgnt.voices::r", "api.dsgnt.router::r"];
|
|
1619
|
+
const label = mode === "write" ? "read/write" : "read-only";
|
|
1620
|
+
print(`Creating ${label} API key...`);
|
|
1621
|
+
const generateApiKeyResponse = await authenticatedInworldRequest(
|
|
1622
|
+
ApiKeys.GenerateApiKey,
|
|
1623
|
+
{
|
|
1624
|
+
parent,
|
|
1625
|
+
scopes,
|
|
1626
|
+
displayName,
|
|
1627
|
+
authTypes: [
|
|
1628
|
+
"API_KEY_AUTHORIZATION_TYPE_BASIC" /* API_KEY_AUTHORIZATION_TYPE_BASIC */,
|
|
1629
|
+
"API_KEY_AUTHORIZATION_TYPE_JWT" /* API_KEY_AUTHORIZATION_TYPE_JWT */
|
|
1630
|
+
]
|
|
1631
|
+
}
|
|
1632
|
+
);
|
|
1633
|
+
if (!generateApiKeyResponse) {
|
|
1634
|
+
printError("Failed to generate API key.");
|
|
1635
|
+
return;
|
|
1636
|
+
}
|
|
1637
|
+
const base64Key = this.returnBase64(
|
|
1638
|
+
generateApiKeyResponse.key,
|
|
1639
|
+
generateApiKeyResponse.secret
|
|
1640
|
+
);
|
|
1641
|
+
const workspaceId = credentials.workspace.replace(/^workspaces\//, "");
|
|
1642
|
+
await authManager.updateWorkspaceAndApiKey(workspaceId, base64Key);
|
|
1643
|
+
const permissions = formatApiKeyScopes(generateApiKeyResponse.scopes);
|
|
1644
|
+
success("\nAPI key created and activated.");
|
|
1645
|
+
console.log();
|
|
1646
|
+
printHeader("API Key details:");
|
|
1647
|
+
if (displayName) {
|
|
1648
|
+
printListItem(`Display Name: ${displayName}`);
|
|
1649
|
+
}
|
|
1650
|
+
printListItem(`Permissions: ${permissions || label}`);
|
|
1651
|
+
printListItem(`Key: ${trimBase64Key(base64Key)}`);
|
|
1652
|
+
}
|
|
1561
1653
|
};
|
|
1562
1654
|
|
|
1563
1655
|
// src/commands/auth/login_command.ts
|
|
@@ -1605,9 +1697,9 @@ var loginAction = async (options) => {
|
|
|
1605
1697
|
input: process.stdin,
|
|
1606
1698
|
output: process.stdout
|
|
1607
1699
|
});
|
|
1608
|
-
const enterPromise = new Promise((
|
|
1700
|
+
const enterPromise = new Promise((resolve3) => {
|
|
1609
1701
|
readlineInterface.question("Press Enter to open your browser...", () => {
|
|
1610
|
-
|
|
1702
|
+
resolve3();
|
|
1611
1703
|
});
|
|
1612
1704
|
});
|
|
1613
1705
|
const result = await Promise.race([
|
|
@@ -1919,15 +2011,15 @@ var Analytics = class _Analytics {
|
|
|
1919
2011
|
* Should be called before the CLI exits
|
|
1920
2012
|
*/
|
|
1921
2013
|
flush() {
|
|
1922
|
-
return new Promise((
|
|
2014
|
+
return new Promise((resolve3) => {
|
|
1923
2015
|
if (!this.initialized || !this.mixpanel) {
|
|
1924
|
-
|
|
2016
|
+
resolve3();
|
|
1925
2017
|
return;
|
|
1926
2018
|
}
|
|
1927
|
-
const timeout = setTimeout(() =>
|
|
2019
|
+
const timeout = setTimeout(() => resolve3(), 500);
|
|
1928
2020
|
setTimeout(() => {
|
|
1929
2021
|
clearTimeout(timeout);
|
|
1930
|
-
|
|
2022
|
+
resolve3();
|
|
1931
2023
|
}, 100);
|
|
1932
2024
|
});
|
|
1933
2025
|
}
|
|
@@ -2570,7 +2662,7 @@ var deployAction = async (file, options) => {
|
|
|
2570
2662
|
zlib: { level: 9 }
|
|
2571
2663
|
// Maximum compression
|
|
2572
2664
|
});
|
|
2573
|
-
const archiveComplete = new Promise((
|
|
2665
|
+
const archiveComplete = new Promise((resolve3, reject) => {
|
|
2574
2666
|
output.on("close", () => {
|
|
2575
2667
|
if (options.packageOnly) {
|
|
2576
2668
|
let packageName;
|
|
@@ -2590,7 +2682,7 @@ var deployAction = async (file, options) => {
|
|
|
2590
2682
|
print("Deployment should take around 5 minutes, please be patient.");
|
|
2591
2683
|
print("Deploying...");
|
|
2592
2684
|
console.log();
|
|
2593
|
-
|
|
2685
|
+
resolve3();
|
|
2594
2686
|
});
|
|
2595
2687
|
archive.on("error", (err) => {
|
|
2596
2688
|
reject(err);
|
|
@@ -2800,7 +2892,7 @@ async function downloadTemplateFromGitHub(templateName, targetPath, repository,
|
|
|
2800
2892
|
const zipPath = path3.join(tempDir, `${templateName}.zip`);
|
|
2801
2893
|
const archiveUrl = `https://api.github.com/repos/${owner}/${repo}/zipball/${repoBranch}`;
|
|
2802
2894
|
spinner.text = `Downloading repository archive from ${owner}/${repo}...`;
|
|
2803
|
-
await new Promise((
|
|
2895
|
+
await new Promise((resolve3, reject) => {
|
|
2804
2896
|
https.get(
|
|
2805
2897
|
archiveUrl,
|
|
2806
2898
|
{ headers: { "User-Agent": "inworld-cli" } },
|
|
@@ -2820,14 +2912,14 @@ async function downloadTemplateFromGitHub(templateName, targetPath, repository,
|
|
|
2820
2912
|
}
|
|
2821
2913
|
const fileStream = createWriteStream(zipPath);
|
|
2822
2914
|
redirectRes.pipe(fileStream);
|
|
2823
|
-
fileStream.on("finish",
|
|
2915
|
+
fileStream.on("finish", resolve3);
|
|
2824
2916
|
fileStream.on("error", reject);
|
|
2825
2917
|
}
|
|
2826
2918
|
).on("error", reject);
|
|
2827
2919
|
} else if (res.statusCode === 200) {
|
|
2828
2920
|
const fileStream = createWriteStream(zipPath);
|
|
2829
2921
|
res.pipe(fileStream);
|
|
2830
|
-
fileStream.on("finish",
|
|
2922
|
+
fileStream.on("finish", resolve3);
|
|
2831
2923
|
fileStream.on("error", reject);
|
|
2832
2924
|
} else {
|
|
2833
2925
|
reject(new Error(`Failed to download: ${res.statusCode}`));
|
|
@@ -2942,7 +3034,9 @@ async function getAvailableTemplatesWithMetadata() {
|
|
|
2942
3034
|
} catch (error) {
|
|
2943
3035
|
throw error;
|
|
2944
3036
|
}
|
|
2945
|
-
return templates.filter(
|
|
3037
|
+
return templates.filter(
|
|
3038
|
+
(template) => template.metadata.id === "llm-to-tts-node"
|
|
3039
|
+
);
|
|
2946
3040
|
}
|
|
2947
3041
|
function copyTemplateDirectory(src, dest) {
|
|
2948
3042
|
copyDirectory(src, dest);
|
|
@@ -2963,7 +3057,7 @@ Would you like to install dependencies now using npm? (y/n) `,
|
|
|
2963
3057
|
}
|
|
2964
3058
|
async function runPackageInstall(directory) {
|
|
2965
3059
|
const { spawn } = await import("child_process");
|
|
2966
|
-
return new Promise((
|
|
3060
|
+
return new Promise((resolve3, reject) => {
|
|
2967
3061
|
print(`Installing dependencies using npm...`);
|
|
2968
3062
|
const install = spawn("npm", ["install"], {
|
|
2969
3063
|
cwd: directory,
|
|
@@ -2973,7 +3067,7 @@ async function runPackageInstall(directory) {
|
|
|
2973
3067
|
install.on("close", (code) => {
|
|
2974
3068
|
if (code === 0) {
|
|
2975
3069
|
success("Dependencies installed successfully!");
|
|
2976
|
-
|
|
3070
|
+
resolve3();
|
|
2977
3071
|
} else {
|
|
2978
3072
|
printError(`\u274C npm install failed with code ${code}`);
|
|
2979
3073
|
reject(new Error(`npm install failed with code ${code}`));
|
|
@@ -3070,7 +3164,7 @@ Note: Templates are downloaded from GitHub repositories as complete applications
|
|
|
3070
3164
|
let selectedTemplateId;
|
|
3071
3165
|
const templates = await fetchTemplatesMetadata();
|
|
3072
3166
|
if (!options.template) {
|
|
3073
|
-
printBright("\u{1F680} Welcome to Inworld Template Initializer!");
|
|
3167
|
+
printBright("\u{1F680} Welcome to the Inworld Template Initializer!");
|
|
3074
3168
|
if (templates.length === 0) {
|
|
3075
3169
|
printError("\u274C No templates found.");
|
|
3076
3170
|
print(`
|
|
@@ -3083,7 +3177,7 @@ Please ensure the templates metadata is accessible.`);
|
|
|
3083
3177
|
return `${bold(cyan(template2.name))} - ${template2.description}`;
|
|
3084
3178
|
},
|
|
3085
3179
|
getIdentifier: (template2) => template2.id,
|
|
3086
|
-
prompt: "Select a template (enter number or name)",
|
|
3180
|
+
prompt: "Select a template (enter number or name):",
|
|
3087
3181
|
title: "\u{1F4CB} Available Templates:",
|
|
3088
3182
|
exitOnFailure: true
|
|
3089
3183
|
});
|
|
@@ -3167,13 +3261,13 @@ Please ensure the template exists in the templates metadata and the repository i
|
|
|
3167
3261
|
input: process.stdin,
|
|
3168
3262
|
output: process.stdout
|
|
3169
3263
|
});
|
|
3170
|
-
const askProjectName = () => new Promise((
|
|
3264
|
+
const askProjectName = () => new Promise((resolve3) => {
|
|
3171
3265
|
rl.question(
|
|
3172
3266
|
`
|
|
3173
3267
|
Project name (${selectedTemplate.metadata.id || selectedTemplate.metadata.name}): `,
|
|
3174
3268
|
(answer) => {
|
|
3175
3269
|
rl.close();
|
|
3176
|
-
|
|
3270
|
+
resolve3(
|
|
3177
3271
|
answer.trim() || selectedTemplate.metadata.id || selectedTemplate.metadata.name
|
|
3178
3272
|
);
|
|
3179
3273
|
}
|
|
@@ -3278,12 +3372,13 @@ var runAction = async (file, request) => {
|
|
|
3278
3372
|
console.error("Error parsing request:", error);
|
|
3279
3373
|
process.exit(1);
|
|
3280
3374
|
}
|
|
3281
|
-
const
|
|
3375
|
+
const { processGraphRequest } = await import("@inworld/graph-server");
|
|
3376
|
+
const results = await processGraphRequest(requestJson, graph);
|
|
3282
3377
|
for await (const result of results) {
|
|
3283
3378
|
console.log(result);
|
|
3284
3379
|
}
|
|
3285
3380
|
} catch (error) {
|
|
3286
|
-
console.error("Error
|
|
3381
|
+
console.error("Error running graph:", error);
|
|
3287
3382
|
}
|
|
3288
3383
|
};
|
|
3289
3384
|
var makeRunCommand = (description) => {
|
|
@@ -3325,12 +3420,12 @@ var serveAction = async (file, options) => {
|
|
|
3325
3420
|
printError('Transport must be either "http" or "grpc"');
|
|
3326
3421
|
process.exit(1);
|
|
3327
3422
|
}
|
|
3328
|
-
await graph
|
|
3329
|
-
|
|
3330
|
-
port,
|
|
3331
|
-
|
|
3332
|
-
|
|
3333
|
-
}
|
|
3423
|
+
const { startHttpServer, startGrpcServer } = await import("@inworld/graph-server");
|
|
3424
|
+
if (options.transport === "grpc") {
|
|
3425
|
+
await startGrpcServer(host, port, graph);
|
|
3426
|
+
} else {
|
|
3427
|
+
await startHttpServer(host, port, graph, options.swagger);
|
|
3428
|
+
}
|
|
3334
3429
|
} catch (error) {
|
|
3335
3430
|
printError("Error starting server:");
|
|
3336
3431
|
console.error(error);
|
|
@@ -3549,31 +3644,37 @@ var graphCommand = new Command19("graph").description("Manage Inworld graph proj
|
|
|
3549
3644
|
});
|
|
3550
3645
|
|
|
3551
3646
|
// src/commands/tts_commands.ts
|
|
3647
|
+
import { Command as Command24 } from "commander";
|
|
3648
|
+
|
|
3649
|
+
// src/commands/tts/tts_clone_command.ts
|
|
3552
3650
|
import chalk4 from "chalk";
|
|
3553
3651
|
import { Command as Command20 } from "commander";
|
|
3554
|
-
import {
|
|
3652
|
+
import { readFile } from "fs/promises";
|
|
3555
3653
|
import { resolve } from "path";
|
|
3556
3654
|
|
|
3557
3655
|
// src/services/tts_service.ts
|
|
3656
|
+
var LEGACY_MODELS = /* @__PURE__ */ new Set([
|
|
3657
|
+
"inworld-tts-1" /* INWORLD_TTS_1 */,
|
|
3658
|
+
"inworld-tts-1-max" /* INWORLD_TTS_1_MAX */
|
|
3659
|
+
]);
|
|
3558
3660
|
var TTSService = class {
|
|
3559
3661
|
apiKey = null;
|
|
3560
|
-
/**
|
|
3561
|
-
* Ensures the API key is available
|
|
3562
|
-
* @private
|
|
3563
|
-
*/
|
|
3564
3662
|
async ensureApiKey() {
|
|
3565
3663
|
if (!this.apiKey) {
|
|
3566
3664
|
this.apiKey = await requireApiKey();
|
|
3567
3665
|
}
|
|
3568
3666
|
return this.apiKey;
|
|
3569
3667
|
}
|
|
3668
|
+
/** Builds the API base URL from the platform URL */
|
|
3669
|
+
get apiBaseUrl() {
|
|
3670
|
+
return PLATFORM_URL.replace("platform", "api");
|
|
3671
|
+
}
|
|
3570
3672
|
/**
|
|
3571
3673
|
* Makes an authenticated request to the Inworld API
|
|
3572
|
-
* @private
|
|
3573
3674
|
*/
|
|
3574
3675
|
async makeRequest(endpoint, options = {}, trackMetrics = false) {
|
|
3575
3676
|
const apiKey = await this.ensureApiKey();
|
|
3576
|
-
const url = `${
|
|
3677
|
+
const url = `${this.apiBaseUrl}${endpoint}`;
|
|
3577
3678
|
const metrics = trackMetrics ? {
|
|
3578
3679
|
startTime: Date.now(),
|
|
3579
3680
|
ttfb: 0,
|
|
@@ -3598,9 +3699,18 @@ var TTSService = class {
|
|
|
3598
3699
|
}
|
|
3599
3700
|
if (!response.ok) {
|
|
3600
3701
|
const error = data;
|
|
3601
|
-
|
|
3602
|
-
|
|
3603
|
-
)
|
|
3702
|
+
const code = error.code || response.status;
|
|
3703
|
+
const message = error.message || "Unknown error";
|
|
3704
|
+
if (code === 7 && /scope/i.test(message)) {
|
|
3705
|
+
throw new Error(
|
|
3706
|
+
`${message}
|
|
3707
|
+
|
|
3708
|
+
Your API key does not have the required scopes for this operation.
|
|
3709
|
+
Run "inworld ws select-key" to switch to a key with the correct permissions,
|
|
3710
|
+
or "inworld ws add-key --write" to create a new one with read/write access.`
|
|
3711
|
+
);
|
|
3712
|
+
}
|
|
3713
|
+
throw new Error(`TTS API Error [${code}]: ${message}`);
|
|
3604
3714
|
}
|
|
3605
3715
|
const result = data;
|
|
3606
3716
|
if (trackMetrics) {
|
|
@@ -3610,14 +3720,6 @@ var TTSService = class {
|
|
|
3610
3720
|
}
|
|
3611
3721
|
/**
|
|
3612
3722
|
* Lists all available voices based on the provided filter
|
|
3613
|
-
* @param filter - Optional filter expression (e.g., "language=en")
|
|
3614
|
-
* @returns Promise resolving to the list of available voices
|
|
3615
|
-
* @example
|
|
3616
|
-
* ```typescript
|
|
3617
|
-
* const ttsService = new TTSService();
|
|
3618
|
-
* const voices = await ttsService.listVoices('language=en');
|
|
3619
|
-
* console.log(voices.voices);
|
|
3620
|
-
* ```
|
|
3621
3723
|
*/
|
|
3622
3724
|
async listVoices(filter) {
|
|
3623
3725
|
const params = filter ? `?filter=${encodeURIComponent(filter)}` : "";
|
|
@@ -3627,19 +3729,6 @@ var TTSService = class {
|
|
|
3627
3729
|
}
|
|
3628
3730
|
/**
|
|
3629
3731
|
* Synthesizes speech from text
|
|
3630
|
-
* @param request - The synthesis request parameters
|
|
3631
|
-
* @returns Promise resolving to the synthesized audio data and optional timestamp information
|
|
3632
|
-
* @example
|
|
3633
|
-
* ```typescript
|
|
3634
|
-
* const ttsService = new TTSService();
|
|
3635
|
-
* const result = await ttsService.synthesizeSpeech({
|
|
3636
|
-
* text: 'Hello, world!',
|
|
3637
|
-
* voiceId: 'Dennis',
|
|
3638
|
-
* modelId: TTSModel.INWORLD_TTS_1,
|
|
3639
|
-
* timestampType: TimestampType.WORD,
|
|
3640
|
-
* });
|
|
3641
|
-
* // result.audioContent is base64 encoded audio data
|
|
3642
|
-
* ```
|
|
3643
3732
|
*/
|
|
3644
3733
|
async synthesizeSpeech(request) {
|
|
3645
3734
|
return this.makeRequest("/tts/v1/voice", {
|
|
@@ -3649,8 +3738,6 @@ var TTSService = class {
|
|
|
3649
3738
|
}
|
|
3650
3739
|
/**
|
|
3651
3740
|
* Synthesizes speech from text with performance metrics
|
|
3652
|
-
* @param request - The synthesis request parameters
|
|
3653
|
-
* @returns Promise resolving to the synthesized audio data with metrics
|
|
3654
3741
|
*/
|
|
3655
3742
|
async synthesizeSpeechWithMetrics(request) {
|
|
3656
3743
|
return this.makeRequest(
|
|
@@ -3660,19 +3747,14 @@ var TTSService = class {
|
|
|
3660
3747
|
body: JSON.stringify(request)
|
|
3661
3748
|
},
|
|
3662
3749
|
true
|
|
3663
|
-
// trackMetrics
|
|
3664
3750
|
);
|
|
3665
3751
|
}
|
|
3666
3752
|
/**
|
|
3667
3753
|
* Synthesizes speech using streaming API
|
|
3668
|
-
* @param request - The synthesis request parameters
|
|
3669
|
-
* @param onChunk - Callback for each audio chunk received
|
|
3670
|
-
* @param trackMetrics - Whether to track streaming metrics
|
|
3671
|
-
* @returns Promise resolving when stream completes, with optional metrics
|
|
3672
3754
|
*/
|
|
3673
3755
|
async synthesizeSpeechStream(request, onChunk, trackMetrics = false) {
|
|
3674
3756
|
const apiKey = await this.ensureApiKey();
|
|
3675
|
-
const url = `${
|
|
3757
|
+
const url = `${this.apiBaseUrl}/tts/v1/voice:stream`;
|
|
3676
3758
|
const metrics = trackMetrics ? {
|
|
3677
3759
|
startTime: Date.now(),
|
|
3678
3760
|
timeToFirstChunk: 0,
|
|
@@ -3687,15 +3769,25 @@ var TTSService = class {
|
|
|
3687
3769
|
method: "POST",
|
|
3688
3770
|
headers: {
|
|
3689
3771
|
Authorization: `Basic ${apiKey}`,
|
|
3690
|
-
"Content-Type": "application/json"
|
|
3772
|
+
"Content-Type": "application/json",
|
|
3773
|
+
Connection: "keep-alive"
|
|
3691
3774
|
},
|
|
3692
3775
|
body: JSON.stringify(request)
|
|
3693
3776
|
});
|
|
3694
3777
|
if (!response.ok) {
|
|
3695
3778
|
const error = await response.json();
|
|
3696
|
-
|
|
3697
|
-
|
|
3698
|
-
)
|
|
3779
|
+
const code = error.code || response.status;
|
|
3780
|
+
const message = error.message || "Unknown error";
|
|
3781
|
+
if (code === 7 && /scope/i.test(message)) {
|
|
3782
|
+
throw new Error(
|
|
3783
|
+
`${message}
|
|
3784
|
+
|
|
3785
|
+
Your API key does not have the required scopes for this operation.
|
|
3786
|
+
Run "inworld ws select-key" to switch to a key with the correct permissions,
|
|
3787
|
+
or "inworld ws add-key --write" to create a new one with read/write access.`
|
|
3788
|
+
);
|
|
3789
|
+
}
|
|
3790
|
+
throw new Error(`TTS Stream API Error [${code}]: ${message}`);
|
|
3699
3791
|
}
|
|
3700
3792
|
if (!response.body) {
|
|
3701
3793
|
throw new Error("No response body received from streaming endpoint");
|
|
@@ -3767,18 +3859,8 @@ var TTSService = class {
|
|
|
3767
3859
|
}
|
|
3768
3860
|
/**
|
|
3769
3861
|
* Helper method to synthesize speech with simple parameters
|
|
3770
|
-
* @param text - The text to synthesize
|
|
3771
|
-
* @param voiceId - The voice ID to use
|
|
3772
|
-
* @param modelId - The model ID to use (defaults to inworld-tts-1-max)
|
|
3773
|
-
* @returns Promise resolving to the synthesized audio data
|
|
3774
|
-
* @example
|
|
3775
|
-
* ```typescript
|
|
3776
|
-
* const ttsService = new TTSService();
|
|
3777
|
-
* const result = await ttsService.synthesize('Hello, world!', 'Dennis');
|
|
3778
|
-
* const audioBuffer = Buffer.from(result.audioContent, 'base64');
|
|
3779
|
-
* ```
|
|
3780
3862
|
*/
|
|
3781
|
-
async synthesize(text, voiceId, modelId = "inworld-tts-1-max" /*
|
|
3863
|
+
async synthesize(text, voiceId, modelId = "inworld-tts-1.5-max" /* INWORLD_TTS_1_5_MAX */) {
|
|
3782
3864
|
return this.synthesizeSpeech({
|
|
3783
3865
|
text,
|
|
3784
3866
|
voiceId,
|
|
@@ -3787,25 +3869,158 @@ var TTSService = class {
|
|
|
3787
3869
|
}
|
|
3788
3870
|
/**
|
|
3789
3871
|
* Saves synthesized audio to a file
|
|
3790
|
-
* @param audioContent - Base64 encoded audio content
|
|
3791
|
-
* @param filepath - Path where the audio file should be saved
|
|
3792
|
-
* @returns Promise that resolves when the file is written
|
|
3793
|
-
* @example
|
|
3794
|
-
* ```typescript
|
|
3795
|
-
* const ttsService = new TTSService();
|
|
3796
|
-
* const result = await ttsService.synthesize('Hello, world!', 'Dennis');
|
|
3797
|
-
* await ttsService.saveAudioToFile(result.audioContent, 'output.mp3');
|
|
3798
|
-
* ```
|
|
3799
3872
|
*/
|
|
3800
3873
|
async saveAudioToFile(audioContent, filepath) {
|
|
3801
|
-
const { writeFile:
|
|
3874
|
+
const { writeFile: writeFile3 } = await import("fs/promises");
|
|
3802
3875
|
const audioBuffer = Buffer.from(audioContent, "base64");
|
|
3803
|
-
await
|
|
3876
|
+
await writeFile3(filepath, audioBuffer);
|
|
3877
|
+
}
|
|
3878
|
+
// --- Voice Cloning ---
|
|
3879
|
+
/**
|
|
3880
|
+
* Clones a voice from audio samples
|
|
3881
|
+
*/
|
|
3882
|
+
async cloneVoice(request) {
|
|
3883
|
+
return this.makeRequest("/voices/v1/voices:clone", {
|
|
3884
|
+
method: "POST",
|
|
3885
|
+
body: JSON.stringify(request)
|
|
3886
|
+
});
|
|
3887
|
+
}
|
|
3888
|
+
// --- Voice Design ---
|
|
3889
|
+
/**
|
|
3890
|
+
* Generates preview text for voice design
|
|
3891
|
+
*/
|
|
3892
|
+
async generatePreviewText(workspace, description, langCode) {
|
|
3893
|
+
const resourceName = ensureWorkspaceResourceName(workspace);
|
|
3894
|
+
return this.makeRequest(
|
|
3895
|
+
`/voices/v1/${resourceName}/voices:generatePreviewText`,
|
|
3896
|
+
{
|
|
3897
|
+
method: "POST",
|
|
3898
|
+
body: JSON.stringify({ description, langCode })
|
|
3899
|
+
}
|
|
3900
|
+
);
|
|
3901
|
+
}
|
|
3902
|
+
/**
|
|
3903
|
+
* Designs a voice from a text description
|
|
3904
|
+
*/
|
|
3905
|
+
async designVoice(request) {
|
|
3906
|
+
return this.makeRequest("/voices/v1/voices:design", {
|
|
3907
|
+
method: "POST",
|
|
3908
|
+
body: JSON.stringify(request)
|
|
3909
|
+
});
|
|
3910
|
+
}
|
|
3911
|
+
/**
|
|
3912
|
+
* Publishes a designed voice preview to the voice library
|
|
3913
|
+
*/
|
|
3914
|
+
async publishVoice(voiceId, request) {
|
|
3915
|
+
return this.makeRequest(
|
|
3916
|
+
`/voices/v1/voices/${voiceId}:publish`,
|
|
3917
|
+
{
|
|
3918
|
+
method: "POST",
|
|
3919
|
+
body: JSON.stringify(request)
|
|
3920
|
+
}
|
|
3921
|
+
);
|
|
3804
3922
|
}
|
|
3805
3923
|
};
|
|
3806
3924
|
var ttsService = new TTSService();
|
|
3807
3925
|
|
|
3808
|
-
// src/commands/
|
|
3926
|
+
// src/commands/tts/tts_clone_command.ts
|
|
3927
|
+
var cloneCommand = new Command20("clone").description("Clone a voice from an audio file (5-15 seconds, max 4MB)").argument("<audioFile>", "Path to audio file (wav, mp3, webm)").requiredOption("-n, --name <name>", "Display name for the cloned voice").option("-l, --lang <code>", "Language code (e.g., EN_US)", "EN_US").option("-t, --transcription <text>", "Transcription of the audio").option("-d, --description <text>", "Description of the voice").option("--tags <tags>", "Comma-separated tags").option("--remove-noise", "Remove background noise from audio").option("-j, --json", "Output response as JSON").action(async (audioFile, options) => {
|
|
3928
|
+
try {
|
|
3929
|
+
const filePath = resolve(audioFile);
|
|
3930
|
+
const audioData = await readFile(filePath);
|
|
3931
|
+
if (audioData.length > 4 * 1024 * 1024) {
|
|
3932
|
+
console.error(chalk4.red("Error: Audio file exceeds 4MB limit"));
|
|
3933
|
+
process.exit(1);
|
|
3934
|
+
}
|
|
3935
|
+
const audioBase64 = audioData.toString("base64");
|
|
3936
|
+
console.log(chalk4.cyan("Cloning voice..."));
|
|
3937
|
+
console.log(chalk4.gray(`File: ${filePath}`));
|
|
3938
|
+
console.log(chalk4.gray(`Name: ${options.name}`));
|
|
3939
|
+
console.log(
|
|
3940
|
+
chalk4.gray(`Size: ${(audioData.length / 1024).toFixed(1)} KB`)
|
|
3941
|
+
);
|
|
3942
|
+
const response = await ttsService.cloneVoice({
|
|
3943
|
+
displayName: options.name,
|
|
3944
|
+
langCode: options.lang,
|
|
3945
|
+
voiceSamples: [
|
|
3946
|
+
{
|
|
3947
|
+
audioData: audioBase64,
|
|
3948
|
+
transcription: options.transcription
|
|
3949
|
+
}
|
|
3950
|
+
],
|
|
3951
|
+
description: options.description,
|
|
3952
|
+
tags: options.tags?.split(",").map((t) => t.trim()).filter(Boolean),
|
|
3953
|
+
audioProcessingConfig: options.removeNoise ? { removeBackgroundNoise: true } : void 0
|
|
3954
|
+
});
|
|
3955
|
+
if (options.json) {
|
|
3956
|
+
console.log(JSON.stringify(response, null, 2));
|
|
3957
|
+
process.exit(0);
|
|
3958
|
+
return;
|
|
3959
|
+
}
|
|
3960
|
+
for (const sample of response.audioSamplesValidated) {
|
|
3961
|
+
for (const warning of sample.warnings) {
|
|
3962
|
+
console.log(chalk4.yellow(`${warning}`));
|
|
3963
|
+
}
|
|
3964
|
+
for (const error of sample.errors) {
|
|
3965
|
+
console.log(chalk4.red(`${error}`));
|
|
3966
|
+
}
|
|
3967
|
+
}
|
|
3968
|
+
const voice = response.voice;
|
|
3969
|
+
console.log(chalk4.green("\nVoice cloned successfully!"));
|
|
3970
|
+
console.log(chalk4.white(` Voice ID: ${chalk4.cyan(voice.voiceId)}`));
|
|
3971
|
+
console.log(chalk4.white(` Display Name: ${voice.displayName}`));
|
|
3972
|
+
console.log(chalk4.white(` Language: ${voice.langCode}`));
|
|
3973
|
+
if (voice.description) {
|
|
3974
|
+
console.log(chalk4.white(` Description: ${voice.description}`));
|
|
3975
|
+
}
|
|
3976
|
+
console.log(
|
|
3977
|
+
chalk4.gray(
|
|
3978
|
+
`
|
|
3979
|
+
Use this voice: inworld tts synthesize "Hello" -v ${voice.voiceId}`
|
|
3980
|
+
)
|
|
3981
|
+
);
|
|
3982
|
+
process.exit(0);
|
|
3983
|
+
} catch (error) {
|
|
3984
|
+
console.error(chalk4.red("Error cloning voice:"));
|
|
3985
|
+
console.error(chalk4.red(error.message || error));
|
|
3986
|
+
process.exit(1);
|
|
3987
|
+
}
|
|
3988
|
+
});
|
|
3989
|
+
|
|
3990
|
+
// src/commands/tts/tts_design_command.ts
|
|
3991
|
+
import chalk6 from "chalk";
|
|
3992
|
+
import { Command as Command21 } from "commander";
|
|
3993
|
+
import { writeFile } from "fs/promises";
|
|
3994
|
+
import { tmpdir } from "os";
|
|
3995
|
+
import { join } from "path";
|
|
3996
|
+
import * as readline6 from "readline";
|
|
3997
|
+
|
|
3998
|
+
// src/utils/audio_player.ts
|
|
3999
|
+
import { unlink } from "fs/promises";
|
|
4000
|
+
async function playFile(filePath) {
|
|
4001
|
+
try {
|
|
4002
|
+
const player = (await import("play-sound")).default();
|
|
4003
|
+
await new Promise((resolve3, reject) => {
|
|
4004
|
+
player.play(filePath, (err) => {
|
|
4005
|
+
if (err) reject(err);
|
|
4006
|
+
else resolve3();
|
|
4007
|
+
});
|
|
4008
|
+
});
|
|
4009
|
+
return true;
|
|
4010
|
+
} catch {
|
|
4011
|
+
return false;
|
|
4012
|
+
}
|
|
4013
|
+
}
|
|
4014
|
+
async function cleanupTempFile(filepath) {
|
|
4015
|
+
try {
|
|
4016
|
+
await unlink(filepath);
|
|
4017
|
+
} catch {
|
|
4018
|
+
}
|
|
4019
|
+
}
|
|
4020
|
+
|
|
4021
|
+
// src/commands/tts/tts_utils.ts
|
|
4022
|
+
import chalk5 from "chalk";
|
|
4023
|
+
import * as readline5 from "readline";
|
|
3809
4024
|
function wrapText(text, maxWidth) {
|
|
3810
4025
|
const words = text.split(" ");
|
|
3811
4026
|
const lines = [];
|
|
@@ -3821,7 +4036,300 @@ function wrapText(text, maxWidth) {
|
|
|
3821
4036
|
if (currentLine) lines.push(currentLine);
|
|
3822
4037
|
return lines;
|
|
3823
4038
|
}
|
|
3824
|
-
|
|
4039
|
+
function resolveModel(modelStr) {
|
|
4040
|
+
const modelMap = {
|
|
4041
|
+
"inworld-tts-1": "inworld-tts-1" /* INWORLD_TTS_1 */,
|
|
4042
|
+
"inworld-tts-1-max": "inworld-tts-1-max" /* INWORLD_TTS_1_MAX */,
|
|
4043
|
+
"inworld-tts-1.5-mini": "inworld-tts-1.5-mini" /* INWORLD_TTS_1_5_MINI */,
|
|
4044
|
+
"inworld-tts-1.5-max": "inworld-tts-1.5-max" /* INWORLD_TTS_1_5_MAX */
|
|
4045
|
+
};
|
|
4046
|
+
const model = modelMap[modelStr];
|
|
4047
|
+
if (!model) {
|
|
4048
|
+
console.error(
|
|
4049
|
+
chalk5.red(
|
|
4050
|
+
`Unknown model: ${modelStr}. Available: ${Object.keys(modelMap).join(", ")}`
|
|
4051
|
+
)
|
|
4052
|
+
);
|
|
4053
|
+
process.exit(1);
|
|
4054
|
+
}
|
|
4055
|
+
if (LEGACY_MODELS.has(model)) {
|
|
4056
|
+
console.log(
|
|
4057
|
+
chalk5.yellow(
|
|
4058
|
+
`Model "${modelStr}" is deprecated. Consider using "inworld-tts-1.5-mini" or "inworld-tts-1.5-max".`
|
|
4059
|
+
)
|
|
4060
|
+
);
|
|
4061
|
+
}
|
|
4062
|
+
return model;
|
|
4063
|
+
}
|
|
4064
|
+
var FORMAT_EXTENSIONS = {
|
|
4065
|
+
MP3: ".mp3",
|
|
4066
|
+
LINEAR16: ".wav",
|
|
4067
|
+
WAV: ".wav",
|
|
4068
|
+
OGG_OPUS: ".ogg",
|
|
4069
|
+
ALAW: ".raw",
|
|
4070
|
+
MULAW: ".raw",
|
|
4071
|
+
FLAC: ".flac",
|
|
4072
|
+
PCM: ".pcm"
|
|
4073
|
+
};
|
|
4074
|
+
var VALID_FORMATS = Object.keys(FORMAT_EXTENSIONS);
|
|
4075
|
+
function getFileExtension(format) {
|
|
4076
|
+
return FORMAT_EXTENSIONS[format] || ".mp3";
|
|
4077
|
+
}
|
|
4078
|
+
function resolveFormat(format, defaultFormat) {
|
|
4079
|
+
if (!format) return defaultFormat;
|
|
4080
|
+
const normalized = format.toUpperCase();
|
|
4081
|
+
if (!FORMAT_EXTENSIONS[normalized]) {
|
|
4082
|
+
console.error(
|
|
4083
|
+
chalk5.red(
|
|
4084
|
+
`Unknown format: ${format}. Available: ${VALID_FORMATS.join(", ")}`
|
|
4085
|
+
)
|
|
4086
|
+
);
|
|
4087
|
+
process.exit(1);
|
|
4088
|
+
}
|
|
4089
|
+
return normalized;
|
|
4090
|
+
}
|
|
4091
|
+
function promptInput(prompt, defaultValue) {
|
|
4092
|
+
const rl = readline5.createInterface({
|
|
4093
|
+
input: process.stdin,
|
|
4094
|
+
output: process.stdout
|
|
4095
|
+
});
|
|
4096
|
+
const displayPrompt = defaultValue ? `${prompt} [${defaultValue}]: ` : `${prompt}: `;
|
|
4097
|
+
return new Promise((resolve3) => {
|
|
4098
|
+
rl.question(displayPrompt, (answer) => {
|
|
4099
|
+
rl.close();
|
|
4100
|
+
resolve3(answer.trim() || defaultValue || "");
|
|
4101
|
+
});
|
|
4102
|
+
});
|
|
4103
|
+
}
|
|
4104
|
+
|
|
4105
|
+
// src/commands/tts/tts_design_command.ts
|
|
4106
|
+
async function savePreviewsToTemp(previews) {
|
|
4107
|
+
const paths = [];
|
|
4108
|
+
for (let i = 0; i < previews.length; i++) {
|
|
4109
|
+
const safeId = previews[i].voiceId.replace(/[^a-zA-Z0-9_-]/g, "_");
|
|
4110
|
+
const tempPath = join(tmpdir(), `inworld-preview-${i + 1}-${safeId}.wav`);
|
|
4111
|
+
const buf = Buffer.from(previews[i].previewAudio, "base64");
|
|
4112
|
+
await writeFile(tempPath, buf);
|
|
4113
|
+
paths.push(tempPath);
|
|
4114
|
+
}
|
|
4115
|
+
return paths;
|
|
4116
|
+
}
|
|
4117
|
+
var designCommand = new Command21("design").description(
|
|
4118
|
+
"Design a voice from a text description (interactive wizard)\n\nGenerates voice previews, lets you listen and pick, then publishes."
|
|
4119
|
+
).argument("<prompt>", "Voice description (30-250 characters, English)").option(
|
|
4120
|
+
"-s, --script <text>",
|
|
4121
|
+
"Preview script for the voice to speak (50-200 chars)"
|
|
4122
|
+
).option(
|
|
4123
|
+
"--auto-script",
|
|
4124
|
+
"Auto-generate preview script from prompt instead of using --script"
|
|
4125
|
+
).option("-l, --lang <code>", "Language code (e.g., EN_US)", "EN_US").option("-c, --count <n>", "Number of preview samples (1-3)", "3").option("-n, --name <name>", "Display name for publishing").option("-d, --description <text>", "Description for publishing").option("--tags <tags>", "Comma-separated tags for publishing").option("-j, --json", "Non-interactive: output all previews as JSON").action(async (prompt, options) => {
|
|
4126
|
+
let tempFiles = [];
|
|
4127
|
+
try {
|
|
4128
|
+
if (prompt.length < 30 || prompt.length > 250) {
|
|
4129
|
+
console.error(
|
|
4130
|
+
chalk6.red("Error: Design prompt must be 30-250 characters")
|
|
4131
|
+
);
|
|
4132
|
+
console.log(chalk6.gray(`Current length: ${prompt.length} characters`));
|
|
4133
|
+
process.exit(1);
|
|
4134
|
+
}
|
|
4135
|
+
const count = parseInt(options.count, 10);
|
|
4136
|
+
if (isNaN(count) || count < 1 || count > 3) {
|
|
4137
|
+
console.error(chalk6.red("Error: --count must be 1, 2, or 3"));
|
|
4138
|
+
process.exit(1);
|
|
4139
|
+
}
|
|
4140
|
+
let previewText = options.script;
|
|
4141
|
+
if (!previewText && !options.autoScript) {
|
|
4142
|
+
console.error(
|
|
4143
|
+
chalk6.red("Error: Provide --script <text> or use --auto-script")
|
|
4144
|
+
);
|
|
4145
|
+
process.exit(1);
|
|
4146
|
+
}
|
|
4147
|
+
if (options.autoScript) {
|
|
4148
|
+
console.log(chalk6.cyan("Generating preview script..."));
|
|
4149
|
+
const workspace = await requireWorkspace();
|
|
4150
|
+
const result = await ttsService.generatePreviewText(
|
|
4151
|
+
workspace,
|
|
4152
|
+
prompt,
|
|
4153
|
+
options.lang
|
|
4154
|
+
);
|
|
4155
|
+
previewText = result.previewText;
|
|
4156
|
+
console.log(chalk6.gray(` "${previewText}"`));
|
|
4157
|
+
} else if (previewText.length < 50 || previewText.length > 200) {
|
|
4158
|
+
console.error(
|
|
4159
|
+
chalk6.red("Error: Preview script must be 50-200 characters")
|
|
4160
|
+
);
|
|
4161
|
+
process.exit(1);
|
|
4162
|
+
}
|
|
4163
|
+
tempFiles = [];
|
|
4164
|
+
const generate = async () => {
|
|
4165
|
+
console.log(chalk6.cyan("\nDesigning voice..."));
|
|
4166
|
+
const response = await ttsService.designVoice({
|
|
4167
|
+
langCode: options.lang,
|
|
4168
|
+
designPrompt: prompt,
|
|
4169
|
+
previewText,
|
|
4170
|
+
voiceDesignConfig: { numberOfSamples: count }
|
|
4171
|
+
});
|
|
4172
|
+
return response.previewVoices;
|
|
4173
|
+
};
|
|
4174
|
+
let previews = await generate();
|
|
4175
|
+
if (options.json) {
|
|
4176
|
+
console.log(JSON.stringify(previews, null, 2));
|
|
4177
|
+
process.exit(0);
|
|
4178
|
+
return;
|
|
4179
|
+
}
|
|
4180
|
+
let selectedVoiceId = null;
|
|
4181
|
+
if (previews.length === 1) {
|
|
4182
|
+
const preview = previews[0];
|
|
4183
|
+
tempFiles = await savePreviewsToTemp(previews);
|
|
4184
|
+
console.log(chalk6.green(`
|
|
4185
|
+
Generated voice preview:
|
|
4186
|
+
`));
|
|
4187
|
+
console.log(
|
|
4188
|
+
` ${chalk6.bold.white("1.")} ${chalk6.cyan(preview.voiceId)}`
|
|
4189
|
+
);
|
|
4190
|
+
console.log(chalk6.gray(` ${tempFiles[0]}`));
|
|
4191
|
+
selectedVoiceId = preview.voiceId;
|
|
4192
|
+
}
|
|
4193
|
+
while (!selectedVoiceId) {
|
|
4194
|
+
for (const f of tempFiles) await cleanupTempFile(f);
|
|
4195
|
+
tempFiles = await savePreviewsToTemp(previews);
|
|
4196
|
+
console.log(
|
|
4197
|
+
chalk6.green(`
|
|
4198
|
+
Generated ${previews.length} voice preview(s):
|
|
4199
|
+
`)
|
|
4200
|
+
);
|
|
4201
|
+
for (let i = 0; i < previews.length; i++) {
|
|
4202
|
+
console.log(
|
|
4203
|
+
` ${chalk6.bold.white(`${i + 1}.`)} ${chalk6.cyan(previews[i].voiceId)}`
|
|
4204
|
+
);
|
|
4205
|
+
console.log(chalk6.gray(` ${tempFiles[i]}`));
|
|
4206
|
+
}
|
|
4207
|
+
console.log(
|
|
4208
|
+
chalk6.gray(
|
|
4209
|
+
`
|
|
4210
|
+
Actions: [1-${previews.length}] play a preview, [p] publish, [r] regenerate, [q] quit`
|
|
4211
|
+
)
|
|
4212
|
+
);
|
|
4213
|
+
const rl = readline6.createInterface({
|
|
4214
|
+
input: process.stdin,
|
|
4215
|
+
output: process.stdout
|
|
4216
|
+
});
|
|
4217
|
+
const ask = (q) => new Promise((resolve3) => rl.question(q, resolve3));
|
|
4218
|
+
let action = null;
|
|
4219
|
+
while (true) {
|
|
4220
|
+
const answer = (await ask("> ")).trim().toLowerCase();
|
|
4221
|
+
const idx = parseInt(answer, 10);
|
|
4222
|
+
if (!isNaN(idx) && idx >= 1 && idx <= previews.length) {
|
|
4223
|
+
console.log(
|
|
4224
|
+
chalk6.white(
|
|
4225
|
+
` Playing preview ${idx}... (${chalk6.cyan(previews[idx - 1].voiceId)})`
|
|
4226
|
+
)
|
|
4227
|
+
);
|
|
4228
|
+
const played = await playFile(tempFiles[idx - 1]);
|
|
4229
|
+
if (!played) {
|
|
4230
|
+
console.log(
|
|
4231
|
+
chalk6.gray(
|
|
4232
|
+
` Playback unavailable. Open: ${tempFiles[idx - 1]}`
|
|
4233
|
+
)
|
|
4234
|
+
);
|
|
4235
|
+
}
|
|
4236
|
+
continue;
|
|
4237
|
+
}
|
|
4238
|
+
if (answer === "r") {
|
|
4239
|
+
action = "regenerate";
|
|
4240
|
+
break;
|
|
4241
|
+
}
|
|
4242
|
+
if (answer === "q") {
|
|
4243
|
+
action = "quit";
|
|
4244
|
+
break;
|
|
4245
|
+
}
|
|
4246
|
+
if (answer === "p") {
|
|
4247
|
+
action = "publish";
|
|
4248
|
+
break;
|
|
4249
|
+
}
|
|
4250
|
+
console.log(
|
|
4251
|
+
chalk6.yellow(
|
|
4252
|
+
` Enter 1-${previews.length} to play, p to publish, r to regenerate, q to quit`
|
|
4253
|
+
)
|
|
4254
|
+
);
|
|
4255
|
+
}
|
|
4256
|
+
rl.close();
|
|
4257
|
+
if (action === "quit") {
|
|
4258
|
+
break;
|
|
4259
|
+
}
|
|
4260
|
+
if (action === "regenerate") {
|
|
4261
|
+
console.log(chalk6.cyan("Regenerating..."));
|
|
4262
|
+
previews = await generate();
|
|
4263
|
+
continue;
|
|
4264
|
+
}
|
|
4265
|
+
if (action === "publish") {
|
|
4266
|
+
if (previews.length === 1) {
|
|
4267
|
+
selectedVoiceId = previews[0].voiceId;
|
|
4268
|
+
} else {
|
|
4269
|
+
const choice = await promptInput(
|
|
4270
|
+
` Which voice to publish? (1-${previews.length})`
|
|
4271
|
+
);
|
|
4272
|
+
const choiceIdx = parseInt(choice, 10);
|
|
4273
|
+
if (isNaN(choiceIdx) || choiceIdx < 1 || choiceIdx > previews.length) {
|
|
4274
|
+
console.error(chalk6.red("Invalid selection."));
|
|
4275
|
+
continue;
|
|
4276
|
+
}
|
|
4277
|
+
selectedVoiceId = previews[choiceIdx - 1].voiceId;
|
|
4278
|
+
}
|
|
4279
|
+
break;
|
|
4280
|
+
}
|
|
4281
|
+
}
|
|
4282
|
+
if (!selectedVoiceId) {
|
|
4283
|
+
for (const f of tempFiles) await cleanupTempFile(f);
|
|
4284
|
+
process.exit(0);
|
|
4285
|
+
return;
|
|
4286
|
+
}
|
|
4287
|
+
console.log(chalk6.green(`
|
|
4288
|
+
Publishing: ${chalk6.cyan(selectedVoiceId)}`));
|
|
4289
|
+
const displayName = options.name || await promptInput(" Display name");
|
|
4290
|
+
if (!displayName) {
|
|
4291
|
+
console.error(chalk6.red("Display name is required."));
|
|
4292
|
+
for (const f of tempFiles) await cleanupTempFile(f);
|
|
4293
|
+
process.exit(1);
|
|
4294
|
+
return;
|
|
4295
|
+
}
|
|
4296
|
+
const description = options.description || await promptInput(" Description", prompt);
|
|
4297
|
+
const tagsRaw = options.tags || await promptInput(" Tags (comma-separated, optional)");
|
|
4298
|
+
const tags = tagsRaw ? tagsRaw.split(",").map((t) => t.trim()).filter(Boolean) : void 0;
|
|
4299
|
+
console.log(chalk6.cyan("\nPublishing voice..."));
|
|
4300
|
+
const published = await ttsService.publishVoice(selectedVoiceId, {
|
|
4301
|
+
displayName,
|
|
4302
|
+
description,
|
|
4303
|
+
tags
|
|
4304
|
+
});
|
|
4305
|
+
console.log(chalk6.green("\nVoice published!"));
|
|
4306
|
+
console.log(
|
|
4307
|
+
chalk6.white(` Voice ID: ${chalk6.cyan(published.voiceId)}`)
|
|
4308
|
+
);
|
|
4309
|
+
console.log(chalk6.white(` Display Name: ${published.displayName}`));
|
|
4310
|
+
if (published.description) {
|
|
4311
|
+
console.log(chalk6.white(` Description: ${published.description}`));
|
|
4312
|
+
}
|
|
4313
|
+
console.log(
|
|
4314
|
+
chalk6.gray(
|
|
4315
|
+
`
|
|
4316
|
+
Use this voice: inworld tts synthesize "Hello" -v ${published.voiceId}`
|
|
4317
|
+
)
|
|
4318
|
+
);
|
|
4319
|
+
for (const f of tempFiles) await cleanupTempFile(f);
|
|
4320
|
+
process.exit(0);
|
|
4321
|
+
} catch (error) {
|
|
4322
|
+
for (const f of tempFiles) await cleanupTempFile(f);
|
|
4323
|
+
console.error(chalk6.red("Error designing voice:"));
|
|
4324
|
+
console.error(chalk6.red(error.message || error));
|
|
4325
|
+
process.exit(1);
|
|
4326
|
+
}
|
|
4327
|
+
});
|
|
4328
|
+
|
|
4329
|
+
// src/commands/tts/tts_list_voices_command.ts
|
|
4330
|
+
import chalk7 from "chalk";
|
|
4331
|
+
import { Command as Command22 } from "commander";
|
|
4332
|
+
var listVoicesCommand = new Command22("list-voices").description("List all available voices from the workspace").option("-f, --filter <filter>", 'Filter voices (e.g., "language=en")').option("-j, --json", "Output as JSON").option("-c, --compact", "Compact output (voice IDs only)").action(async (options) => {
|
|
3825
4333
|
try {
|
|
3826
4334
|
const response = await ttsService.listVoices(options.filter);
|
|
3827
4335
|
if (options.json) {
|
|
@@ -3830,15 +4338,15 @@ var listVoicesCommand = new Command20("list-voices").description("List all avail
|
|
|
3830
4338
|
return;
|
|
3831
4339
|
}
|
|
3832
4340
|
if (!response.voices || response.voices.length === 0) {
|
|
3833
|
-
console.log(
|
|
4341
|
+
console.log(chalk7.yellow("No voices found"));
|
|
3834
4342
|
process.exit(0);
|
|
3835
4343
|
return;
|
|
3836
4344
|
}
|
|
3837
4345
|
if (options.compact) {
|
|
3838
|
-
console.log("\n" +
|
|
3839
|
-
console.log(
|
|
4346
|
+
console.log("\n" + chalk7.bold.green("Available Voice IDs:"));
|
|
4347
|
+
console.log(chalk7.gray("\u2500".repeat(50)));
|
|
3840
4348
|
response.voices.sort((a, b) => a.voiceId.localeCompare(b.voiceId)).forEach((voice) => {
|
|
3841
|
-
console.log(` ${
|
|
4349
|
+
console.log(` ${chalk7.cyan("\u2022")} ${voice.voiceId}`);
|
|
3842
4350
|
});
|
|
3843
4351
|
console.log();
|
|
3844
4352
|
process.exit(0);
|
|
@@ -3854,13 +4362,13 @@ var listVoicesCommand = new Command20("list-voices").description("List all avail
|
|
|
3854
4362
|
voicesByLanguage.get(primaryLang).push(voice);
|
|
3855
4363
|
});
|
|
3856
4364
|
const sortedLanguages = Array.from(voicesByLanguage.keys()).sort();
|
|
3857
|
-
console.log("\n" +
|
|
4365
|
+
console.log("\n" + chalk7.bold.green("Available TTS Voices"));
|
|
3858
4366
|
console.log(
|
|
3859
|
-
|
|
4367
|
+
chalk7.gray(
|
|
3860
4368
|
`Found ${response.voices.length} voices across ${sortedLanguages.length} languages`
|
|
3861
4369
|
)
|
|
3862
4370
|
);
|
|
3863
|
-
console.log(
|
|
4371
|
+
console.log(chalk7.gray("\u2500".repeat(80)));
|
|
3864
4372
|
sortedLanguages.forEach((lang, langIndex) => {
|
|
3865
4373
|
const voices = voicesByLanguage.get(lang);
|
|
3866
4374
|
const languageFlags = {
|
|
@@ -3880,19 +4388,19 @@ var listVoicesCommand = new Command20("list-voices").description("List all avail
|
|
|
3880
4388
|
const flag = languageFlags[lang] || "\u{1F310}";
|
|
3881
4389
|
console.log(
|
|
3882
4390
|
`
|
|
3883
|
-
${flag} ${
|
|
4391
|
+
${flag} ${chalk7.bold.yellow(lang.toUpperCase())} ${chalk7.gray(`(${voices.length} voices)`)}`
|
|
3884
4392
|
);
|
|
3885
|
-
console.log(
|
|
4393
|
+
console.log(chalk7.gray("\u2500".repeat(80)));
|
|
3886
4394
|
voices.sort((a, b) => a.voiceId.localeCompare(b.voiceId)).forEach((voice) => {
|
|
3887
|
-
const displayName = voice.displayName && voice.displayName !== voice.voiceId ?
|
|
4395
|
+
const displayName = voice.displayName && voice.displayName !== voice.voiceId ? chalk7.gray(` (${voice.displayName})`) : "";
|
|
3888
4396
|
console.log(
|
|
3889
|
-
` ${
|
|
4397
|
+
` ${chalk7.cyan("\u25B8")} ${chalk7.bold.white(voice.voiceId)}${displayName}`
|
|
3890
4398
|
);
|
|
3891
4399
|
if (voice.description) {
|
|
3892
4400
|
const maxWidth = 76;
|
|
3893
4401
|
const descriptionLines = wrapText(voice.description, maxWidth);
|
|
3894
4402
|
descriptionLines.forEach((line) => {
|
|
3895
|
-
console.log(` ${
|
|
4403
|
+
console.log(` ${chalk7.gray(line)}`);
|
|
3896
4404
|
});
|
|
3897
4405
|
}
|
|
3898
4406
|
});
|
|
@@ -3900,112 +4408,111 @@ ${flag} ${chalk4.bold.yellow(lang.toUpperCase())} ${chalk4.gray(`(${voices.leng
|
|
|
3900
4408
|
console.log();
|
|
3901
4409
|
}
|
|
3902
4410
|
});
|
|
3903
|
-
console.log("\n" +
|
|
3904
|
-
console.log(
|
|
4411
|
+
console.log("\n" + chalk7.gray("\u2500".repeat(80)));
|
|
4412
|
+
console.log(chalk7.gray("Tips:"));
|
|
3905
4413
|
console.log(
|
|
3906
|
-
|
|
4414
|
+
chalk7.gray(' \u2022 Use --filter "language=<code>" to filter by language')
|
|
3907
4415
|
);
|
|
3908
4416
|
console.log(
|
|
3909
|
-
|
|
4417
|
+
chalk7.gray(" \u2022 Use --compact for a simple list of voice IDs")
|
|
3910
4418
|
);
|
|
3911
|
-
console.log(
|
|
4419
|
+
console.log(chalk7.gray(" \u2022 Use --json for machine-readable output"));
|
|
3912
4420
|
console.log(
|
|
3913
|
-
|
|
4421
|
+
chalk7.gray('\nExample: inworld tts list-voices --filter "language=en"')
|
|
3914
4422
|
);
|
|
3915
4423
|
console.log();
|
|
3916
4424
|
} catch (error) {
|
|
3917
|
-
console.error(
|
|
4425
|
+
console.error(chalk7.red("Error listing voices:"), error);
|
|
3918
4426
|
process.exit(1);
|
|
3919
4427
|
}
|
|
3920
4428
|
process.exit(0);
|
|
3921
4429
|
});
|
|
3922
|
-
|
|
4430
|
+
|
|
4431
|
+
// src/commands/tts/tts_synthesize_command.ts
|
|
4432
|
+
import chalk8 from "chalk";
|
|
4433
|
+
import { Command as Command23 } from "commander";
|
|
4434
|
+
import { writeFile as writeFile2 } from "fs/promises";
|
|
4435
|
+
import { resolve as resolve2 } from "path";
|
|
4436
|
+
var synthesizeCommand = new Command23("synthesize").description(
|
|
4437
|
+
'Synthesize text to speech\n\nAudio markups supported in text:\n SSML breaks: <break time="1s" /> or <break time="500ms" />\n Emotions: [happy] [sad] [angry] [surprised] [fearful] [disgusted]\n Delivery: [laughing] [whispering]\n Vocalizations: [breathe] [clear_throat] [cough] [laugh] [sigh] [yawn]\n Pronunciation: /kri\u02D0t/ (IPA in forward slashes)'
|
|
4438
|
+
).argument("<text>", "Text to synthesize (max 2000 characters)").requiredOption(
|
|
3923
4439
|
"-v, --voice <voiceId>",
|
|
3924
4440
|
"Voice ID to use for synthesis",
|
|
3925
4441
|
"Dennis"
|
|
3926
4442
|
).option("-o, --output <file>", "Output audio file path (default: output.mp3)").option(
|
|
3927
4443
|
"-m, --model <model>",
|
|
3928
|
-
"TTS model
|
|
3929
|
-
"inworld-tts-1"
|
|
4444
|
+
"TTS model (inworld-tts-1.5-mini, inworld-tts-1.5-max, or legacy inworld-tts-1, inworld-tts-1-max)",
|
|
4445
|
+
"inworld-tts-1.5-max"
|
|
3930
4446
|
).option(
|
|
3931
4447
|
"-t, --temperature <temp>",
|
|
3932
4448
|
"Temperature (0.0-2.0, default: 1.1)",
|
|
3933
4449
|
"1.1"
|
|
3934
|
-
).option(
|
|
4450
|
+
).option(
|
|
4451
|
+
"--format <format>",
|
|
4452
|
+
"Audio format (MP3, LINEAR16, OGG_OPUS, FLAC, PCM, WAV, ALAW, MULAW). Default: MP3 (LINEAR16 for streaming)"
|
|
4453
|
+
).option("--timestamps <type>", "Include timestamps (WORD or CHARACTER)").option("--normalize <mode>", "Text normalization (on or off)").option("-j, --json", "Output response as JSON (includes base64 audio)").option("-p, --play", "Play the synthesized audio through speakers").option("--stats", "Show request performance statistics").option("--stream", "Use streaming API for synthesis").action(async (text, options) => {
|
|
3935
4454
|
try {
|
|
3936
4455
|
if (text.length > 2e3) {
|
|
3937
|
-
console.error(
|
|
3938
|
-
console.log(
|
|
4456
|
+
console.error(chalk8.red("Error: Text exceeds 2000 character limit"));
|
|
4457
|
+
console.log(chalk8.gray(`Current length: ${text.length} characters`));
|
|
3939
4458
|
process.exit(1);
|
|
3940
4459
|
}
|
|
3941
4460
|
const temperature = parseFloat(options.temperature);
|
|
3942
4461
|
if (isNaN(temperature) || temperature < 0 || temperature > 2) {
|
|
3943
4462
|
console.error(
|
|
3944
|
-
|
|
4463
|
+
chalk8.red("Error: Temperature must be between 0.0 and 2.0")
|
|
3945
4464
|
);
|
|
3946
4465
|
process.exit(1);
|
|
3947
4466
|
}
|
|
3948
|
-
const
|
|
3949
|
-
|
|
3950
|
-
|
|
3951
|
-
};
|
|
3952
|
-
|
|
3953
|
-
|
|
3954
|
-
|
|
3955
|
-
|
|
3956
|
-
|
|
4467
|
+
const modelId = resolveModel(options.model);
|
|
4468
|
+
console.log(chalk8.cyan("Synthesizing speech..."));
|
|
4469
|
+
console.log(chalk8.gray(`Voice: ${options.voice}`));
|
|
4470
|
+
console.log(chalk8.gray(`Model: ${options.model}`));
|
|
4471
|
+
console.log(chalk8.gray(`Text length: ${text.length} characters`));
|
|
4472
|
+
const defaultFormat = options.stream ? "LINEAR16" : "MP3";
|
|
4473
|
+
const format = resolveFormat(options.format, defaultFormat);
|
|
4474
|
+
const fileExtension = getFileExtension(format);
|
|
4475
|
+
const safeVoice = options.voice.replace(/[^a-zA-Z0-9_-]/g, "_");
|
|
4476
|
+
const outputPath = resolve2(
|
|
4477
|
+
options.output || `${safeVoice}_${Date.now()}${fileExtension}`
|
|
4478
|
+
);
|
|
3957
4479
|
const request = {
|
|
3958
4480
|
text,
|
|
3959
4481
|
voiceId: options.voice,
|
|
3960
4482
|
modelId,
|
|
3961
|
-
temperature
|
|
4483
|
+
temperature,
|
|
4484
|
+
audioConfig: { audioEncoding: format }
|
|
3962
4485
|
};
|
|
3963
|
-
if (options.format) {
|
|
3964
|
-
request.audioConfig = {
|
|
3965
|
-
audioEncoding: options.format
|
|
3966
|
-
};
|
|
3967
|
-
}
|
|
3968
4486
|
if (options.timestamps) {
|
|
3969
4487
|
request.timestampType = options.timestamps;
|
|
3970
4488
|
}
|
|
4489
|
+
if (options.normalize) {
|
|
4490
|
+
const mode = options.normalize.toUpperCase();
|
|
4491
|
+
if (mode === "ON" || mode === "OFF") {
|
|
4492
|
+
request.applyTextNormalization = mode;
|
|
4493
|
+
} else {
|
|
4494
|
+
console.error(chalk8.red('Error: --normalize must be "on" or "off"'));
|
|
4495
|
+
process.exit(1);
|
|
4496
|
+
}
|
|
4497
|
+
}
|
|
3971
4498
|
let response;
|
|
3972
4499
|
let audioBuffer;
|
|
3973
|
-
let fileExtension = ".mp3";
|
|
3974
4500
|
if (options.stream) {
|
|
3975
|
-
|
|
3976
|
-
fileExtension = ".wav";
|
|
3977
|
-
if (options.format === "MP3") {
|
|
4501
|
+
if (format === "MP3") {
|
|
3978
4502
|
console.log(
|
|
3979
|
-
|
|
3980
|
-
"\u26A0\uFE0F Warning: MP3 streaming requires special handling."
|
|
3981
|
-
)
|
|
4503
|
+
chalk8.yellow("Warning: MP3 streaming requires special handling.")
|
|
3982
4504
|
);
|
|
3983
4505
|
console.log(
|
|
3984
|
-
|
|
4506
|
+
chalk8.yellow(" Audio chunks may not concatenate perfectly.")
|
|
3985
4507
|
);
|
|
3986
4508
|
console.log(
|
|
3987
|
-
|
|
4509
|
+
chalk8.yellow(
|
|
3988
4510
|
" Consider using LINEAR16 or OGG_OPUS for better streaming."
|
|
3989
4511
|
)
|
|
3990
4512
|
);
|
|
3991
|
-
fileExtension = ".mp3";
|
|
3992
|
-
} else if (options.format === "OGG_OPUS") {
|
|
3993
|
-
fileExtension = ".ogg";
|
|
3994
|
-
} else if (options.format === "ALAW" || options.format === "MULAW") {
|
|
3995
|
-
fileExtension = ".raw";
|
|
3996
|
-
} else if (!options.format || options.format === "LINEAR16") {
|
|
3997
|
-
streamFormat = "LINEAR16";
|
|
3998
|
-
fileExtension = ".wav";
|
|
3999
4513
|
}
|
|
4000
|
-
console.log(
|
|
4001
|
-
console.log(
|
|
4002
|
-
const streamRequest = {
|
|
4003
|
-
...request,
|
|
4004
|
-
audioConfig: {
|
|
4005
|
-
...request.audioConfig,
|
|
4006
|
-
audioEncoding: streamFormat
|
|
4007
|
-
}
|
|
4008
|
-
};
|
|
4514
|
+
console.log(chalk8.cyan("Using streaming synthesis..."));
|
|
4515
|
+
console.log(chalk8.gray(`Format: ${format}${fileExtension}`));
|
|
4009
4516
|
const audioChunks = [];
|
|
4010
4517
|
let timestampInfo = null;
|
|
4011
4518
|
let streamError = null;
|
|
@@ -4022,18 +4529,16 @@ var synthesizeCommand = new Command20("synthesize").description("Synthesize text
|
|
|
4022
4529
|
characterEndTimeSeconds: []
|
|
4023
4530
|
};
|
|
4024
4531
|
const streamResult = await ttsService.synthesizeSpeechStream(
|
|
4025
|
-
|
|
4532
|
+
request,
|
|
4026
4533
|
(chunk) => {
|
|
4027
4534
|
chunkCount++;
|
|
4028
4535
|
if (chunk.error) {
|
|
4029
4536
|
streamError = chunk.error;
|
|
4030
|
-
console.error(
|
|
4031
|
-
chalk4.red(`\u274C Stream error: ${chunk.error.message}`)
|
|
4032
|
-
);
|
|
4537
|
+
console.error(chalk8.red(`Stream error: ${chunk.error.message}`));
|
|
4033
4538
|
} else {
|
|
4034
4539
|
if (chunk.audioContent) {
|
|
4035
4540
|
const chunkBuffer = Buffer.from(chunk.audioContent, "base64");
|
|
4036
|
-
if (
|
|
4541
|
+
if (format === "LINEAR16" || format === "WAV") {
|
|
4037
4542
|
if (!isFirstChunk) {
|
|
4038
4543
|
const headerSize = 44;
|
|
4039
4544
|
if (chunkBuffer.length > headerSize) {
|
|
@@ -4043,17 +4548,13 @@ var synthesizeCommand = new Command20("synthesize").description("Synthesize text
|
|
|
4043
4548
|
audioChunks.push(chunkBuffer);
|
|
4044
4549
|
isFirstChunk = false;
|
|
4045
4550
|
}
|
|
4046
|
-
} else if (streamFormat === "OGG_OPUS") {
|
|
4047
|
-
audioChunks.push(chunkBuffer);
|
|
4048
|
-
} else if (streamFormat === "MP3") {
|
|
4049
|
-
audioChunks.push(chunkBuffer);
|
|
4050
4551
|
} else {
|
|
4051
4552
|
audioChunks.push(chunkBuffer);
|
|
4052
4553
|
}
|
|
4053
4554
|
if (!options.json && !options.stats) {
|
|
4054
4555
|
const chunkSizeKB = (chunkBuffer.length / 1024).toFixed(2);
|
|
4055
4556
|
process.stdout.write(
|
|
4056
|
-
|
|
4557
|
+
chalk8.gray(
|
|
4057
4558
|
`\rReceived chunk ${chunkCount} (${chunkSizeKB} KB)...`
|
|
4058
4559
|
)
|
|
4059
4560
|
);
|
|
@@ -4086,7 +4587,6 @@ var synthesizeCommand = new Command20("synthesize").description("Synthesize text
|
|
|
4086
4587
|
}
|
|
4087
4588
|
},
|
|
4088
4589
|
options.stats
|
|
4089
|
-
// trackMetrics
|
|
4090
4590
|
);
|
|
4091
4591
|
if (!options.json && !options.stats && chunkCount > 0) {
|
|
4092
4592
|
process.stdout.write("\r" + " ".repeat(50) + "\r");
|
|
@@ -4098,18 +4598,10 @@ var synthesizeCommand = new Command20("synthesize").description("Synthesize text
|
|
|
4098
4598
|
if (allWordAlignments.words.length > 0 || allCharacterAlignments.characters.length > 0) {
|
|
4099
4599
|
timestampInfo = {};
|
|
4100
4600
|
if (allWordAlignments.words.length > 0) {
|
|
4101
|
-
timestampInfo.wordAlignment = {
|
|
4102
|
-
words: allWordAlignments.words,
|
|
4103
|
-
wordStartTimeSeconds: allWordAlignments.wordStartTimeSeconds,
|
|
4104
|
-
wordEndTimeSeconds: allWordAlignments.wordEndTimeSeconds
|
|
4105
|
-
};
|
|
4601
|
+
timestampInfo.wordAlignment = { ...allWordAlignments };
|
|
4106
4602
|
}
|
|
4107
4603
|
if (allCharacterAlignments.characters.length > 0) {
|
|
4108
|
-
timestampInfo.characterAlignment = {
|
|
4109
|
-
characters: allCharacterAlignments.characters,
|
|
4110
|
-
characterStartTimeSeconds: allCharacterAlignments.characterStartTimeSeconds,
|
|
4111
|
-
characterEndTimeSeconds: allCharacterAlignments.characterEndTimeSeconds
|
|
4112
|
-
};
|
|
4604
|
+
timestampInfo.characterAlignment = { ...allCharacterAlignments };
|
|
4113
4605
|
}
|
|
4114
4606
|
}
|
|
4115
4607
|
const combinedAudioBase64 = audioBuffer.toString("base64");
|
|
@@ -4131,55 +4623,40 @@ var synthesizeCommand = new Command20("synthesize").description("Synthesize text
|
|
|
4131
4623
|
)
|
|
4132
4624
|
);
|
|
4133
4625
|
} else {
|
|
4134
|
-
|
|
4135
|
-
|
|
4136
|
-
);
|
|
4137
|
-
await writeFile(outputPath, audioBuffer);
|
|
4138
|
-
console.log(chalk4.green(`\u2705 Audio saved to: ${outputPath}`));
|
|
4626
|
+
await writeFile2(outputPath, audioBuffer);
|
|
4627
|
+
console.log(chalk8.green(`Audio saved to: ${outputPath}`));
|
|
4139
4628
|
console.log(
|
|
4140
|
-
|
|
4629
|
+
chalk8.gray(
|
|
4141
4630
|
`File size: ${(audioBuffer.length / 1024).toFixed(2)} KB`
|
|
4142
4631
|
)
|
|
4143
4632
|
);
|
|
4144
|
-
console.log(
|
|
4633
|
+
console.log(chalk8.gray(`Chunks received: ${chunkCount}`));
|
|
4145
4634
|
if (allWordAlignments.words.length > 0) {
|
|
4146
4635
|
console.log(
|
|
4147
|
-
|
|
4636
|
+
chalk8.gray(
|
|
4148
4637
|
`Word timestamps collected: ${allWordAlignments.words.length}`
|
|
4149
4638
|
)
|
|
4150
4639
|
);
|
|
4151
4640
|
}
|
|
4152
4641
|
if (allCharacterAlignments.characters.length > 0) {
|
|
4153
4642
|
console.log(
|
|
4154
|
-
|
|
4643
|
+
chalk8.gray(
|
|
4155
4644
|
`Character timestamps collected: ${allCharacterAlignments.characters.length}`
|
|
4156
4645
|
)
|
|
4157
4646
|
);
|
|
4158
4647
|
}
|
|
4159
4648
|
}
|
|
4160
4649
|
} else {
|
|
4161
|
-
console.log(
|
|
4162
|
-
if (options.format === "LINEAR16") {
|
|
4163
|
-
fileExtension = ".wav";
|
|
4164
|
-
} else if (options.format === "OGG_OPUS") {
|
|
4165
|
-
fileExtension = ".ogg";
|
|
4166
|
-
} else if (options.format === "ALAW" || options.format === "MULAW") {
|
|
4167
|
-
fileExtension = ".raw";
|
|
4168
|
-
} else {
|
|
4169
|
-
fileExtension = ".mp3";
|
|
4170
|
-
}
|
|
4650
|
+
console.log(chalk8.gray(`Format: ${format}`));
|
|
4171
4651
|
response = options.stats ? await ttsService.synthesizeSpeechWithMetrics(request) : await ttsService.synthesizeSpeech(request);
|
|
4172
4652
|
audioBuffer = Buffer.from(response.audioContent, "base64");
|
|
4173
4653
|
if (options.json) {
|
|
4174
4654
|
console.log(JSON.stringify(response, null, 2));
|
|
4175
4655
|
} else {
|
|
4176
|
-
|
|
4177
|
-
|
|
4178
|
-
);
|
|
4179
|
-
await writeFile(outputPath, audioBuffer);
|
|
4180
|
-
console.log(chalk4.green(`\u2705 Audio saved to: ${outputPath}`));
|
|
4656
|
+
await writeFile2(outputPath, audioBuffer);
|
|
4657
|
+
console.log(chalk8.green(`Audio saved to: ${outputPath}`));
|
|
4181
4658
|
console.log(
|
|
4182
|
-
|
|
4659
|
+
chalk8.gray(
|
|
4183
4660
|
`File size: ${(audioBuffer.length / 1024).toFixed(2)} KB`
|
|
4184
4661
|
)
|
|
4185
4662
|
);
|
|
@@ -4189,171 +4666,190 @@ var synthesizeCommand = new Command20("synthesize").description("Synthesize text
|
|
|
4189
4666
|
process.exit(0);
|
|
4190
4667
|
return;
|
|
4191
4668
|
}
|
|
4669
|
+
if (response.usage) {
|
|
4670
|
+
console.log(
|
|
4671
|
+
chalk8.gray(
|
|
4672
|
+
`Characters processed: ${response.usage.processedCharactersCount} (model: ${response.usage.modelId})`
|
|
4673
|
+
)
|
|
4674
|
+
);
|
|
4675
|
+
}
|
|
4192
4676
|
if (options.stats && response._metrics) {
|
|
4193
4677
|
const m = response._metrics;
|
|
4194
4678
|
const isStreaming = "timeToFirstChunk" in m;
|
|
4195
4679
|
if (isStreaming) {
|
|
4196
4680
|
const sm = m;
|
|
4681
|
+
console.log("\n" + chalk8.cyan("Streaming Performance Statistics:"));
|
|
4682
|
+
console.log(chalk8.gray("\u2550".repeat(50)));
|
|
4683
|
+
console.log(chalk8.bold.white("\n Streaming Timeline:"));
|
|
4684
|
+
console.log(chalk8.gray(" \u2500".repeat(23)));
|
|
4197
4685
|
console.log(
|
|
4198
|
-
"
|
|
4686
|
+
chalk8.white(" Time to First Chunk: ") + chalk8.yellow(`${sm.timeToFirstChunk.toFixed(0)} ms`)
|
|
4199
4687
|
);
|
|
4200
|
-
console.log(chalk4.gray("\u2550".repeat(50)));
|
|
4201
|
-
console.log(chalk4.bold.white("\n Streaming Timeline:"));
|
|
4202
|
-
console.log(chalk4.gray(" \u2500".repeat(23)));
|
|
4203
4688
|
console.log(
|
|
4204
|
-
|
|
4689
|
+
chalk8.white(" Total Stream Time: ") + chalk8.bold.yellow(`${sm.totalTime.toFixed(0)} ms`)
|
|
4205
4690
|
);
|
|
4691
|
+
console.log(chalk8.bold.white("\n Chunk Statistics:"));
|
|
4692
|
+
console.log(chalk8.gray(" \u2500".repeat(23)));
|
|
4206
4693
|
console.log(
|
|
4207
|
-
|
|
4208
|
-
);
|
|
4209
|
-
console.log(chalk4.bold.white("\n Chunk Statistics:"));
|
|
4210
|
-
console.log(chalk4.gray(" \u2500".repeat(23)));
|
|
4211
|
-
console.log(
|
|
4212
|
-
chalk4.white(" \u{1F4E6} Chunks Received: ") + chalk4.yellow(`${sm.chunksReceived}`)
|
|
4694
|
+
chalk8.white(" Chunks Received: ") + chalk8.yellow(`${sm.chunksReceived}`)
|
|
4213
4695
|
);
|
|
4214
4696
|
if (sm.errorChunks > 0) {
|
|
4215
4697
|
console.log(
|
|
4216
|
-
|
|
4698
|
+
chalk8.white(" Error Chunks: ") + chalk8.red(`${sm.errorChunks}`)
|
|
4217
4699
|
);
|
|
4218
4700
|
}
|
|
4219
4701
|
if (sm.chunkSizes.length > 0) {
|
|
4220
4702
|
const avgChunkSize = sm.chunkSizes.reduce((a, b) => a + b, 0) / sm.chunkSizes.length;
|
|
4221
|
-
const minChunkSize = Math.min(...sm.chunkSizes);
|
|
4222
|
-
const maxChunkSize = Math.max(...sm.chunkSizes);
|
|
4223
4703
|
console.log(
|
|
4224
|
-
|
|
4704
|
+
chalk8.white(" Avg Chunk Size: ") + chalk8.yellow(`${(avgChunkSize / 1024).toFixed(2)} KB`)
|
|
4225
4705
|
);
|
|
4226
4706
|
console.log(
|
|
4227
|
-
|
|
4228
|
-
`${(
|
|
4707
|
+
chalk8.gray(" Min/Max: ") + chalk8.gray(
|
|
4708
|
+
`${(Math.min(...sm.chunkSizes) / 1024).toFixed(2)} - ${(Math.max(...sm.chunkSizes) / 1024).toFixed(2)} KB`
|
|
4229
4709
|
)
|
|
4230
4710
|
);
|
|
4231
4711
|
}
|
|
4232
4712
|
if (sm.chunkIntervals.length > 0) {
|
|
4233
4713
|
const avgInterval = sm.chunkIntervals.reduce((a, b) => a + b, 0) / sm.chunkIntervals.length;
|
|
4234
|
-
const minInterval = Math.min(...sm.chunkIntervals);
|
|
4235
|
-
const maxInterval = Math.max(...sm.chunkIntervals);
|
|
4236
4714
|
console.log(
|
|
4237
|
-
|
|
4715
|
+
chalk8.white(" Avg Chunk Interval: ") + chalk8.yellow(`${avgInterval.toFixed(0)} ms`)
|
|
4238
4716
|
);
|
|
4239
4717
|
console.log(
|
|
4240
|
-
|
|
4241
|
-
`${
|
|
4718
|
+
chalk8.gray(" Min/Max: ") + chalk8.gray(
|
|
4719
|
+
`${Math.min(...sm.chunkIntervals).toFixed(0)} - ${Math.max(...sm.chunkIntervals).toFixed(0)} ms`
|
|
4242
4720
|
)
|
|
4243
4721
|
);
|
|
4244
4722
|
}
|
|
4245
|
-
console.log(
|
|
4246
|
-
console.log(
|
|
4723
|
+
console.log(chalk8.bold.white("\n Data Transfer:"));
|
|
4724
|
+
console.log(chalk8.gray(" \u2500".repeat(23)));
|
|
4247
4725
|
console.log(
|
|
4248
|
-
|
|
4726
|
+
chalk8.white(" Total Data: ") + chalk8.yellow(`${(sm.totalBytes / 1024).toFixed(2)} KB`)
|
|
4249
4727
|
);
|
|
4250
4728
|
console.log(
|
|
4251
|
-
|
|
4729
|
+
chalk8.white(" Audio File: ") + chalk8.yellow(
|
|
4252
4730
|
`${((audioBuffer?.length || 0) / 1024).toFixed(2)} KB`
|
|
4253
4731
|
)
|
|
4254
4732
|
);
|
|
4255
|
-
console.log(
|
|
4256
|
-
console.log(
|
|
4733
|
+
console.log(chalk8.bold.white("\n Performance Metrics:"));
|
|
4734
|
+
console.log(chalk8.gray(" \u2500".repeat(23)));
|
|
4257
4735
|
const throughputKBps = sm.totalBytes / 1024 / (sm.totalTime / 1e3);
|
|
4258
4736
|
console.log(
|
|
4259
|
-
|
|
4737
|
+
chalk8.white(" Stream Throughput: ") + chalk8.yellow(`${throughputKBps.toFixed(2)} KB/s`)
|
|
4260
4738
|
);
|
|
4261
4739
|
const audioDuration = (audioBuffer?.length || 0) / (128 * 125);
|
|
4262
4740
|
const realTimeRatio = audioDuration / (sm.totalTime / 1e3);
|
|
4263
4741
|
console.log(
|
|
4264
|
-
|
|
4742
|
+
chalk8.white(" Audio Duration: ") + chalk8.yellow(`${audioDuration.toFixed(2)} seconds`)
|
|
4265
4743
|
);
|
|
4266
4744
|
console.log(
|
|
4267
|
-
|
|
4745
|
+
chalk8.white(" Real-time Factor: ") + (realTimeRatio > 1 ? chalk8.green(`${realTimeRatio.toFixed(2)}x faster`) : chalk8.yellow(`${realTimeRatio.toFixed(2)}x`))
|
|
4268
4746
|
);
|
|
4269
4747
|
const streamingEfficiency = (sm.totalTime - sm.timeToFirstChunk) / sm.totalTime * 100;
|
|
4270
4748
|
console.log(
|
|
4271
|
-
|
|
4749
|
+
chalk8.white(" Stream Efficiency: ") + chalk8.yellow(`${streamingEfficiency.toFixed(1)}%`)
|
|
4272
4750
|
);
|
|
4273
|
-
console.log(
|
|
4751
|
+
console.log(chalk8.gray("\u2550".repeat(50)));
|
|
4274
4752
|
} else {
|
|
4275
|
-
console.log("\n" +
|
|
4276
|
-
console.log(
|
|
4277
|
-
console.log(
|
|
4278
|
-
console.log(
|
|
4753
|
+
console.log("\n" + chalk8.cyan("Performance Statistics:"));
|
|
4754
|
+
console.log(chalk8.gray("\u2550".repeat(50)));
|
|
4755
|
+
console.log(chalk8.bold.white("\n Network Timing:"));
|
|
4756
|
+
console.log(chalk8.gray(" \u2500".repeat(23)));
|
|
4279
4757
|
console.log(
|
|
4280
|
-
|
|
4758
|
+
chalk8.white(" Time to First Byte: ") + chalk8.yellow(`${m.ttfb.toFixed(0)} ms`)
|
|
4281
4759
|
);
|
|
4282
4760
|
if (m.downloadTime !== void 0) {
|
|
4283
4761
|
console.log(
|
|
4284
|
-
|
|
4762
|
+
chalk8.white(" Content Download: ") + chalk8.yellow(`${m.downloadTime.toFixed(0)} ms`)
|
|
4285
4763
|
);
|
|
4286
4764
|
}
|
|
4287
4765
|
console.log(
|
|
4288
|
-
|
|
4766
|
+
chalk8.white(" Total Time: ") + chalk8.bold.yellow(`${m.totalTime.toFixed(0)} ms`)
|
|
4289
4767
|
);
|
|
4290
|
-
console.log(
|
|
4291
|
-
console.log(
|
|
4768
|
+
console.log(chalk8.bold.white("\n Data Transfer:"));
|
|
4769
|
+
console.log(chalk8.gray(" \u2500".repeat(23)));
|
|
4292
4770
|
if (m.requestSize) {
|
|
4293
4771
|
console.log(
|
|
4294
|
-
|
|
4772
|
+
chalk8.white(" Request Size: ") + chalk8.yellow(`${(m.requestSize / 1024).toFixed(2)} KB`)
|
|
4295
4773
|
);
|
|
4296
4774
|
}
|
|
4297
4775
|
console.log(
|
|
4298
|
-
|
|
4776
|
+
chalk8.white(" Response Size: ") + chalk8.yellow(`${(m.responseSize / 1024).toFixed(2)} KB`)
|
|
4299
4777
|
);
|
|
4300
4778
|
console.log(
|
|
4301
|
-
|
|
4779
|
+
chalk8.white(" Audio File: ") + chalk8.yellow(
|
|
4302
4780
|
`${((audioBuffer?.length || 0) / 1024).toFixed(2)} KB`
|
|
4303
4781
|
)
|
|
4304
4782
|
);
|
|
4305
|
-
console.log(
|
|
4306
|
-
console.log(
|
|
4783
|
+
console.log(chalk8.bold.white("\n Performance Metrics:"));
|
|
4784
|
+
console.log(chalk8.gray(" \u2500".repeat(23)));
|
|
4307
4785
|
const audioDuration = (audioBuffer?.length || 0) / (128 * 125);
|
|
4308
4786
|
const realTimeRatio = audioDuration / (m.totalTime / 1e3);
|
|
4309
|
-
const serverTime = m.ttfb;
|
|
4310
4787
|
console.log(
|
|
4311
|
-
|
|
4788
|
+
chalk8.white(" Server Processing: ") + chalk8.yellow(`${Math.max(0, m.ttfb).toFixed(0)} ms`)
|
|
4312
4789
|
);
|
|
4313
4790
|
console.log(
|
|
4314
|
-
|
|
4791
|
+
chalk8.white(" Audio Duration: ") + chalk8.yellow(`${audioDuration.toFixed(2)} seconds`)
|
|
4315
4792
|
);
|
|
4316
4793
|
console.log(
|
|
4317
|
-
|
|
4794
|
+
chalk8.white(" Real-time Factor: ") + (realTimeRatio > 1 ? chalk8.green(`${realTimeRatio.toFixed(2)}x faster`) : chalk8.yellow(`${realTimeRatio.toFixed(2)}x`))
|
|
4318
4795
|
);
|
|
4319
4796
|
const throughputMbps = (m.responseSize + (audioBuffer?.length || 0)) * 8 / (m.totalTime * 1e3);
|
|
4320
4797
|
console.log(
|
|
4321
|
-
|
|
4798
|
+
chalk8.white(" Throughput: ") + chalk8.yellow(`${throughputMbps.toFixed(2)} Mbps`)
|
|
4322
4799
|
);
|
|
4323
|
-
console.log(
|
|
4800
|
+
console.log(chalk8.gray("\u2550".repeat(50)));
|
|
4324
4801
|
}
|
|
4325
4802
|
}
|
|
4326
4803
|
if (response.timestampInfo?.wordAlignment) {
|
|
4327
4804
|
const alignment = response.timestampInfo.wordAlignment;
|
|
4328
|
-
console.log("\n" +
|
|
4805
|
+
console.log("\n" + chalk8.cyan("Word Timestamps:"));
|
|
4329
4806
|
alignment.words.forEach((word, i) => {
|
|
4330
4807
|
const start = alignment.wordStartTimeSeconds[i].toFixed(3);
|
|
4331
4808
|
const end = alignment.wordEndTimeSeconds[i].toFixed(3);
|
|
4332
|
-
console.log(
|
|
4809
|
+
console.log(chalk8.gray(` ${start}s - ${end}s: ${word}`));
|
|
4333
4810
|
});
|
|
4811
|
+
if (alignment.phoneticDetails && alignment.phoneticDetails.length > 0) {
|
|
4812
|
+
console.log("\n" + chalk8.cyan("Phonetic Details (IPA + Visemes):"));
|
|
4813
|
+
for (const detail of alignment.phoneticDetails) {
|
|
4814
|
+
const viseme = detail.visemeSymbol ? chalk8.yellow(` [${detail.visemeSymbol}]`) : "";
|
|
4815
|
+
console.log(
|
|
4816
|
+
chalk8.gray(
|
|
4817
|
+
` ${detail.startTimeSeconds.toFixed(3)}s +${detail.durationSeconds.toFixed(3)}s: /${detail.phoneSymbol}/${viseme}`
|
|
4818
|
+
)
|
|
4819
|
+
);
|
|
4820
|
+
}
|
|
4821
|
+
}
|
|
4334
4822
|
}
|
|
4335
4823
|
if (response.timestampInfo?.characterAlignment) {
|
|
4336
|
-
console.log("\n" +
|
|
4824
|
+
console.log("\n" + chalk8.cyan("Character Timestamps:"));
|
|
4337
4825
|
console.log(
|
|
4338
|
-
|
|
4826
|
+
chalk8.gray(
|
|
4339
4827
|
" (Too detailed to display - use --json to see full data)"
|
|
4340
4828
|
)
|
|
4341
4829
|
);
|
|
4342
4830
|
}
|
|
4831
|
+
if (options.play && audioBuffer) {
|
|
4832
|
+
const played = await playFile(outputPath);
|
|
4833
|
+
if (!played) {
|
|
4834
|
+
console.log(chalk8.gray(`Playback unavailable. Open: ${outputPath}`));
|
|
4835
|
+
}
|
|
4836
|
+
}
|
|
4343
4837
|
process.exit(0);
|
|
4344
4838
|
} catch (error) {
|
|
4345
|
-
console.error(
|
|
4346
|
-
console.error(
|
|
4839
|
+
console.error(chalk8.red("Error synthesizing speech:"));
|
|
4840
|
+
console.error(chalk8.red(error.message || error));
|
|
4347
4841
|
process.exit(1);
|
|
4348
4842
|
}
|
|
4349
4843
|
});
|
|
4350
|
-
|
|
4844
|
+
|
|
4845
|
+
// src/commands/tts_commands.ts
|
|
4846
|
+
var ttsCommand = new Command24("tts").description("Text-to-speech functionality").addCommand(listVoicesCommand).addCommand(synthesizeCommand).addCommand(cloneCommand).addCommand(designCommand).action(() => {
|
|
4351
4847
|
ttsCommand.help();
|
|
4352
4848
|
});
|
|
4353
4849
|
|
|
4354
4850
|
// src/commands/workspace_command.ts
|
|
4355
|
-
import { Command as
|
|
4356
|
-
var selectWorkspaceCommand = new
|
|
4851
|
+
import { Command as Command25 } from "commander";
|
|
4852
|
+
var selectWorkspaceCommand = new Command25("select").description("Select a workspace for CLI operations").action(async () => {
|
|
4357
4853
|
await requireAuth();
|
|
4358
4854
|
try {
|
|
4359
4855
|
await WorkspaceService.activateWorkspace();
|
|
@@ -4363,7 +4859,35 @@ var selectWorkspaceCommand = new Command21("select").description("Select a works
|
|
|
4363
4859
|
process.exit(1);
|
|
4364
4860
|
}
|
|
4365
4861
|
});
|
|
4366
|
-
var
|
|
4862
|
+
var selectKeyCommand = new Command25("select-key").description("Select an API key for the current workspace").action(async () => {
|
|
4863
|
+
await requireAuth();
|
|
4864
|
+
try {
|
|
4865
|
+
await WorkspaceService.selectApiKey();
|
|
4866
|
+
process.exit(0);
|
|
4867
|
+
} catch (error) {
|
|
4868
|
+
printError(`
|
|
4869
|
+
Failed to select API key: ${error.message || error}`);
|
|
4870
|
+
process.exit(1);
|
|
4871
|
+
}
|
|
4872
|
+
});
|
|
4873
|
+
var addKeyCommand = new Command25("add-key").description(
|
|
4874
|
+
"Create a new API key (read-only by default, --write for read/write)"
|
|
4875
|
+
).option(
|
|
4876
|
+
"-w, --write",
|
|
4877
|
+
"Create with read/write permissions for voices and router"
|
|
4878
|
+
).option("-n, --name <name>", "Display name for the API key").action(async (options) => {
|
|
4879
|
+
await requireAuth();
|
|
4880
|
+
try {
|
|
4881
|
+
const mode = options.write ? "write" : "read";
|
|
4882
|
+
await WorkspaceService.createApiKey(mode, options.name);
|
|
4883
|
+
process.exit(0);
|
|
4884
|
+
} catch (error) {
|
|
4885
|
+
printError(`
|
|
4886
|
+
Failed to create API key: ${error.message || error}`);
|
|
4887
|
+
process.exit(1);
|
|
4888
|
+
}
|
|
4889
|
+
});
|
|
4890
|
+
var workspaceCommand = new Command25("workspace").description("Manage Inworld workspaces").alias("ws").addCommand(selectWorkspaceCommand).addCommand(selectKeyCommand).addCommand(addKeyCommand).action(() => {
|
|
4367
4891
|
workspaceCommand.help();
|
|
4368
4892
|
});
|
|
4369
4893
|
|
|
@@ -4496,7 +5020,7 @@ var InworldCLI = class {
|
|
|
4496
5020
|
program;
|
|
4497
5021
|
currentCommand = null;
|
|
4498
5022
|
constructor() {
|
|
4499
|
-
this.program = new
|
|
5023
|
+
this.program = new Command26();
|
|
4500
5024
|
this.setupProgram();
|
|
4501
5025
|
this.registerCommands();
|
|
4502
5026
|
}
|
|
@@ -4569,7 +5093,7 @@ var InworldCLI = class {
|
|
|
4569
5093
|
})
|
|
4570
5094
|
]);
|
|
4571
5095
|
const timeoutPromise = new Promise(
|
|
4572
|
-
(
|
|
5096
|
+
(resolve3) => setTimeout(resolve3, 1e3)
|
|
4573
5097
|
);
|
|
4574
5098
|
await Promise.race([initPromise, timeoutPromise]);
|
|
4575
5099
|
await this.program.parseAsync(args);
|
|
@@ -4580,7 +5104,7 @@ var InworldCLI = class {
|
|
|
4580
5104
|
analytics.trackCommandResult(this.currentCommand, false, errorMessage);
|
|
4581
5105
|
}
|
|
4582
5106
|
console.error(
|
|
4583
|
-
|
|
5107
|
+
chalk9.red("Error:"),
|
|
4584
5108
|
error instanceof Error ? error.message : String(error)
|
|
4585
5109
|
);
|
|
4586
5110
|
await analytics.flush();
|
|
@@ -4590,6 +5114,6 @@ var InworldCLI = class {
|
|
|
4590
5114
|
};
|
|
4591
5115
|
var cli = new InworldCLI();
|
|
4592
5116
|
cli.run().catch((error) => {
|
|
4593
|
-
console.error(
|
|
5117
|
+
console.error(chalk9.red("Fatal error:"), error);
|
|
4594
5118
|
process.exit(1);
|
|
4595
5119
|
});
|