@inworld/cli 0.2.15 → 0.3.0-rc.5
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 +1246 -544
- package/dist/index.js.map +4 -4
- package/dist/package.json +49 -0
- package/dist/proto/generated/portal/ai/inworld/language_codes/language_codes.pb.d.ts +10 -0
- package/dist/proto/generated/portal/ai/inworld/language_codes/language_codes.pb.d.ts.map +1 -0
- package/dist/proto/generated/portal/ai/inworld/language_codes/language_codes.pb.js +16 -0
- package/dist/proto/generated/portal/ai/inworld/language_codes/language_codes.pb.js.map +1 -0
- package/dist/proto/generated/portal/ai/inworld/studio/v1/errors.pb.d.ts +13 -0
- package/dist/proto/generated/portal/ai/inworld/studio/v1/errors.pb.d.ts.map +1 -0
- package/dist/proto/generated/portal/ai/inworld/studio/v1/errors.pb.js +2 -0
- package/dist/proto/generated/portal/ai/inworld/studio/v1/errors.pb.js.map +1 -0
- package/dist/proto/generated/portal/ai/inworld/studio/v1/operations.pb.d.ts +7 -0
- package/dist/proto/generated/portal/ai/inworld/studio/v1/operations.pb.d.ts.map +1 -0
- package/dist/proto/generated/portal/ai/inworld/studio/v1/operations.pb.js +15 -0
- package/dist/proto/generated/portal/ai/inworld/studio/v1/operations.pb.js.map +1 -0
- package/dist/proto/generated/portal/ai/inworld/studio/v1/remote/configuration/graph_configuration.pb.d.ts +14 -0
- package/dist/proto/generated/portal/ai/inworld/studio/v1/remote/configuration/graph_configuration.pb.d.ts.map +1 -0
- package/dist/proto/generated/portal/ai/inworld/studio/v1/remote/configuration/graph_configuration.pb.js +7 -0
- package/dist/proto/generated/portal/ai/inworld/studio/v1/remote/configuration/graph_configuration.pb.js.map +1 -0
- package/dist/proto/generated/portal/ai/inworld/studio/v1/remote/configuration/graphs.pb.d.ts +116 -0
- package/dist/proto/generated/portal/ai/inworld/studio/v1/remote/configuration/graphs.pb.d.ts.map +1 -0
- package/dist/proto/generated/portal/ai/inworld/studio/v1/remote/configuration/graphs.pb.js +71 -0
- package/dist/proto/generated/portal/ai/inworld/studio/v1/remote/configuration/graphs.pb.js.map +1 -0
- package/dist/proto/generated/portal/ai/inworld/studio/v1/remote/configuration/targeting.pb.d.ts +14 -0
- package/dist/proto/generated/portal/ai/inworld/studio/v1/remote/configuration/targeting.pb.d.ts.map +1 -0
- package/dist/proto/generated/portal/ai/inworld/studio/v1/remote/configuration/targeting.pb.js +7 -0
- package/dist/proto/generated/portal/ai/inworld/studio/v1/remote/configuration/targeting.pb.js.map +1 -0
- package/dist/proto/generated/portal/ai/inworld/studio/v1alpha/apikeys.pb.d.ts +76 -0
- package/dist/proto/generated/portal/ai/inworld/studio/v1alpha/apikeys.pb.d.ts.map +1 -0
- package/dist/proto/generated/portal/ai/inworld/studio/v1alpha/apikeys.pb.js +40 -0
- package/dist/proto/generated/portal/ai/inworld/studio/v1alpha/apikeys.pb.js.map +1 -0
- package/dist/proto/generated/portal/ai/inworld/studio/v1alpha/impression_event_data.pb.d.ts +10 -0
- package/dist/proto/generated/portal/ai/inworld/studio/v1alpha/impression_event_data.pb.d.ts.map +1 -0
- package/dist/proto/generated/portal/ai/inworld/studio/v1alpha/impression_event_data.pb.js +7 -0
- package/dist/proto/generated/portal/ai/inworld/studio/v1alpha/impression_event_data.pb.js.map +1 -0
- package/dist/proto/generated/portal/ai/inworld/studio/v1alpha/language_code.pb.d.ts +7 -0
- package/dist/proto/generated/portal/ai/inworld/studio/v1alpha/language_code.pb.d.ts.map +1 -0
- package/dist/proto/generated/portal/ai/inworld/studio/v1alpha/language_code.pb.js +13 -0
- package/dist/proto/generated/portal/ai/inworld/studio/v1alpha/language_code.pb.js.map +1 -0
- package/dist/proto/generated/portal/ai/inworld/studio/v1alpha/users.pb.d.ts +115 -0
- package/dist/proto/generated/portal/ai/inworld/studio/v1alpha/users.pb.d.ts.map +1 -0
- package/dist/proto/generated/portal/ai/inworld/studio/v1alpha/users.pb.js +86 -0
- package/dist/proto/generated/portal/ai/inworld/studio/v1alpha/users.pb.js.map +1 -0
- package/dist/proto/generated/portal/ai/inworld/studio/v1alpha/workspaces.pb.d.ts +255 -0
- package/dist/proto/generated/portal/ai/inworld/studio/v1alpha/workspaces.pb.d.ts.map +1 -0
- package/dist/proto/generated/portal/ai/inworld/studio/v1alpha/workspaces.pb.js +88 -0
- package/dist/proto/generated/portal/ai/inworld/studio/v1alpha/workspaces.pb.js.map +1 -0
- package/dist/proto/generated/portal/fetch.pb.d.ts +26 -0
- package/dist/proto/generated/portal/fetch.pb.d.ts.map +1 -0
- package/dist/proto/generated/portal/fetch.pb.js +274 -0
- package/dist/proto/generated/portal/fetch.pb.js.map +1 -0
- package/dist/src/auth/callback_server.d.ts +41 -0
- package/dist/src/auth/callback_server.d.ts.map +1 -0
- package/dist/src/auth/callback_server.js +136 -0
- package/dist/src/auth/callback_server.js.map +1 -0
- package/dist/src/auth/manager.d.ts +97 -0
- package/dist/src/auth/manager.d.ts.map +1 -0
- package/dist/src/auth/manager.js +340 -0
- package/dist/src/auth/manager.js.map +1 -0
- package/dist/src/auth/utils.d.ts +45 -0
- package/dist/src/auth/utils.d.ts.map +1 -0
- package/dist/src/auth/utils.js +183 -0
- package/dist/src/auth/utils.js.map +1 -0
- package/dist/src/commands/auth/disable_telemetry_command.d.ts +3 -0
- package/dist/src/commands/auth/disable_telemetry_command.d.ts.map +1 -0
- package/dist/src/commands/auth/enable_telemetry_command.d.ts +3 -0
- package/dist/src/commands/auth/enable_telemetry_command.d.ts.map +1 -0
- package/dist/src/commands/auth/login_ci_command.d.ts +3 -0
- package/dist/src/commands/auth/login_ci_command.d.ts.map +1 -0
- package/dist/src/commands/auth/login_ci_command.js +41 -0
- package/dist/src/commands/auth/login_ci_command.js.map +1 -0
- package/dist/src/commands/auth/login_command.d.ts +4 -0
- package/dist/src/commands/auth/login_command.d.ts.map +1 -0
- package/dist/src/commands/auth/login_command.js +134 -0
- package/dist/src/commands/auth/login_command.js.map +1 -0
- package/dist/src/commands/auth/logout_command.d.ts +4 -0
- package/dist/src/commands/auth/logout_command.d.ts.map +1 -0
- package/dist/src/commands/auth/logout_command.js +54 -0
- package/dist/src/commands/auth/logout_command.js.map +1 -0
- package/dist/src/commands/auth/print_access_token_command.d.ts +3 -0
- package/dist/src/commands/auth/print_access_token_command.d.ts.map +1 -0
- package/dist/src/commands/auth/print_access_token_command.js +21 -0
- package/dist/src/commands/auth/print_access_token_command.js.map +1 -0
- package/dist/src/commands/auth/print_api_key_command.d.ts +3 -0
- package/dist/src/commands/auth/print_api_key_command.d.ts.map +1 -0
- package/dist/src/commands/auth/print_api_key_command.js +26 -0
- package/dist/src/commands/auth/print_api_key_command.js.map +1 -0
- package/dist/src/commands/auth/status_command.d.ts +4 -0
- package/dist/src/commands/auth/status_command.d.ts.map +1 -0
- package/dist/src/commands/auth/status_command.js +84 -0
- package/dist/src/commands/auth/status_command.js.map +1 -0
- package/dist/src/commands/auth_command.d.ts +3 -0
- package/dist/src/commands/auth_command.d.ts.map +1 -0
- package/dist/src/commands/auth_command.js +20 -0
- package/dist/src/commands/auth_command.js.map +1 -0
- package/dist/src/commands/graph/graph_deploy_command.d.ts +24 -0
- package/dist/src/commands/graph/graph_deploy_command.d.ts.map +1 -0
- package/dist/src/commands/graph/graph_deploy_command.js +191 -0
- package/dist/src/commands/graph/graph_deploy_command.js.map +1 -0
- package/dist/src/commands/graph/graph_init_command.d.ts +4 -0
- package/dist/src/commands/graph/graph_init_command.d.ts.map +1 -0
- package/dist/src/commands/graph/graph_init_command.js +376 -0
- package/dist/src/commands/graph/graph_init_command.js.map +1 -0
- package/dist/src/commands/graph/graph_run_command.d.ts +24 -0
- package/dist/src/commands/graph/graph_run_command.d.ts.map +1 -0
- package/dist/src/commands/graph/graph_run_command.js +50 -0
- package/dist/src/commands/graph/graph_run_command.js.map +1 -0
- package/dist/src/commands/graph/graph_serve_command.d.ts +4 -0
- package/dist/src/commands/graph/graph_serve_command.d.ts.map +1 -0
- package/dist/src/commands/graph/graph_serve_command.js +40 -0
- package/dist/src/commands/graph/graph_serve_command.js.map +1 -0
- package/dist/src/commands/graph/graph_variant_command.d.ts +3 -0
- package/dist/src/commands/graph/graph_variant_command.d.ts.map +1 -0
- package/dist/src/commands/graph/graph_variant_command.js +13 -0
- package/dist/src/commands/graph/graph_variant_command.js.map +1 -0
- package/dist/src/commands/graph/graph_visualize_command.d.ts +7 -0
- package/dist/src/commands/graph/graph_visualize_command.d.ts.map +1 -0
- package/dist/src/commands/graph/graph_visualize_command.js +35 -0
- package/dist/src/commands/graph/graph_visualize_command.js.map +1 -0
- package/dist/src/commands/graph/variant/graph_variant_list_command.d.ts +3 -0
- package/dist/src/commands/graph/variant/graph_variant_list_command.d.ts.map +1 -0
- package/dist/src/commands/graph/variant/graph_variant_list_command.js +25 -0
- package/dist/src/commands/graph/variant/graph_variant_list_command.js.map +1 -0
- package/dist/src/commands/graph/variant/graph_variant_print_command.d.ts +7 -0
- package/dist/src/commands/graph/variant/graph_variant_print_command.d.ts.map +1 -0
- package/dist/src/commands/graph/variant/graph_variant_print_command.js +45 -0
- package/dist/src/commands/graph/variant/graph_variant_print_command.js.map +1 -0
- package/dist/src/commands/graph/variant/graph_variant_register_command.d.ts +3 -0
- package/dist/src/commands/graph/variant/graph_variant_register_command.d.ts.map +1 -0
- package/dist/src/commands/graph/variant/graph_variant_register_command.js +45 -0
- package/dist/src/commands/graph/variant/graph_variant_register_command.js.map +1 -0
- package/dist/src/commands/graph_command.d.ts +3 -0
- package/dist/src/commands/graph_command.d.ts.map +1 -0
- package/dist/src/commands/graph_command.js +20 -0
- package/dist/src/commands/graph_command.js.map +1 -0
- package/dist/src/commands/tts_commands.d.ts +17 -0
- package/dist/src/commands/tts_commands.d.ts.map +1 -0
- package/dist/src/commands/tts_commands.js +568 -0
- package/dist/src/commands/tts_commands.js.map +1 -0
- package/dist/src/commands/workspace_command.d.ts +12 -0
- package/dist/src/commands/workspace_command.d.ts.map +1 -0
- package/dist/src/commands/workspace_command.js +33 -0
- package/dist/src/commands/workspace_command.js.map +1 -0
- package/dist/src/constants.d.ts +10 -0
- package/dist/src/constants.d.ts.map +1 -0
- package/dist/src/constants.js +30 -0
- package/dist/src/constants.js.map +1 -0
- package/dist/src/grpc/core/InworldError.d.ts +30 -0
- package/dist/src/grpc/core/InworldError.d.ts.map +1 -0
- package/dist/src/grpc/core/InworldError.js +46 -0
- package/dist/src/grpc/core/InworldError.js.map +1 -0
- package/dist/src/grpc/core/statusCodes.d.ts +122 -0
- package/dist/src/grpc/core/statusCodes.d.ts.map +1 -0
- package/dist/src/grpc/core/statusCodes.js +133 -0
- package/dist/src/grpc/core/statusCodes.js.map +1 -0
- package/dist/src/index.d.ts +2 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/services/analytics.d.ts +45 -0
- package/dist/src/services/analytics.d.ts.map +1 -0
- package/dist/src/services/deploy_service.d.ts +4 -0
- package/dist/src/services/deploy_service.d.ts.map +1 -0
- package/dist/src/services/deploy_service.js +128 -0
- package/dist/src/services/deploy_service.js.map +1 -0
- package/dist/src/services/graph_loader.d.ts +7 -0
- package/dist/src/services/graph_loader.d.ts.map +1 -0
- package/dist/src/services/graph_loader.js +103 -0
- package/dist/src/services/graph_loader.js.map +1 -0
- package/dist/src/services/graph_variant_service.d.ts +12 -0
- package/dist/src/services/graph_variant_service.d.ts.map +1 -0
- package/dist/src/services/graph_variant_service.js +66 -0
- package/dist/src/services/graph_variant_service.js.map +1 -0
- package/dist/src/services/tts_service.d.ts +273 -0
- package/dist/src/services/tts_service.d.ts.map +1 -0
- package/dist/src/services/tts_service.js +299 -0
- package/dist/src/services/tts_service.js.map +1 -0
- package/dist/src/services/update_checker.d.ts +37 -0
- package/dist/src/services/update_checker.d.ts.map +1 -0
- package/dist/src/services/workspace_service.d.ts +47 -0
- package/dist/src/services/workspace_service.d.ts.map +1 -0
- package/dist/src/services/workspace_service.js +222 -0
- package/dist/src/services/workspace_service.js.map +1 -0
- package/dist/src/templates/llm_tts/graph.d.ts +2 -0
- package/dist/src/templates/llm_tts/graph.d.ts.map +1 -0
- package/dist/src/utils/array.d.ts +2 -0
- package/dist/src/utils/array.d.ts.map +1 -0
- package/dist/src/utils/array.js +4 -0
- package/dist/src/utils/array.js.map +1 -0
- package/dist/src/utils/confirm.d.ts +62 -0
- package/dist/src/utils/confirm.d.ts.map +1 -0
- package/dist/src/utils/confirm.js +90 -0
- package/dist/src/utils/confirm.js.map +1 -0
- package/dist/src/utils/long_running_operations.d.ts +38 -0
- package/dist/src/utils/long_running_operations.d.ts.map +1 -0
- package/dist/src/utils/long_running_operations.js +62 -0
- package/dist/src/utils/long_running_operations.js.map +1 -0
- package/dist/src/utils/resource_name_helper.d.ts +12 -0
- package/dist/src/utils/resource_name_helper.d.ts.map +1 -0
- package/dist/src/utils/resource_name_helper.js +29 -0
- package/dist/src/utils/resource_name_helper.js.map +1 -0
- package/dist/src/utils/selector.d.ts +62 -0
- package/dist/src/utils/selector.d.ts.map +1 -0
- package/dist/src/utils/selector.js +77 -0
- package/dist/src/utils/selector.js.map +1 -0
- package/dist/src/utils/spinner.d.ts +75 -0
- package/dist/src/utils/spinner.d.ts.map +1 -0
- package/dist/src/utils/spinner.js +178 -0
- package/dist/src/utils/spinner.js.map +1 -0
- package/dist/src/utils/ui.d.ts +27 -0
- package/dist/src/utils/ui.d.ts.map +1 -0
- package/dist/src/utils/ui.js +83 -0
- package/dist/src/utils/ui.js.map +1 -0
- package/dist/templates/llm_tts/graph.ts +8 -9
- package/package.json +5 -4
- package/dist/src/templates/simple/README.md +0 -106
- package/dist/src/templates/simple/graph.ts +0 -32
- package/dist/src/templates/simple/metadata.json +0 -26
- package/dist/templates/simple/README.md +0 -106
- package/dist/templates/simple/graph.ts +0 -32
- package/dist/templates/simple/metadata.json +0 -26
- package/src/templates/llm_tts/README.md +0 -155
- package/src/templates/llm_tts/graph.ts +0 -30
- package/src/templates/llm_tts/metadata.json +0 -41
- package/src/templates/simple/README.md +0 -106
- package/src/templates/simple/graph.ts +0 -32
- package/src/templates/simple/metadata.json +0 -26
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"graph_loader.d.ts","sourceRoot":"","sources":["../../../src/services/graph_loader.ts"],"names":[],"mappings":"AASA,eAAO,MAAM,SAAS,GAAU,MAAM,MAAM;;;;;EAiG3C,CAAC"}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import * as esbuild from 'esbuild';
|
|
2
|
+
import fs from 'fs';
|
|
3
|
+
import { Module } from 'module';
|
|
4
|
+
import path from 'path';
|
|
5
|
+
import { printError } from '@/utils/ui';
|
|
6
|
+
import { requireApiKey } from '@/auth/utils';
|
|
7
|
+
export const loadGraph = async (file) => {
|
|
8
|
+
process.env.INWORLD_API_KEY = await requireApiKey();
|
|
9
|
+
// Resolve the file path
|
|
10
|
+
const filePath = path.resolve(process.cwd(), file);
|
|
11
|
+
if (!fs.existsSync(filePath)) {
|
|
12
|
+
console.error(`Error: File not found: ${filePath}`);
|
|
13
|
+
process.exit(1);
|
|
14
|
+
}
|
|
15
|
+
console.log(`Packaging graph from: ${filePath}`);
|
|
16
|
+
// Find the nearest package.json
|
|
17
|
+
const packageJsonPath = findNearestPackageJson(path.dirname(filePath));
|
|
18
|
+
if (!packageJsonPath) {
|
|
19
|
+
console.error('Error: No package.json found in the project hierarchy');
|
|
20
|
+
console.error('Please ensure your graph file is in a proper Node.js project');
|
|
21
|
+
process.exit(1);
|
|
22
|
+
}
|
|
23
|
+
console.log(`Using package.json from: ${packageJsonPath}`);
|
|
24
|
+
const originalPackageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf-8'));
|
|
25
|
+
// Bundle the module with local files
|
|
26
|
+
console.log('Bundling graph module with local dependencies...');
|
|
27
|
+
let bundledCode;
|
|
28
|
+
let module;
|
|
29
|
+
if (!filePath.endsWith('.ts') && !filePath.endsWith('.js')) {
|
|
30
|
+
console.error('Error: File must be a .ts or .js file');
|
|
31
|
+
process.exit(1);
|
|
32
|
+
}
|
|
33
|
+
// Use esbuild to bundle local files together
|
|
34
|
+
const result = await esbuild.build({
|
|
35
|
+
entryPoints: [filePath],
|
|
36
|
+
bundle: true,
|
|
37
|
+
platform: 'node',
|
|
38
|
+
loader: { '.ts': 'ts', '.js': 'js' },
|
|
39
|
+
target: 'node18',
|
|
40
|
+
format: 'cjs',
|
|
41
|
+
// Keep all npm packages external - they'll be installed via package.json
|
|
42
|
+
packages: 'external',
|
|
43
|
+
sourcemap: 'inline',
|
|
44
|
+
write: false,
|
|
45
|
+
logLevel: 'error',
|
|
46
|
+
resolveExtensions: ['.ts', '.tsx', '.js', '.jsx', '.json'],
|
|
47
|
+
keepNames: true,
|
|
48
|
+
minify: false,
|
|
49
|
+
});
|
|
50
|
+
bundledCode = result.outputFiles[0].text;
|
|
51
|
+
// Validate that the bundled module exports a graph
|
|
52
|
+
const moduleInstance = new Module(filePath, module);
|
|
53
|
+
moduleInstance.filename = filePath;
|
|
54
|
+
moduleInstance.paths = Module._nodeModulePaths(path.dirname(filePath));
|
|
55
|
+
// Compile and evaluate with proper module resolution
|
|
56
|
+
moduleInstance._compile(bundledCode, filePath);
|
|
57
|
+
module = moduleInstance.exports;
|
|
58
|
+
// Validate that the module exports a graph
|
|
59
|
+
if (!module.graph) {
|
|
60
|
+
console.error('Error: The file must export a "graph" object');
|
|
61
|
+
process.exit(1);
|
|
62
|
+
}
|
|
63
|
+
const graphId = module.graph.graphId;
|
|
64
|
+
// Validate that the graphId is alphanumeric, dashes, or underscores
|
|
65
|
+
if (typeof graphId !== 'string' || !/^[a-zA-Z0-9_-]+$/.test(graphId)) {
|
|
66
|
+
printError('Error: Graph id must be a string containing only alphanumeric (latin) characters, dashes, or underscores.');
|
|
67
|
+
process.exit(1);
|
|
68
|
+
}
|
|
69
|
+
// FIXME: validate graph module.
|
|
70
|
+
// if (!(module.graph instanceof Graph)) {
|
|
71
|
+
// console.error(
|
|
72
|
+
// 'Error: The exported "graph" must be an instance of Inworld Runtime Graph class',
|
|
73
|
+
// );
|
|
74
|
+
// process.exit(1);
|
|
75
|
+
// }
|
|
76
|
+
return {
|
|
77
|
+
graph: module.graph,
|
|
78
|
+
bundledCode,
|
|
79
|
+
originalPackageJson,
|
|
80
|
+
packageJsonPath,
|
|
81
|
+
};
|
|
82
|
+
};
|
|
83
|
+
/**
|
|
84
|
+
* Find the nearest package.json file by traversing up the directory tree
|
|
85
|
+
*/
|
|
86
|
+
function findNearestPackageJson(startDir) {
|
|
87
|
+
let currentDir = startDir;
|
|
88
|
+
const root = path.parse(currentDir).root;
|
|
89
|
+
while (currentDir !== root) {
|
|
90
|
+
const packageJsonPath = path.join(currentDir, 'package.json');
|
|
91
|
+
if (fs.existsSync(packageJsonPath)) {
|
|
92
|
+
return packageJsonPath;
|
|
93
|
+
}
|
|
94
|
+
currentDir = path.dirname(currentDir);
|
|
95
|
+
}
|
|
96
|
+
// Check root directory as well
|
|
97
|
+
const rootPackageJson = path.join(root, 'package.json');
|
|
98
|
+
if (fs.existsSync(rootPackageJson)) {
|
|
99
|
+
return rootPackageJson;
|
|
100
|
+
}
|
|
101
|
+
return null;
|
|
102
|
+
}
|
|
103
|
+
//# sourceMappingURL=graph_loader.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"graph_loader.js","sourceRoot":"","sources":["../../../src/services/graph_loader.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,OAAO,MAAM,SAAS,CAAC;AACnC,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB,OAAO,EAAC,UAAU,EAAC,MAAM,YAAY,CAAA;AAErC,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAE7C,MAAM,CAAC,MAAM,SAAS,GAAG,KAAK,EAAE,IAAY,EAAE,EAAE;IAC9C,OAAO,CAAC,GAAG,CAAC,eAAe,GAAG,MAAM,aAAa,EAAE,CAAC;IAEpD,wBAAwB;I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,CAAC,OAAO,CAAC,EAAE,CAAC;QACrE,UAAU,CAAC,2GAA2G,CAAC,CAAA;QACvH,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;IAED,gCAAgC;IAChC,0CAA0C;IAC1C,mBAAmB;IACnB,wFAAwF;IACxF,OAAO;IACP,qBAAqB;IACrB,IAAI;IAEJ,OAAO;QACL,KAAK,EAAE,MAAM,CAAC,KAAK;QACnB,WAAW;QACX,mBAAmB;QACnB,eAAe;KAChB,CAAC;AACJ,CAAC,CAAC;AAEF;;GAEG;AACH,SAAS,sBAAsB,CAAC,QAAgB;IAC9C,IAAI,UAAU,GAAG,QAAQ,CAAC;IAC1B,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,IAAI,CAAC;IAEzC,OAAO,UAAU,KAAK,IAAI,EAAE,CAAC;QAC3B,MAAM,eAAe,GAAG,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,cAAc,CAAC,CAAC;QAC9D,IAAI,EAAE,CAAC,UAAU,CAAC,eAAe,CAAC,EAAE,CAAC;YACnC,OAAO,eAAe,CAAC;QACzB,CAAC;QACD,UAAU,GAAG,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;IACxC,CAAC;IAED,+BAA+B;IAC/B,MAAM,eAAe,GAAG,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,cAAc,CAAC,CAAC;IACxD,IAAI,EAAE,CAAC,UAAU,CAAC,eAAe,CAAC,EAAE,CAAC;QACnC,OAAO,eAAe,CAAC;IACzB,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export declare const listGraphVariants: (graphId: string) => Promise<import("@/proto/generated/portal/ai/inworld/studio/v1/remote/configuration/graphs.pb").ListGraphVariantsResponse | undefined>;
|
|
2
|
+
/**
|
|
3
|
+
* Converts the input string to a string containing only alphanumeric characters,
|
|
4
|
+
* dashes, and underscores. Spaces are replaced with underscores, all other
|
|
5
|
+
* non-alphanumeric/dash/underscore characters are removed, and the result is lowercased.
|
|
6
|
+
*
|
|
7
|
+
* @param input - The string to sanitize.
|
|
8
|
+
* @returns The sanitized, lowercased string containing only [a-z0-9-_], with spaces replaced by underscores.
|
|
9
|
+
*/
|
|
10
|
+
export declare function toAlphanumericDashUnderscore(input: string): string;
|
|
11
|
+
export declare const registerGraphVariant: (graphId: string, variantDisplayName: string, variantConfig: string, force?: boolean) => Promise<unknown>;
|
|
12
|
+
//# sourceMappingURL=graph_variant_service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"graph_variant_service.d.ts","sourceRoot":"","sources":["../../../src/services/graph_variant_service.ts"],"names":[],"mappings":"AASA,eAAO,MAAM,iBAAiB,GAAU,SAAS,MAAM,0IAMtD,CAAC;AAEF;;;;;;;GAOG;AACH,wBAAgB,4BAA4B,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAKlE;AAED,eAAO,MAAM,oBAAoB,GAC/B,SAAS,MAAM,EACf,oBAAoB,MAAM,EAC1B,eAAe,MAAM,EACrB,QAAO,OAAe,qBAoDvB,CAAC"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { GraphsService } from '@/proto/generated/portal/ai/inworld/studio/v1/remote/configuration/graphs.pb';
|
|
2
|
+
import { authenticatedInworldRequest, requireWorkspace } from '@/auth/utils';
|
|
3
|
+
import { checkLRO } from '@/utils/long_running_operations';
|
|
4
|
+
import { getGraphResourceName, getGraphVariantResourceName, } from '@/utils/resource_name_helper';
|
|
5
|
+
import { ensureGraphRegistered } from './deploy_service';
|
|
6
|
+
export const listGraphVariants = async (graphId) => {
|
|
7
|
+
const workspaceId = await requireWorkspace();
|
|
8
|
+
const graphResourceName = getGraphResourceName(workspaceId, graphId);
|
|
9
|
+
return await authenticatedInworldRequest(GraphsService.ListGraphVariants, {
|
|
10
|
+
parent: graphResourceName,
|
|
11
|
+
});
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* Converts the input string to a string containing only alphanumeric characters,
|
|
15
|
+
* dashes, and underscores. Spaces are replaced with underscores, all other
|
|
16
|
+
* non-alphanumeric/dash/underscore characters are removed, and the result is lowercased.
|
|
17
|
+
*
|
|
18
|
+
* @param input - The string to sanitize.
|
|
19
|
+
* @returns The sanitized, lowercased string containing only [a-z0-9-_], with spaces replaced by underscores.
|
|
20
|
+
*/
|
|
21
|
+
export function toAlphanumericDashUnderscore(input) {
|
|
22
|
+
return input
|
|
23
|
+
.replace(/\s+/g, '_') // Replace spaces with underscores
|
|
24
|
+
.replace(/[^a-zA-Z0-9-_]/g, '') // Remove all non-alphanumeric, non-dash, non-underscore
|
|
25
|
+
.toLowerCase(); // Convert to lowercase
|
|
26
|
+
}
|
|
27
|
+
export const registerGraphVariant = async (graphId, variantDisplayName, variantConfig, force = false) => {
|
|
28
|
+
const request = force
|
|
29
|
+
? GraphsService.UpdateGraphVariant
|
|
30
|
+
: GraphsService.CreateGraphVariant;
|
|
31
|
+
const workspaceId = await requireWorkspace();
|
|
32
|
+
const graphResourceName = getGraphResourceName(workspaceId, graphId);
|
|
33
|
+
const variantResourceName = getGraphVariantResourceName(workspaceId, graphId, toAlphanumericDashUnderscore(variantDisplayName));
|
|
34
|
+
await ensureGraphRegistered(workspaceId, graphId);
|
|
35
|
+
try {
|
|
36
|
+
const operation = await authenticatedInworldRequest(request, {
|
|
37
|
+
parent: graphResourceName,
|
|
38
|
+
graphVariant: {
|
|
39
|
+
config: {
|
|
40
|
+
rawContent: variantConfig,
|
|
41
|
+
},
|
|
42
|
+
displayName: variantDisplayName,
|
|
43
|
+
name: variantResourceName,
|
|
44
|
+
graph: graphResourceName,
|
|
45
|
+
},
|
|
46
|
+
});
|
|
47
|
+
await checkLRO({ operationName: operation.name });
|
|
48
|
+
const graph = await ensureGraphRegistered(workspaceId, graphId);
|
|
49
|
+
if (graph && graph.targeting?.rawContent === '{}') {
|
|
50
|
+
console.log(`Graph "${graphId}" has no targeting, setting up registered variant as default...`);
|
|
51
|
+
// graph has no targeting, so we need to setup registered variant as default.
|
|
52
|
+
const operation = await authenticatedInworldRequest(GraphsService.UpdateGraph, {
|
|
53
|
+
graph: {
|
|
54
|
+
...graph,
|
|
55
|
+
targeting: { rawContent: `{"if": ["${variantResourceName}"]}` },
|
|
56
|
+
},
|
|
57
|
+
});
|
|
58
|
+
await checkLRO({ operationName: operation.name });
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
catch (error) {
|
|
62
|
+
return error;
|
|
63
|
+
}
|
|
64
|
+
return true;
|
|
65
|
+
};
|
|
66
|
+
//# sourceMappingURL=graph_variant_service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"graph_variant_service.js","sourceRoot":"","sources":["../../../src/services/graph_variant_service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,8EAA8E,CAAC;AAC7G,OAAO,EAAE,2BAA2B,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAC7E,OAAO,EAAE,QAAQ,EAAE,MAAM,iCAAiC,CAAC;AAC3D,OAAO,EACL,oBAAoB,EACpB,2BAA2B,GAC5B,MAAM,8BAA8B,CAAC;AACtC,OAAO,EAAE,qBAAqB,EAAE,MAAM,kBAAkB,CAAC;AAEzD,MAAM,CAAC,MAAM,iBAAiB,GAAG,KAAK,EAAE,OAAe,EAAE,EAAE;IACzD,MAAM,WAAW,GAAG,MAAM,gBAAgB,EAAE,CAAC;IAC7C,MAAM,iBAAiB,GAAG,oBAAoB,CAAC,WAAW,EAAE,OAAO,CAAC,CAAC;IACrE,OAAO,MAAM,2BAA2B,CAAC,aAAa,CAAC,iBAAiB,EAAE;QACxE,MAAM,EAAE,iBAAiB;KAC1B,CAAC,CAAC;AACL,CAAC,CAAC;AAEF;;;;;;;GAOG;AACH,MAAM,UAAU,4BAA4B,CAAC,KAAa;IACxD,OAAO,KAAK;SACT,OAAO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AC;YACF,6EAA6E;YAC7E,MAAM,SAAS,GAAG,MAAM,2BAA2B,CACjD,aAAa,CAAC,WAAW,EACzB;gBACE,KAAK,EAAE;oBACL,GAAG,KAAK;oBACR,SAAS,EAAE,EAAE,UAAU,EAAE,YAAY,mBAAmB,KAAK,EAAE;iBAChE;aACF,CACF,CAAC;YACF,MAAM,QAAQ,CAAC,EAAE,aAAa,EAAE,SAAS,CAAC,IAAI,EAAE,CAAC,CAAC;QACpD,CAAC;IACH,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,KAAK,CAAC;IACf,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC,CAAC"}
|
|
@@ -0,0 +1,273 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Audio encoding options for TTS
|
|
3
|
+
* @see {@link https://api.inworld.ai/docs/models#tts}
|
|
4
|
+
*/
|
|
5
|
+
export declare enum AudioEncoding {
|
|
6
|
+
LINEAR16 = "LINEAR16",
|
|
7
|
+
MP3 = "MP3",
|
|
8
|
+
OGG_OPUS = "OGG_OPUS",
|
|
9
|
+
ALAW = "ALAW",
|
|
10
|
+
MULAW = "MULAW"
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Available TTS models
|
|
14
|
+
* @see {@link https://api.inworld.ai/docs/models#tts}
|
|
15
|
+
*/
|
|
16
|
+
export declare enum TTSModel {
|
|
17
|
+
INWORLD_TTS_1 = "inworld-tts-1",
|
|
18
|
+
INWORLD_TTS_1_MAX = "inworld-tts-1-max"
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Timestamp types for alignment data
|
|
22
|
+
*/
|
|
23
|
+
export declare enum TimestampType {
|
|
24
|
+
UNSPECIFIED = "TIMESTAMP_TYPE_UNSPECIFIED",
|
|
25
|
+
WORD = "WORD",
|
|
26
|
+
CHARACTER = "CHARACTER"
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Audio configuration for TTS synthesis
|
|
30
|
+
* @description Configurations to use when synthesizing speech
|
|
31
|
+
*/
|
|
32
|
+
export interface AudioConfig {
|
|
33
|
+
/** The desired output format of the synthesized audio. Defaults to MP3. */
|
|
34
|
+
audioEncoding?: AudioEncoding;
|
|
35
|
+
/** Bits per second of the audio. Only for compressed audio formats (MP3, OGG_OPUS). Default is 128,000. */
|
|
36
|
+
bitRate?: number;
|
|
37
|
+
/** The synthesis sample rate (in hertz) for this audio. Accepts values within the range [8000, 48000]. Default is 48,000. */
|
|
38
|
+
sampleRateHertz?: number;
|
|
39
|
+
/** Modifies the pitch of the synthesized speech. Range [-5.0, 5.0]. 0.0 is original pitch. Default is 0.0. */
|
|
40
|
+
pitch?: number;
|
|
41
|
+
/** Speaking rate/speed, in the range [0.5, 1.5]. Not supported for streaming. Default is 1.0. */
|
|
42
|
+
speakingRate?: number;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Request options for synthesizing speech
|
|
46
|
+
* @description Parameters for the TTS synthesis request
|
|
47
|
+
*/
|
|
48
|
+
export interface SynthesizeSpeechRequest {
|
|
49
|
+
/** The text to be synthesized into speech. Maximum input of 2,000 characters. */
|
|
50
|
+
text: string;
|
|
51
|
+
/** The ID of the voice to use for synthesizing speech. */
|
|
52
|
+
voiceId: string;
|
|
53
|
+
/** The ID of the model to use for synthesizing speech. */
|
|
54
|
+
modelId: TTSModel;
|
|
55
|
+
/** Audio configuration options. */
|
|
56
|
+
audioConfig?: AudioConfig;
|
|
57
|
+
/** Determines the degree of randomness when sampling audio tokens. Range [0, 2]. Default is 0.8. */
|
|
58
|
+
temperature?: number;
|
|
59
|
+
/** Controls timestamp metadata returned with the audio. */
|
|
60
|
+
timestampType?: TimestampType;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Word alignment information
|
|
64
|
+
* @description Word-level timestamp alignment data
|
|
65
|
+
*/
|
|
66
|
+
export interface WordAlignment {
|
|
67
|
+
/** Aligned words in order. */
|
|
68
|
+
words: string[];
|
|
69
|
+
/** Start time for each word in seconds from the beginning of the audio. */
|
|
70
|
+
wordStartTimeSeconds: number[];
|
|
71
|
+
/** End time for each word in seconds from the beginning of the audio. */
|
|
72
|
+
wordEndTimeSeconds: number[];
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Character alignment information
|
|
76
|
+
* @description Character-level timestamp alignment data
|
|
77
|
+
*/
|
|
78
|
+
export interface CharacterAlignment {
|
|
79
|
+
/** Aligned characters (including punctuation and spaces) in order. */
|
|
80
|
+
characters: string[];
|
|
81
|
+
/** Start time for each character in seconds from the beginning of the audio. */
|
|
82
|
+
characterStartTimeSeconds: number[];
|
|
83
|
+
/** End time for each character in seconds from the beginning of the audio. */
|
|
84
|
+
characterEndTimeSeconds: number[];
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Timestamp information for synthesized speech
|
|
88
|
+
* @description Alignment information present when alignment is enabled
|
|
89
|
+
*/
|
|
90
|
+
export interface TimestampInfo {
|
|
91
|
+
/** Word-level alignment when timestampType is WORD. */
|
|
92
|
+
wordAlignment?: WordAlignment;
|
|
93
|
+
/** Character-level alignment when timestampType is CHARACTER. */
|
|
94
|
+
characterAlignment?: CharacterAlignment;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Response from synthesizing speech
|
|
98
|
+
* @description The response containing the synthesized audio and optional timestamp information
|
|
99
|
+
*/
|
|
100
|
+
export interface SynthesizeSpeechResponse {
|
|
101
|
+
/** The audio data bytes encoded in the format specified in the request. Base64 encoded. */
|
|
102
|
+
audioContent: string;
|
|
103
|
+
/** Timestamp alignment information (present when alignment is enabled). */
|
|
104
|
+
timestampInfo?: TimestampInfo;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Voice information
|
|
108
|
+
* @description Information about an available TTS voice
|
|
109
|
+
*/
|
|
110
|
+
export interface Voice {
|
|
111
|
+
/** The language(s) of the original voice audio. */
|
|
112
|
+
languages: string[];
|
|
113
|
+
/** The ID of the voice. */
|
|
114
|
+
voiceId: string;
|
|
115
|
+
/** The display name of the voice. */
|
|
116
|
+
displayName?: string;
|
|
117
|
+
/** The description of the voice. */
|
|
118
|
+
description?: string;
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Response from listing voices
|
|
122
|
+
* @description The response containing the list of available voices
|
|
123
|
+
*/
|
|
124
|
+
export interface ListVoicesResponse {
|
|
125
|
+
/** The list of voices. */
|
|
126
|
+
voices: Voice[];
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Error response from the API
|
|
130
|
+
* @description Standard error response format
|
|
131
|
+
*/
|
|
132
|
+
export interface ErrorResponse {
|
|
133
|
+
/** The error code, as specified by gRPC status codes. */
|
|
134
|
+
code: number;
|
|
135
|
+
/** A short description of the error. */
|
|
136
|
+
message: string;
|
|
137
|
+
/** Additional error details. */
|
|
138
|
+
details?: any[];
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Request performance metrics
|
|
142
|
+
* @description Timing and size metrics for API requests
|
|
143
|
+
*/
|
|
144
|
+
export interface RequestMetrics {
|
|
145
|
+
/** Time when the request started (ms) */
|
|
146
|
+
startTime: number;
|
|
147
|
+
/** Time to first byte (ms) */
|
|
148
|
+
ttfb: number;
|
|
149
|
+
/** Total request time (ms) */
|
|
150
|
+
totalTime: number;
|
|
151
|
+
/** Estimated response size in bytes */
|
|
152
|
+
responseSize: number;
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Streaming performance metrics
|
|
156
|
+
* @description Timing and chunk metrics for streaming requests
|
|
157
|
+
*/
|
|
158
|
+
export interface StreamingMetrics {
|
|
159
|
+
/** Time when the request started (ms) */
|
|
160
|
+
startTime: number;
|
|
161
|
+
/** Time to first chunk (ms) */
|
|
162
|
+
timeToFirstChunk: number;
|
|
163
|
+
/** Total streaming time (ms) */
|
|
164
|
+
totalTime: number;
|
|
165
|
+
/** Number of chunks received */
|
|
166
|
+
chunksReceived: number;
|
|
167
|
+
/** Total bytes received */
|
|
168
|
+
totalBytes: number;
|
|
169
|
+
/** Individual chunk sizes */
|
|
170
|
+
chunkSizes: number[];
|
|
171
|
+
/** Time between chunks (ms) */
|
|
172
|
+
chunkIntervals: number[];
|
|
173
|
+
/** Error chunks received */
|
|
174
|
+
errorChunks: number;
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* TTS Service for interacting with Inworld's Text-to-Speech API
|
|
178
|
+
* @description Provides methods for listing voices and synthesizing speech
|
|
179
|
+
*/
|
|
180
|
+
export declare class TTSService {
|
|
181
|
+
private apiKey;
|
|
182
|
+
/**
|
|
183
|
+
* Ensures the API key is available
|
|
184
|
+
* @private
|
|
185
|
+
*/
|
|
186
|
+
private ensureApiKey;
|
|
187
|
+
/**
|
|
188
|
+
* Makes an authenticated request to the Inworld API
|
|
189
|
+
* @private
|
|
190
|
+
*/
|
|
191
|
+
private makeRequest;
|
|
192
|
+
/**
|
|
193
|
+
* Lists all available voices based on the provided filter
|
|
194
|
+
* @param filter - Optional filter expression (e.g., "language=en")
|
|
195
|
+
* @returns Promise resolving to the list of available voices
|
|
196
|
+
* @example
|
|
197
|
+
* ```typescript
|
|
198
|
+
* const ttsService = new TTSService();
|
|
199
|
+
* const voices = await ttsService.listVoices('language=en');
|
|
200
|
+
* console.log(voices.voices);
|
|
201
|
+
* ```
|
|
202
|
+
*/
|
|
203
|
+
listVoices(filter?: string): Promise<ListVoicesResponse>;
|
|
204
|
+
/**
|
|
205
|
+
* Synthesizes speech from text
|
|
206
|
+
* @param request - The synthesis request parameters
|
|
207
|
+
* @returns Promise resolving to the synthesized audio data and optional timestamp information
|
|
208
|
+
* @example
|
|
209
|
+
* ```typescript
|
|
210
|
+
* const ttsService = new TTSService();
|
|
211
|
+
* const result = await ttsService.synthesizeSpeech({
|
|
212
|
+
* text: 'Hello, world!',
|
|
213
|
+
* voiceId: 'Dennis',
|
|
214
|
+
* modelId: TTSModel.INWORLD_TTS_1,
|
|
215
|
+
* timestampType: TimestampType.WORD,
|
|
216
|
+
* });
|
|
217
|
+
* // result.audioContent is base64 encoded audio data
|
|
218
|
+
* ```
|
|
219
|
+
*/
|
|
220
|
+
synthesizeSpeech(request: SynthesizeSpeechRequest): Promise<SynthesizeSpeechResponse>;
|
|
221
|
+
/**
|
|
222
|
+
* Synthesizes speech from text with performance metrics
|
|
223
|
+
* @param request - The synthesis request parameters
|
|
224
|
+
* @returns Promise resolving to the synthesized audio data with metrics
|
|
225
|
+
*/
|
|
226
|
+
synthesizeSpeechWithMetrics(request: SynthesizeSpeechRequest): Promise<SynthesizeSpeechResponse & {
|
|
227
|
+
_metrics?: RequestMetrics;
|
|
228
|
+
}>;
|
|
229
|
+
/**
|
|
230
|
+
* Synthesizes speech using streaming API
|
|
231
|
+
* @param request - The synthesis request parameters
|
|
232
|
+
* @param onChunk - Callback for each audio chunk received
|
|
233
|
+
* @param trackMetrics - Whether to track streaming metrics
|
|
234
|
+
* @returns Promise resolving when stream completes, with optional metrics
|
|
235
|
+
*/
|
|
236
|
+
synthesizeSpeechStream(request: SynthesizeSpeechRequest, onChunk: (chunk: {
|
|
237
|
+
audioContent?: string;
|
|
238
|
+
timestampInfo?: TimestampInfo;
|
|
239
|
+
error?: ErrorResponse;
|
|
240
|
+
}) => void, trackMetrics?: boolean): Promise<{
|
|
241
|
+
_metrics?: StreamingMetrics;
|
|
242
|
+
}>;
|
|
243
|
+
/**
|
|
244
|
+
* Helper method to synthesize speech with simple parameters
|
|
245
|
+
* @param text - The text to synthesize
|
|
246
|
+
* @param voiceId - The voice ID to use
|
|
247
|
+
* @param modelId - The model ID to use (defaults to inworld-tts-1-max)
|
|
248
|
+
* @returns Promise resolving to the synthesized audio data
|
|
249
|
+
* @example
|
|
250
|
+
* ```typescript
|
|
251
|
+
* const ttsService = new TTSService();
|
|
252
|
+
* const result = await ttsService.synthesize('Hello, world!', 'Dennis');
|
|
253
|
+
* const audioBuffer = Buffer.from(result.audioContent, 'base64');
|
|
254
|
+
* ```
|
|
255
|
+
*/
|
|
256
|
+
synthesize(text: string, voiceId: string, modelId?: TTSModel): Promise<SynthesizeSpeechResponse>;
|
|
257
|
+
/**
|
|
258
|
+
* Saves synthesized audio to a file
|
|
259
|
+
* @param audioContent - Base64 encoded audio content
|
|
260
|
+
* @param filepath - Path where the audio file should be saved
|
|
261
|
+
* @returns Promise that resolves when the file is written
|
|
262
|
+
* @example
|
|
263
|
+
* ```typescript
|
|
264
|
+
* const ttsService = new TTSService();
|
|
265
|
+
* const result = await ttsService.synthesize('Hello, world!', 'Dennis');
|
|
266
|
+
* await ttsService.saveAudioToFile(result.audioContent, 'output.mp3');
|
|
267
|
+
* ```
|
|
268
|
+
*/
|
|
269
|
+
saveAudioToFile(audioContent: string, filepath: string): Promise<void>;
|
|
270
|
+
}
|
|
271
|
+
export declare const ttsService: TTSService;
|
|
272
|
+
export declare const synthesizeSpeech: (text: string, voice: string) => Promise<SynthesizeSpeechResponse>;
|
|
273
|
+
//# sourceMappingURL=tts_service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tts_service.d.ts","sourceRoot":"","sources":["../../../src/services/tts_service.ts"],"names":[],"mappings":"AAGA;;;GAGG;AACH,oBAAY,aAAa;IACvB,QAAQ,aAAa;IACrB,GAAG,QAAQ;IACX,QAAQ,aAAa;IACrB,IAAI,SAAS;IACb,KAAK,UAAU;CAChB;AAED;;;GAGG;AACH,oBAAY,QAAQ;IAClB,aAAa,kBAAkB;IAC/B,iBAAiB,sBAAsB;CACxC;AAED;;GAEG;AACH,oBAAY,aAAa;IACvB,WAAW,+BAA+B;IAC1C,IAAI,SAAS;IACb,SAAS,cAAc;CACxB;AAED;;;GAGG;AACH,MAAM,WAAW,WAAW;IAC1B,2EAA2E;IAC3E,aAAa,CAAC,EAAE,aAAa,CAAC;IAC9B,2GAA2G;IAC3G,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,6HAA6H;IAC7H,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,8GAA8G;IAC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