@inworld/cli 0.3.1 → 1.0.0-rc.1
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 +820 -296
- package/dist/package.json +11 -7
- package/dist/proto/generated/portal/ai/inworld/language_codes/language_codes.pb.d.ts.map +1 -1
- package/dist/proto/generated/portal/ai/inworld/language_codes/language_codes.pb.js +0 -1
- package/dist/proto/generated/portal/ai/inworld/language_codes/language_codes.pb.js.map +1 -1
- package/dist/proto/generated/portal/ai/inworld/studio/v1/errors.pb.d.ts.map +1 -1
- package/dist/proto/generated/portal/ai/inworld/studio/v1/operations.pb.d.ts.map +1 -1
- package/dist/proto/generated/portal/ai/inworld/studio/v1/operations.pb.js +0 -1
- package/dist/proto/generated/portal/ai/inworld/studio/v1/operations.pb.js.map +1 -1
- package/dist/proto/generated/portal/ai/inworld/studio/v1/remote/configuration/graph_configuration.pb.d.ts.map +1 -1
- package/dist/proto/generated/portal/ai/inworld/studio/v1/remote/configuration/graph_configuration.pb.js +0 -1
- package/dist/proto/generated/portal/ai/inworld/studio/v1/remote/configuration/graph_configuration.pb.js.map +1 -1
- package/dist/proto/generated/portal/ai/inworld/studio/v1/remote/configuration/targeting.pb.d.ts.map +1 -1
- package/dist/proto/generated/portal/ai/inworld/studio/v1/remote/configuration/targeting.pb.js +0 -1
- package/dist/proto/generated/portal/ai/inworld/studio/v1/remote/configuration/targeting.pb.js.map +1 -1
- package/dist/proto/generated/portal/ai/inworld/studio/v1alpha/apikeys.pb.d.ts +2 -0
- package/dist/proto/generated/portal/ai/inworld/studio/v1alpha/apikeys.pb.d.ts.map +1 -1
- package/dist/proto/generated/portal/ai/inworld/studio/v1alpha/apikeys.pb.js +0 -1
- package/dist/proto/generated/portal/ai/inworld/studio/v1alpha/apikeys.pb.js.map +1 -1
- package/dist/proto/generated/portal/ai/inworld/studio/v1alpha/impression_event_data.pb.d.ts.map +1 -1
- package/dist/proto/generated/portal/ai/inworld/studio/v1alpha/impression_event_data.pb.js +0 -1
- package/dist/proto/generated/portal/ai/inworld/studio/v1alpha/impression_event_data.pb.js.map +1 -1
- package/dist/proto/generated/portal/ai/inworld/studio/v1alpha/language_code.pb.d.ts.map +1 -1
- package/dist/proto/generated/portal/ai/inworld/studio/v1alpha/language_code.pb.js +0 -1
- package/dist/proto/generated/portal/ai/inworld/studio/v1alpha/language_code.pb.js.map +1 -1
- package/dist/proto/generated/portal/ai/inworld/studio/v1alpha/users.pb.d.ts.map +1 -1
- package/dist/proto/generated/portal/ai/inworld/studio/v1alpha/users.pb.js +0 -1
- package/dist/proto/generated/portal/ai/inworld/studio/v1alpha/users.pb.js.map +1 -1
- package/dist/proto/generated/portal/ai/inworld/studio/v1alpha/workspaces.pb.d.ts.map +1 -1
- package/dist/proto/generated/portal/ai/inworld/studio/v1alpha/workspaces.pb.js +0 -1
- package/dist/proto/generated/portal/ai/inworld/studio/v1alpha/workspaces.pb.js.map +1 -1
- package/dist/proto/generated/portal/fetch.pb.d.ts.map +1 -1
- package/dist/proto/generated/portal/fetch.pb.js.map +1 -1
- package/dist/src/auth/manager.d.ts.map +1 -1
- package/dist/src/auth/manager.js +1 -3
- package/dist/src/auth/manager.js.map +1 -1
- package/dist/src/auth/utils.d.ts +1 -1
- package/dist/src/auth/utils.d.ts.map +1 -1
- package/dist/src/auth/utils.js +1 -1
- package/dist/src/auth/utils.js.map +1 -1
- package/dist/src/commands/auth/disable_telemetry_command.js +21 -0
- package/dist/src/commands/auth/disable_telemetry_command.js.map +1 -0
- package/dist/src/commands/auth/enable_telemetry_command.js +22 -0
- package/dist/src/commands/auth/enable_telemetry_command.js.map +1 -0
- package/dist/src/commands/auth/login_command.d.ts.map +1 -1
- package/dist/src/commands/auth/login_command.js +2 -2
- package/dist/src/commands/auth/login_command.js.map +1 -1
- package/dist/src/commands/auth/status_command.d.ts.map +1 -1
- package/dist/src/commands/auth/status_command.js.map +1 -1
- package/dist/src/commands/auth_command.js +4 -0
- package/dist/src/commands/auth_command.js.map +1 -1
- package/dist/src/commands/graph/graph_deploy_command.d.ts.map +1 -1
- package/dist/src/commands/graph/graph_deploy_command.js +14 -1
- package/dist/src/commands/graph/graph_deploy_command.js.map +1 -1
- package/dist/src/commands/graph/graph_init_command.d.ts.map +1 -1
- package/dist/src/commands/graph/graph_init_command.js +231 -272
- package/dist/src/commands/graph/graph_init_command.js.map +1 -1
- package/dist/src/commands/graph/graph_run_command.d.ts.map +1 -1
- package/dist/src/commands/graph/graph_run_command.js +1 -1
- package/dist/src/commands/graph/graph_run_command.js.map +1 -1
- package/dist/src/commands/graph/graph_visualize_command.d.ts.map +1 -1
- package/dist/src/commands/graph/graph_visualize_command.js +3 -3
- package/dist/src/commands/graph/graph_visualize_command.js.map +1 -1
- package/dist/src/commands/graph/variant/graph_variant_list_command.d.ts.map +1 -1
- package/dist/src/commands/graph/variant/graph_variant_list_command.js +1 -0
- package/dist/src/commands/graph/variant/graph_variant_list_command.js.map +1 -1
- package/dist/src/commands/graph/variant/graph_variant_print_command.d.ts.map +1 -1
- package/dist/src/commands/graph/variant/graph_variant_print_command.js +2 -1
- package/dist/src/commands/graph/variant/graph_variant_print_command.js.map +1 -1
- package/dist/src/commands/graph/variant/graph_variant_register_command.d.ts.map +1 -1
- package/dist/src/commands/graph/variant/graph_variant_register_command.js +1 -0
- package/dist/src/commands/graph/variant/graph_variant_register_command.js.map +1 -1
- package/dist/src/commands/tts/tts_clone_command.d.ts +6 -0
- package/dist/src/commands/tts/tts_clone_command.d.ts.map +1 -0
- package/dist/src/commands/tts/tts_clone_command.js +80 -0
- package/dist/src/commands/tts/tts_clone_command.js.map +1 -0
- package/dist/src/commands/tts/tts_design_command.d.ts +6 -0
- package/dist/src/commands/tts/tts_design_command.d.ts.map +1 -0
- package/dist/src/commands/tts/tts_design_command.js +216 -0
- package/dist/src/commands/tts/tts_design_command.js.map +1 -0
- package/dist/src/commands/tts/tts_list_voices_command.d.ts +6 -0
- package/dist/src/commands/tts/tts_list_voices_command.d.ts.map +1 -0
- package/dist/src/commands/tts/tts_list_voices_command.js +108 -0
- package/dist/src/commands/tts/tts_list_voices_command.js.map +1 -0
- package/dist/src/commands/tts/tts_synthesize_command.d.ts +6 -0
- package/dist/src/commands/tts/tts_synthesize_command.d.ts.map +1 -0
- package/dist/src/commands/tts/tts_synthesize_command.js +351 -0
- package/dist/src/commands/tts/tts_synthesize_command.js.map +1 -0
- package/dist/src/commands/tts/tts_utils.d.ts +14 -0
- package/dist/src/commands/tts/tts_utils.d.ts.map +1 -0
- package/dist/src/commands/tts/tts_utils.js +84 -0
- package/dist/src/commands/tts/tts_utils.js.map +1 -0
- package/dist/src/commands/tts_commands.d.ts +0 -11
- package/dist/src/commands/tts_commands.d.ts.map +1 -1
- package/dist/src/commands/tts_commands.js +6 -556
- package/dist/src/commands/tts_commands.js.map +1 -1
- package/dist/src/commands/workspace_command.d.ts +10 -0
- package/dist/src/commands/workspace_command.d.ts.map +1 -1
- package/dist/src/commands/workspace_command.js +39 -0
- package/dist/src/commands/workspace_command.js.map +1 -1
- package/dist/src/constants.d.ts +2 -1
- package/dist/src/constants.d.ts.map +1 -1
- package/dist/src/constants.js +19 -1
- package/dist/src/constants.js.map +1 -1
- package/dist/src/grpc/core/InworldError.d.ts.map +1 -1
- package/dist/src/grpc/core/InworldError.js.map +1 -1
- package/dist/src/index.js +139 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/services/analytics.d.ts +2 -2
- package/dist/src/services/analytics.d.ts.map +1 -1
- package/dist/src/services/analytics.js +139 -0
- package/dist/src/services/analytics.js.map +1 -0
- package/dist/src/services/deploy_service.js +1 -1
- package/dist/src/services/deploy_service.js.map +1 -1
- package/dist/src/services/graph_loader.d.ts.map +1 -1
- package/dist/src/services/graph_loader.js +1 -1
- package/dist/src/services/graph_loader.js.map +1 -1
- package/dist/src/services/graph_variant_service.d.ts.map +1 -1
- package/dist/src/services/graph_variant_service.js +1 -1
- package/dist/src/services/graph_variant_service.js.map +1 -1
- package/dist/src/services/template_service.d.ts +79 -0
- package/dist/src/services/template_service.d.ts.map +1 -0
- package/dist/src/services/template_service.js +299 -0
- package/dist/src/services/template_service.js.map +1 -0
- package/dist/src/services/tts_service.d.ts +138 -71
- package/dist/src/services/tts_service.d.ts.map +1 -1
- package/dist/src/services/tts_service.js +87 -66
- package/dist/src/services/tts_service.js.map +1 -1
- package/dist/src/services/update_checker.js +134 -0
- package/dist/src/services/update_checker.js.map +1 -0
- package/dist/src/services/workspace_service.d.ts +6 -0
- package/dist/src/services/workspace_service.d.ts.map +1 -1
- package/dist/src/services/workspace_service.js +115 -13
- package/dist/src/services/workspace_service.js.map +1 -1
- package/dist/src/utils/audio_player.d.ts +10 -0
- package/dist/src/utils/audio_player.d.ts.map +1 -0
- package/dist/src/utils/audio_player.js +34 -0
- package/dist/src/utils/audio_player.js.map +1 -0
- package/dist/src/utils/long_running_operations.d.ts.map +1 -1
- package/dist/src/utils/long_running_operations.js +1 -1
- package/dist/src/utils/long_running_operations.js.map +1 -1
- package/dist/src/utils/resource_name_helper.d.ts +5 -0
- package/dist/src/utils/resource_name_helper.d.ts.map +1 -1
- package/dist/src/utils/resource_name_helper.js +9 -0
- package/dist/src/utils/resource_name_helper.js.map +1 -1
- package/dist/src/utils/selector.d.ts.map +1 -1
- package/dist/src/utils/selector.js +1 -2
- package/dist/src/utils/selector.js.map +1 -1
- package/dist/src/utils/ui.d.ts.map +1 -1
- package/dist/src/utils/ui.js +8 -2
- package/dist/src/utils/ui.js.map +1 -1
- package/package.json +8 -2
- package/dist/index.js.map +0 -7
- 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/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
|
@@ -1,104 +1,36 @@
|
|
|
1
|
-
import chalk from 'chalk';
|
|
2
1
|
import { Command } from 'commander';
|
|
3
2
|
import fs from 'fs';
|
|
4
3
|
import path from 'path';
|
|
5
4
|
import * as readline from 'readline';
|
|
6
|
-
import {
|
|
7
|
-
import { RUNTIME_VERSION } from '@/constants';
|
|
5
|
+
import { copyTemplateDirectory, downloadAndCacheTemplate, extractRepoFromUrl, fetchTemplatesMetadata, getAvailableTemplatesWithMetadata, isTemplateCached, } from '@/services/template_service';
|
|
8
6
|
import { confirm } from '@/utils/confirm';
|
|
9
|
-
import {
|
|
7
|
+
import { selectItemOrExit } from '@/utils/selector';
|
|
10
8
|
import * as ui from '@/utils/ui';
|
|
11
|
-
|
|
12
|
-
const
|
|
13
|
-
// Resolve template path - check multiple possible locations
|
|
14
|
-
function getTemplatePath() {
|
|
15
|
-
const possiblePaths = [
|
|
16
|
-
// Production: templates are copied to dist/templates (when code is bundled in dist/index.js)
|
|
17
|
-
path.join(__dirname, 'templates'),
|
|
18
|
-
// Development: templates are in src/templates (when running from src/)
|
|
19
|
-
path.join(__dirname, '..', '..', 'templates'),
|
|
20
|
-
// Alternative: if running from nested directory structure
|
|
21
|
-
path.join(__dirname, '..', '..', '..', 'templates'),
|
|
22
|
-
];
|
|
23
|
-
for (const templatePath of possiblePaths) {
|
|
24
|
-
if (fs.existsSync(templatePath)) {
|
|
25
|
-
return templatePath;
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
throw new Error('Template directory not found. Please ensure templates are properly installed.');
|
|
29
|
-
}
|
|
30
|
-
const TEMPLATE_PATH = getTemplatePath();
|
|
9
|
+
// Default branch for template repositories
|
|
10
|
+
const DEFAULT_TEMPLATE_BRANCH = 'main';
|
|
31
11
|
/**
|
|
32
|
-
*
|
|
12
|
+
* Check if project has package-lock.json file
|
|
33
13
|
*/
|
|
34
|
-
function
|
|
35
|
-
const
|
|
36
|
-
|
|
37
|
-
try {
|
|
38
|
-
return JSON.parse(fs.readFileSync(metadataPath, 'utf-8'));
|
|
39
|
-
}
|
|
40
|
-
catch (err) {
|
|
41
|
-
ui.print(`Failed to parse metadata for ${templateDir}: ${err}`);
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
// Return default metadata if file doesn't exist
|
|
45
|
-
return {
|
|
46
|
-
name: templateDir,
|
|
47
|
-
displayName: templateDir
|
|
48
|
-
.replace(/_/g, ' ')
|
|
49
|
-
.replace(/\b\w/g, (c) => c.toUpperCase()),
|
|
50
|
-
description: `${templateDir} template`,
|
|
51
|
-
tags: [],
|
|
52
|
-
defaultProjectName: templateDir,
|
|
53
|
-
};
|
|
14
|
+
function hasLockFiles(directory) {
|
|
15
|
+
const packageLockPath = path.join(directory, 'package-lock.json');
|
|
16
|
+
return fs.existsSync(packageLockPath);
|
|
54
17
|
}
|
|
55
18
|
/**
|
|
56
|
-
*
|
|
19
|
+
* Ask user to confirm dependency installation
|
|
57
20
|
*/
|
|
58
|
-
function
|
|
59
|
-
const templates = [];
|
|
60
|
-
try {
|
|
61
|
-
const entries = fs.readdirSync(TEMPLATE_PATH, { withFileTypes: true });
|
|
62
|
-
const templateDirs = entries
|
|
63
|
-
.filter((entry) => entry.isDirectory())
|
|
64
|
-
.filter((dir) => {
|
|
65
|
-
// Check if the directory contains a graph.ts file
|
|
66
|
-
const graphPath = path.join(TEMPLATE_PATH, dir.name, 'graph.ts');
|
|
67
|
-
return fs.existsSync(graphPath);
|
|
68
|
-
});
|
|
69
|
-
for (const dir of templateDirs) {
|
|
70
|
-
const metadata = loadTemplateMetadata(dir.name, TEMPLATE_PATH);
|
|
71
|
-
if (metadata) {
|
|
72
|
-
templates.push({
|
|
73
|
-
directory: dir.name,
|
|
74
|
-
metadata,
|
|
75
|
-
});
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
catch (_err) {
|
|
80
|
-
// Continue to next path if there's an error
|
|
81
|
-
}
|
|
82
|
-
return templates;
|
|
83
|
-
}
|
|
84
|
-
/**
|
|
85
|
-
* Ask user to confirm npm install
|
|
86
|
-
*/
|
|
87
|
-
async function promptNpmInstall() {
|
|
21
|
+
async function promptInstallDependencies() {
|
|
88
22
|
return confirm({
|
|
89
|
-
message:
|
|
23
|
+
message: `\nWould you like to install dependencies now using npm? (y/n) `,
|
|
90
24
|
defaultValue: false,
|
|
91
25
|
});
|
|
92
26
|
}
|
|
93
27
|
/**
|
|
94
28
|
* Run npm install in a directory
|
|
95
29
|
*/
|
|
96
|
-
async function
|
|
30
|
+
async function runPackageInstall(directory) {
|
|
97
31
|
const { spawn } = await import('child_process');
|
|
98
32
|
return new Promise((resolve, reject) => {
|
|
99
|
-
|
|
100
|
-
ui.print('📦 Installing dependencies...');
|
|
101
|
-
console.log();
|
|
33
|
+
ui.print(`Installing dependencies using npm...`);
|
|
102
34
|
const install = spawn('npm', ['install'], {
|
|
103
35
|
cwd: directory,
|
|
104
36
|
stdio: 'inherit',
|
|
@@ -106,152 +38,212 @@ async function runNpmInstall(directory) {
|
|
|
106
38
|
});
|
|
107
39
|
install.on('close', (code) => {
|
|
108
40
|
if (code === 0) {
|
|
109
|
-
|
|
110
|
-
ui.success('✅ Dependencies installed successfully!');
|
|
41
|
+
ui.success('Dependencies installed successfully!');
|
|
111
42
|
resolve();
|
|
112
43
|
}
|
|
113
44
|
else {
|
|
114
|
-
console.log();
|
|
115
45
|
ui.printError(`❌ npm install failed with code ${code}`);
|
|
116
46
|
reject(new Error(`npm install failed with code ${code}`));
|
|
117
47
|
}
|
|
118
48
|
});
|
|
119
49
|
install.on('error', (err) => {
|
|
120
|
-
console.log();
|
|
121
50
|
ui.printError(`❌ Failed to run npm install: ${err.message}`);
|
|
122
51
|
reject(err);
|
|
123
52
|
});
|
|
124
53
|
});
|
|
125
54
|
}
|
|
126
|
-
/**
|
|
127
|
-
* Process and enhance the package.json for initialization
|
|
128
|
-
*/
|
|
129
|
-
function createPackageJson(graphFileName) {
|
|
130
|
-
const packageJson = {
|
|
131
|
-
name: 'inworld-graph-project',
|
|
132
|
-
version: '1.0.0',
|
|
133
|
-
description: 'Inworld Runtime Graph Project',
|
|
134
|
-
main: graphFileName,
|
|
135
|
-
scripts: {
|
|
136
|
-
start: `npx inworld serve ${graphFileName}`,
|
|
137
|
-
run: `npx inworld run ${graphFileName}`,
|
|
138
|
-
},
|
|
139
|
-
dependencies: {
|
|
140
|
-
'@inworld/runtime': RUNTIME_VERSION,
|
|
141
|
-
},
|
|
142
|
-
keywords: ['inworld', 'ai', 'graph', 'runtime'],
|
|
143
|
-
author: '',
|
|
144
|
-
license: 'MIT',
|
|
145
|
-
};
|
|
146
|
-
return packageJson;
|
|
147
|
-
}
|
|
148
|
-
/**
|
|
149
|
-
* Get the graph template content from the templates folder
|
|
150
|
-
*/
|
|
151
|
-
function createGraphTemplate(templateName) {
|
|
152
|
-
const availableTemplates = getAvailableTemplatesWithMetadata();
|
|
153
|
-
if (!availableTemplates.find((template) => template.directory === templateName)) {
|
|
154
|
-
throw new Error(`Unknown template: ${templateName}. Available templates: ${availableTemplates
|
|
155
|
-
.map((template) => template.directory)
|
|
156
|
-
.join(', ')}`);
|
|
157
|
-
}
|
|
158
|
-
const templateFilePath = path.join(TEMPLATE_PATH, templateName, 'graph.ts');
|
|
159
|
-
if (!fs.existsSync(templateFilePath)) {
|
|
160
|
-
throw new Error(`Template file not found: ${templateName}/graph.ts. Please ensure the template files are in the templates folder.`);
|
|
161
|
-
}
|
|
162
|
-
return fs.readFileSync(templateFilePath, 'utf-8');
|
|
163
|
-
}
|
|
164
|
-
/**
|
|
165
|
-
* Get README content for the selected template
|
|
166
|
-
*/
|
|
167
|
-
function createReadme(templateName, graphFileName) {
|
|
168
|
-
const readmePath = path.join(TEMPLATE_PATH, templateName, 'README.md');
|
|
169
|
-
if (!fs.existsSync(readmePath)) {
|
|
170
|
-
ui.printError(`README file not found: ${readmePath}`);
|
|
171
|
-
process.exit(1);
|
|
172
|
-
}
|
|
173
|
-
const readmeContent = fs.readFileSync(readmePath, 'utf-8');
|
|
174
|
-
// Replace placeholders in the README
|
|
175
|
-
return readmeContent.replace(/\{\{graphFileName\}\}/g, graphFileName);
|
|
176
|
-
}
|
|
177
55
|
// The actual init action handler
|
|
178
56
|
const initAction = async (options) => {
|
|
179
57
|
try {
|
|
180
58
|
// Handle list templates flag
|
|
181
59
|
if (options.listTemplates) {
|
|
182
|
-
|
|
183
|
-
|
|
60
|
+
let templates;
|
|
61
|
+
try {
|
|
62
|
+
templates = await getAvailableTemplatesWithMetadata();
|
|
63
|
+
}
|
|
64
|
+
catch (error) {
|
|
65
|
+
ui.print(`Failed to fetch templates metadata: ${error instanceof Error ? error.message : String(error)}`);
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
184
68
|
ui.printHeader('📚 Available templates:');
|
|
185
|
-
|
|
69
|
+
if (templates.length === 0) {
|
|
70
|
+
ui.print('No templates found.');
|
|
71
|
+
ui.print(`\nUse ${ui.bold('inworld init --template <name>')} to download and use a template from GitHub.`);
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
186
74
|
for (const template of templates) {
|
|
187
|
-
|
|
188
|
-
ui.
|
|
189
|
-
|
|
190
|
-
|
|
75
|
+
// Template name and ID
|
|
76
|
+
ui.p(`└ ${ui.bold(ui.cyan(template.metadata.name))} (ID: ${template.metadata.id})`);
|
|
77
|
+
ui.print(` ${template.metadata.description}`);
|
|
78
|
+
// Extract use cases from useCase or useCases
|
|
79
|
+
let useCases = [];
|
|
80
|
+
if (template.metadata.useCase &&
|
|
81
|
+
Array.isArray(template.metadata.useCase)) {
|
|
82
|
+
useCases = template.metadata.useCase;
|
|
83
|
+
}
|
|
84
|
+
else if (template.metadata.useCases &&
|
|
85
|
+
Array.isArray(template.metadata.useCases)) {
|
|
86
|
+
useCases = template.metadata.useCases.map((uc) => typeof uc === 'string' ? uc : uc.useCase);
|
|
87
|
+
}
|
|
88
|
+
if (useCases.length > 0) {
|
|
89
|
+
ui.printBright(` Use Cases: ${ui.dim(useCases.join(', '))}`);
|
|
90
|
+
}
|
|
91
|
+
// SDK information
|
|
92
|
+
if (template.metadata.sdk) {
|
|
93
|
+
const sdkInfo = template.metadata.sdkVersion
|
|
94
|
+
? `${template.metadata.sdk} v${template.metadata.sdkVersion}`
|
|
95
|
+
: template.metadata.sdk;
|
|
96
|
+
ui.printBright(` SDK: ${ui.dim(sdkInfo)}`);
|
|
97
|
+
}
|
|
98
|
+
// Input/Output modalities
|
|
99
|
+
const modalities = [];
|
|
100
|
+
if (template.metadata.inputModality &&
|
|
101
|
+
template.metadata.inputModality.length > 0) {
|
|
102
|
+
modalities.push(`Input: ${template.metadata.inputModality.join(', ')}`);
|
|
103
|
+
}
|
|
104
|
+
if (template.metadata.outputModality &&
|
|
105
|
+
template.metadata.outputModality.length > 0) {
|
|
106
|
+
modalities.push(`Output: ${template.metadata.outputModality.join(', ')}`);
|
|
107
|
+
}
|
|
108
|
+
if (modalities.length > 0) {
|
|
109
|
+
ui.printBright(` Modalities: ${ui.dim(modalities.join(' | '))}`);
|
|
191
110
|
}
|
|
192
|
-
|
|
193
|
-
|
|
111
|
+
// Type
|
|
112
|
+
if (template.metadata.type) {
|
|
113
|
+
ui.printBright(` Type: ${ui.dim(template.metadata.type)}`);
|
|
194
114
|
}
|
|
195
|
-
|
|
115
|
+
// Links
|
|
116
|
+
if (template.metadata.docsLink) {
|
|
117
|
+
ui.printBright(` Docs: ${ui.dim(ui.link(template.metadata.docsLink))}`);
|
|
118
|
+
}
|
|
119
|
+
if (template.metadata.webDemo) {
|
|
120
|
+
ui.printBright(` Demo: ${ui.dim(ui.link(template.metadata.webDemo))}`);
|
|
121
|
+
}
|
|
122
|
+
if (template.metadata.videoDemo) {
|
|
123
|
+
ui.printBright(` Video: ${ui.dim(ui.link(template.metadata.videoDemo))}`);
|
|
124
|
+
}
|
|
125
|
+
// Add spacing between templates
|
|
126
|
+
ui.p('');
|
|
196
127
|
}
|
|
197
|
-
ui.print(
|
|
198
|
-
console.log();
|
|
128
|
+
ui.print(`\nNote: Templates are downloaded from GitHub repositories as complete applications.`);
|
|
199
129
|
return;
|
|
200
130
|
}
|
|
201
|
-
// Get available templates with metadata
|
|
202
|
-
const templates = getAvailableTemplatesWithMetadata();
|
|
203
|
-
if (templates.length === 0) {
|
|
204
|
-
ui.printError('❌ No templates found. Please ensure templates are properly installed.');
|
|
205
|
-
process.exit(1);
|
|
206
|
-
}
|
|
207
|
-
let selectedTemplate = null;
|
|
208
131
|
let projectName;
|
|
209
|
-
|
|
132
|
+
let selectedTemplateId;
|
|
133
|
+
// Always fetch fresh template metadata from JSON (no caching)
|
|
134
|
+
const templates = await fetchTemplatesMetadata();
|
|
135
|
+
// If no template specified, show welcome message and let user select
|
|
210
136
|
if (!options.template) {
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
137
|
+
ui.printBright('🚀 Welcome to the Inworld Template Initializer!');
|
|
138
|
+
if (templates.length === 0) {
|
|
139
|
+
ui.printError('❌ No templates found.');
|
|
140
|
+
ui.print(`\nPlease ensure the templates metadata is accessible.`);
|
|
141
|
+
process.exit(1);
|
|
142
|
+
}
|
|
143
|
+
// Use selector to let user choose a template
|
|
144
|
+
const selectedTemplate = await selectItemOrExit({
|
|
216
145
|
items: templates,
|
|
217
|
-
getDisplayName: (
|
|
218
|
-
|
|
219
|
-
|
|
146
|
+
getDisplayName: (template) => {
|
|
147
|
+
// Format: "Template Name - Description" with styled name to match --list-templates
|
|
148
|
+
return `${ui.bold(ui.cyan(template.name))} - ${template.description}`;
|
|
149
|
+
},
|
|
150
|
+
getIdentifier: (template) => template.id,
|
|
151
|
+
prompt: 'Select a template (enter number or name):',
|
|
220
152
|
title: '📋 Available Templates:',
|
|
221
|
-
|
|
222
|
-
invalidSelectionMessage: 'Invalid selection. Please try again.',
|
|
153
|
+
exitOnFailure: true,
|
|
223
154
|
});
|
|
224
|
-
|
|
225
|
-
console.log();
|
|
226
|
-
ui.print('⚠️ No template selected. Exiting.');
|
|
227
|
-
return;
|
|
228
|
-
}
|
|
155
|
+
selectedTemplateId = selectedTemplate.id;
|
|
229
156
|
}
|
|
230
157
|
else {
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
158
|
+
selectedTemplateId = options.template;
|
|
159
|
+
}
|
|
160
|
+
// Try to find template by id
|
|
161
|
+
let template = templates.find((t) => t.id === selectedTemplateId);
|
|
162
|
+
// If not found and name doesn't end with '-node', try appending '-node'
|
|
163
|
+
if (!template && !selectedTemplateId.endsWith('-node')) {
|
|
164
|
+
const nameWithNode = `${selectedTemplateId}-node`;
|
|
165
|
+
template = templates.find((t) => t.id === nameWithNode);
|
|
166
|
+
}
|
|
167
|
+
// If still not found, try matching by name (case-insensitive, with/without spaces)
|
|
168
|
+
if (!template) {
|
|
169
|
+
const normalizedName = selectedTemplateId
|
|
170
|
+
.toLowerCase()
|
|
171
|
+
.replace(/[-_\s]/g, '');
|
|
172
|
+
template = templates.find((t) => {
|
|
173
|
+
const normalizedTemplateName = t.name
|
|
174
|
+
.toLowerCase()
|
|
175
|
+
.replace(/[-_\s]/g, '');
|
|
176
|
+
return normalizedTemplateName === normalizedName;
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
// Template must exist in metadata
|
|
180
|
+
if (!template) {
|
|
181
|
+
ui.printError(`❌ Template '${selectedTemplateId}' not found.`);
|
|
182
|
+
ui.print(`\nUse ${ui.bold('inworld init --list-templates')} to see all available templates.`);
|
|
183
|
+
process.exit(1);
|
|
184
|
+
}
|
|
185
|
+
// Get repository from template metadata
|
|
186
|
+
const repoToUse = template.githubRepo
|
|
187
|
+
? extractRepoFromUrl(template.githubRepo)
|
|
188
|
+
: null;
|
|
189
|
+
if (!repoToUse) {
|
|
190
|
+
ui.printError(`❌ No repository found for template '${selectedTemplateId}'.`);
|
|
191
|
+
ui.print('The template metadata is missing a valid GitHub repository.');
|
|
192
|
+
process.exit(1);
|
|
193
|
+
}
|
|
194
|
+
// Use branch from metadata if available, otherwise default to 'main'
|
|
195
|
+
const branchToUse = template.branch || DEFAULT_TEMPLATE_BRANCH;
|
|
196
|
+
// Download and cache the template from GitHub
|
|
197
|
+
let cachedTemplatePath;
|
|
198
|
+
let templateFromCache = false;
|
|
199
|
+
try {
|
|
200
|
+
// Check cache status first to show appropriate message
|
|
201
|
+
const isCached = isTemplateCached(template.id, options.force ?? false);
|
|
202
|
+
if (options.force) {
|
|
203
|
+
ui.print(`Force refreshing template '${selectedTemplateId}' from GitHub...`);
|
|
204
|
+
}
|
|
205
|
+
else if (isCached) {
|
|
206
|
+
ui.print(`✓ Using cached template '${selectedTemplateId}' (cache expires in 24 hours)`);
|
|
238
207
|
}
|
|
208
|
+
else {
|
|
209
|
+
ui.print(`Downloading template '${selectedTemplateId}' from GitHub...`);
|
|
210
|
+
}
|
|
211
|
+
const cacheResult = await downloadAndCacheTemplate(template.id, repoToUse, branchToUse, options.force);
|
|
212
|
+
cachedTemplatePath = cacheResult.path;
|
|
213
|
+
templateFromCache = cacheResult.fromCache;
|
|
214
|
+
if (!isCached && !templateFromCache) {
|
|
215
|
+
// Only show success message if we actually downloaded (not from cache)
|
|
216
|
+
ui.print(`✓ Template '${selectedTemplateId}' downloaded successfully`);
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
catch (error) {
|
|
220
|
+
ui.printError(`❌ Failed to download template: ${selectedTemplateId}`);
|
|
221
|
+
ui.print(`Error: ${error instanceof Error ? error.message : String(error)}`);
|
|
222
|
+
ui.print(`\nPlease ensure the template exists in the templates metadata and the repository is accessible.`);
|
|
223
|
+
process.exit(1);
|
|
239
224
|
}
|
|
225
|
+
// Create TemplateInfo from the found template
|
|
226
|
+
const selectedTemplate = {
|
|
227
|
+
directory: template.id || template.name,
|
|
228
|
+
metadata: template,
|
|
229
|
+
};
|
|
240
230
|
// Determine project name
|
|
241
231
|
projectName =
|
|
242
232
|
options.name ||
|
|
243
|
-
selectedTemplate.metadata.
|
|
233
|
+
selectedTemplate.metadata.id ||
|
|
244
234
|
selectedTemplate.directory;
|
|
245
|
-
// If
|
|
246
|
-
if (!options.
|
|
235
|
+
// If no name specified, ask for project name
|
|
236
|
+
if (!options.name) {
|
|
247
237
|
const rl = readline.createInterface({
|
|
248
238
|
input: process.stdin,
|
|
249
239
|
output: process.stdout,
|
|
250
240
|
});
|
|
251
241
|
const askProjectName = () => new Promise((resolve) => {
|
|
252
|
-
rl.question(`\nProject name (${selectedTemplate.metadata.
|
|
242
|
+
rl.question(`\nProject name (${selectedTemplate.metadata.id || selectedTemplate.metadata.name}): `, (answer) => {
|
|
253
243
|
rl.close();
|
|
254
|
-
resolve(answer.trim() ||
|
|
244
|
+
resolve(answer.trim() ||
|
|
245
|
+
selectedTemplate.metadata.id ||
|
|
246
|
+
selectedTemplate.metadata.name);
|
|
255
247
|
});
|
|
256
248
|
});
|
|
257
249
|
projectName = await askProjectName();
|
|
@@ -260,97 +252,66 @@ const initAction = async (options) => {
|
|
|
260
252
|
const projectDir = path.join(currentDir, projectName);
|
|
261
253
|
// Check if project directory already exists
|
|
262
254
|
if (fs.existsSync(projectDir)) {
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
if (!confirmOverwrite) {
|
|
272
|
-
ui.print('⚠️ Initialization cancelled.');
|
|
273
|
-
return;
|
|
274
|
-
}
|
|
275
|
-
// Remove existing directory
|
|
276
|
-
fs.rmSync(projectDir, { recursive: true, force: true });
|
|
277
|
-
}
|
|
278
|
-
else {
|
|
279
|
-
ui.print('Overwriting existing directory...');
|
|
280
|
-
fs.rmSync(projectDir, { recursive: true, force: true });
|
|
255
|
+
ui.print(`Directory '${projectName}' already exists.`);
|
|
256
|
+
const confirmOverwrite = await confirm({
|
|
257
|
+
message: 'Do you want to overwrite it? (y/n) ',
|
|
258
|
+
defaultValue: false,
|
|
259
|
+
});
|
|
260
|
+
if (!confirmOverwrite) {
|
|
261
|
+
ui.print('Initialization cancelled.');
|
|
262
|
+
process.exit(0);
|
|
281
263
|
}
|
|
264
|
+
// Remove existing directory
|
|
265
|
+
fs.rmSync(projectDir, { recursive: true, force: true });
|
|
282
266
|
}
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
const readmePath = path.join(projectDir, 'README.md');
|
|
289
|
-
console.log();
|
|
290
|
-
ui.printHeader(`🚀 Initializing Inworld graph project: ${projectName}`);
|
|
291
|
-
ui.print(`📂 Creating project in: ${projectDir}`);
|
|
292
|
-
ui.print(`📋 Using template: ${selectedTemplate.metadata.displayName}`);
|
|
293
|
-
console.log();
|
|
294
|
-
// Create the graph file using the selected template
|
|
295
|
-
ui.print('📝 Creating graph file...');
|
|
296
|
-
const graphContent = createGraphTemplate(selectedTemplate.directory);
|
|
297
|
-
fs.writeFileSync(graphFilePath, graphContent, 'utf-8');
|
|
298
|
-
// Create package.json if not skipped
|
|
299
|
-
if (!options.skipPackageJson) {
|
|
300
|
-
ui.print('📦 Creating package.json...');
|
|
301
|
-
const packageJson = createPackageJson(graphFileName);
|
|
302
|
-
packageJson.name = projectName; // Update project name
|
|
303
|
-
fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2), 'utf-8');
|
|
304
|
-
}
|
|
305
|
-
// Create README if not skipped
|
|
306
|
-
if (!options.skipReadme) {
|
|
307
|
-
ui.print('📚 Creating README.md...');
|
|
308
|
-
const readmeContent = createReadme(selectedTemplate.directory, graphFileName);
|
|
309
|
-
fs.writeFileSync(readmePath, readmeContent, 'utf-8');
|
|
310
|
-
}
|
|
267
|
+
ui.print(`Initializing project from template: ${ui.bright(selectedTemplate.metadata.name || selectedTemplateId)}`);
|
|
268
|
+
ui.print(` Creating project in: ${projectDir}`);
|
|
269
|
+
// Copy the entire template directory to the project directory
|
|
270
|
+
ui.print(' Copying template files...');
|
|
271
|
+
copyTemplateDirectory(cachedTemplatePath, projectDir);
|
|
311
272
|
// Display template-specific information
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
try {
|
|
331
|
-
await runNpmInstall(projectDir);
|
|
273
|
+
// Note: API keys requirements are not in the JSON format, so we skip this
|
|
274
|
+
ui.success('Project initialized successfully!');
|
|
275
|
+
// Check if project has package-lock.json file
|
|
276
|
+
const hasLock = hasLockFiles(projectDir);
|
|
277
|
+
// Only show dependency installation prompts if package-lock.json exists
|
|
278
|
+
if (hasLock) {
|
|
279
|
+
const installCommand = 'npm install';
|
|
280
|
+
// Ask about dependency installation if not skipped
|
|
281
|
+
if (!options.skipInstall) {
|
|
282
|
+
const shouldInstall = await promptInstallDependencies();
|
|
283
|
+
if (shouldInstall) {
|
|
284
|
+
try {
|
|
285
|
+
await runPackageInstall(projectDir);
|
|
286
|
+
}
|
|
287
|
+
catch (_err) {
|
|
288
|
+
ui.print('⚠️ You can install dependencies manually by running:');
|
|
289
|
+
ui.print(` cd ${projectName} && ${installCommand}`);
|
|
290
|
+
}
|
|
332
291
|
}
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
ui.print(` cd ${projectName} && npm install`);
|
|
292
|
+
else {
|
|
293
|
+
ui.printBright(`
|
|
294
|
+
${ui.dim('Skipping dependency installation. You can run `')}${installCommand}${ui.dim('` later.')}`);
|
|
337
295
|
}
|
|
338
296
|
}
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
297
|
+
ui.printHeader('Next steps:\n');
|
|
298
|
+
ui.printBright(` ${ui.dim('1. Run `')}cd ${projectName}${ui.dim('`')}`);
|
|
299
|
+
if (!options.skipInstall) {
|
|
300
|
+
ui.printBright(` ${ui.dim('2. Run `')}${installCommand}${ui.dim('`')} ${ui.dim('(if not already done)')}`);
|
|
301
|
+
ui.printBright(` ${ui.dim('3. Follow the instructions in the README to get started')}`);
|
|
302
|
+
}
|
|
303
|
+
else {
|
|
304
|
+
ui.printBright(` ${ui.dim('2. Run `')}${installCommand}${ui.dim('`')} ${ui.dim('to install dependencies')}`);
|
|
305
|
+
ui.printBright(` ${ui.dim('3. Follow the instructions in the README to get started')}`);
|
|
306
|
+
}
|
|
346
307
|
}
|
|
347
308
|
else {
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
ui.print('💡 Remember to set your API keys before running!');
|
|
309
|
+
// No package-lock.json - just tell user to refer to README
|
|
310
|
+
ui.printHeader('Next steps:\n');
|
|
311
|
+
ui.printBright(` ${ui.dim('1. Run `')}cd ${projectName}${ui.dim('`')}`);
|
|
312
|
+
ui.printBright(` ${ui.dim('2. Follow the instructions in the README to get started')}`);
|
|
353
313
|
}
|
|
314
|
+
process.exit(0);
|
|
354
315
|
}
|
|
355
316
|
catch (error) {
|
|
356
317
|
ui.printError('❌ Error initializing project:');
|
|
@@ -360,17 +321,15 @@ const initAction = async (options) => {
|
|
|
360
321
|
};
|
|
361
322
|
// Create the init subcommand
|
|
362
323
|
const makeInitCommand = (description) => {
|
|
363
|
-
const availableTemplates = getAvailableTemplatesWithMetadata();
|
|
364
324
|
return new Command('init')
|
|
365
325
|
.description(description)
|
|
366
326
|
.option('-n, --name <name>', 'Name of the project directory')
|
|
367
|
-
.option('-t, --template <template>',
|
|
327
|
+
.option('-t, --template <template>', 'Template to use (will download from GitHub). Use --list-templates to see available templates.')
|
|
368
328
|
.option('-l, --list-templates', 'List all available templates')
|
|
369
|
-
.option('--skip-
|
|
370
|
-
.option('--
|
|
371
|
-
.option('--skip-install', 'Skip npm install prompt')
|
|
329
|
+
.option('--skip-install', 'Skip dependency installation prompt')
|
|
330
|
+
.option('--force', 'Force refresh template cache (download fresh copy even if cached)')
|
|
372
331
|
.action(initAction);
|
|
373
332
|
};
|
|
374
|
-
export const initCommand = makeInitCommand('Initialize a new
|
|
375
|
-
export const initCommandAlias = makeInitCommand(`Alias for "${
|
|
333
|
+
export const initCommand = makeInitCommand('Initialize a new project from a template (downloads complete app from GitHub)');
|
|
334
|
+
export const initCommandAlias = makeInitCommand(`Alias for "${ui.bold('inworld graph init')}"`);
|
|
376
335
|
//# sourceMappingURL=graph_init_command.js.map
|