@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.
Files changed (161) hide show
  1. package/dist/index.js +820 -296
  2. package/dist/package.json +11 -7
  3. package/dist/proto/generated/portal/ai/inworld/language_codes/language_codes.pb.d.ts.map +1 -1
  4. package/dist/proto/generated/portal/ai/inworld/language_codes/language_codes.pb.js +0 -1
  5. package/dist/proto/generated/portal/ai/inworld/language_codes/language_codes.pb.js.map +1 -1
  6. package/dist/proto/generated/portal/ai/inworld/studio/v1/errors.pb.d.ts.map +1 -1
  7. package/dist/proto/generated/portal/ai/inworld/studio/v1/operations.pb.d.ts.map +1 -1
  8. package/dist/proto/generated/portal/ai/inworld/studio/v1/operations.pb.js +0 -1
  9. package/dist/proto/generated/portal/ai/inworld/studio/v1/operations.pb.js.map +1 -1
  10. package/dist/proto/generated/portal/ai/inworld/studio/v1/remote/configuration/graph_configuration.pb.d.ts.map +1 -1
  11. package/dist/proto/generated/portal/ai/inworld/studio/v1/remote/configuration/graph_configuration.pb.js +0 -1
  12. package/dist/proto/generated/portal/ai/inworld/studio/v1/remote/configuration/graph_configuration.pb.js.map +1 -1
  13. package/dist/proto/generated/portal/ai/inworld/studio/v1/remote/configuration/targeting.pb.d.ts.map +1 -1
  14. package/dist/proto/generated/portal/ai/inworld/studio/v1/remote/configuration/targeting.pb.js +0 -1
  15. package/dist/proto/generated/portal/ai/inworld/studio/v1/remote/configuration/targeting.pb.js.map +1 -1
  16. package/dist/proto/generated/portal/ai/inworld/studio/v1alpha/apikeys.pb.d.ts +2 -0
  17. package/dist/proto/generated/portal/ai/inworld/studio/v1alpha/apikeys.pb.d.ts.map +1 -1
  18. package/dist/proto/generated/portal/ai/inworld/studio/v1alpha/apikeys.pb.js +0 -1
  19. package/dist/proto/generated/portal/ai/inworld/studio/v1alpha/apikeys.pb.js.map +1 -1
  20. package/dist/proto/generated/portal/ai/inworld/studio/v1alpha/impression_event_data.pb.d.ts.map +1 -1
  21. package/dist/proto/generated/portal/ai/inworld/studio/v1alpha/impression_event_data.pb.js +0 -1
  22. package/dist/proto/generated/portal/ai/inworld/studio/v1alpha/impression_event_data.pb.js.map +1 -1
  23. package/dist/proto/generated/portal/ai/inworld/studio/v1alpha/language_code.pb.d.ts.map +1 -1
  24. package/dist/proto/generated/portal/ai/inworld/studio/v1alpha/language_code.pb.js +0 -1
  25. package/dist/proto/generated/portal/ai/inworld/studio/v1alpha/language_code.pb.js.map +1 -1
  26. package/dist/proto/generated/portal/ai/inworld/studio/v1alpha/users.pb.d.ts.map +1 -1
  27. package/dist/proto/generated/portal/ai/inworld/studio/v1alpha/users.pb.js +0 -1
  28. package/dist/proto/generated/portal/ai/inworld/studio/v1alpha/users.pb.js.map +1 -1
  29. package/dist/proto/generated/portal/ai/inworld/studio/v1alpha/workspaces.pb.d.ts.map +1 -1
  30. package/dist/proto/generated/portal/ai/inworld/studio/v1alpha/workspaces.pb.js +0 -1
  31. package/dist/proto/generated/portal/ai/inworld/studio/v1alpha/workspaces.pb.js.map +1 -1
  32. package/dist/proto/generated/portal/fetch.pb.d.ts.map +1 -1
  33. package/dist/proto/generated/portal/fetch.pb.js.map +1 -1
  34. package/dist/src/auth/manager.d.ts.map +1 -1
  35. package/dist/src/auth/manager.js +1 -3
  36. package/dist/src/auth/manager.js.map +1 -1
  37. package/dist/src/auth/utils.d.ts +1 -1
  38. package/dist/src/auth/utils.d.ts.map +1 -1
  39. package/dist/src/auth/utils.js +1 -1
  40. package/dist/src/auth/utils.js.map +1 -1
  41. package/dist/src/commands/auth/disable_telemetry_command.js +21 -0
  42. package/dist/src/commands/auth/disable_telemetry_command.js.map +1 -0
  43. package/dist/src/commands/auth/enable_telemetry_command.js +22 -0
  44. package/dist/src/commands/auth/enable_telemetry_command.js.map +1 -0
  45. package/dist/src/commands/auth/login_command.d.ts.map +1 -1
  46. package/dist/src/commands/auth/login_command.js +2 -2
  47. package/dist/src/commands/auth/login_command.js.map +1 -1
  48. package/dist/src/commands/auth/status_command.d.ts.map +1 -1
  49. package/dist/src/commands/auth/status_command.js.map +1 -1
  50. package/dist/src/commands/auth_command.js +4 -0
  51. package/dist/src/commands/auth_command.js.map +1 -1
  52. package/dist/src/commands/graph/graph_deploy_command.d.ts.map +1 -1
  53. package/dist/src/commands/graph/graph_deploy_command.js +14 -1
  54. package/dist/src/commands/graph/graph_deploy_command.js.map +1 -1
  55. package/dist/src/commands/graph/graph_init_command.d.ts.map +1 -1
  56. package/dist/src/commands/graph/graph_init_command.js +231 -272
  57. package/dist/src/commands/graph/graph_init_command.js.map +1 -1
  58. package/dist/src/commands/graph/graph_run_command.d.ts.map +1 -1
  59. package/dist/src/commands/graph/graph_run_command.js +1 -1
  60. package/dist/src/commands/graph/graph_run_command.js.map +1 -1
  61. package/dist/src/commands/graph/graph_visualize_command.d.ts.map +1 -1
  62. package/dist/src/commands/graph/graph_visualize_command.js +3 -3
  63. package/dist/src/commands/graph/graph_visualize_command.js.map +1 -1
  64. package/dist/src/commands/graph/variant/graph_variant_list_command.d.ts.map +1 -1
  65. package/dist/src/commands/graph/variant/graph_variant_list_command.js +1 -0
  66. package/dist/src/commands/graph/variant/graph_variant_list_command.js.map +1 -1
  67. package/dist/src/commands/graph/variant/graph_variant_print_command.d.ts.map +1 -1
  68. package/dist/src/commands/graph/variant/graph_variant_print_command.js +2 -1
  69. package/dist/src/commands/graph/variant/graph_variant_print_command.js.map +1 -1
  70. package/dist/src/commands/graph/variant/graph_variant_register_command.d.ts.map +1 -1
  71. package/dist/src/commands/graph/variant/graph_variant_register_command.js +1 -0
  72. package/dist/src/commands/graph/variant/graph_variant_register_command.js.map +1 -1
  73. package/dist/src/commands/tts/tts_clone_command.d.ts +6 -0
  74. package/dist/src/commands/tts/tts_clone_command.d.ts.map +1 -0
  75. package/dist/src/commands/tts/tts_clone_command.js +80 -0
  76. package/dist/src/commands/tts/tts_clone_command.js.map +1 -0
  77. package/dist/src/commands/tts/tts_design_command.d.ts +6 -0
  78. package/dist/src/commands/tts/tts_design_command.d.ts.map +1 -0
  79. package/dist/src/commands/tts/tts_design_command.js +216 -0
  80. package/dist/src/commands/tts/tts_design_command.js.map +1 -0
  81. package/dist/src/commands/tts/tts_list_voices_command.d.ts +6 -0
  82. package/dist/src/commands/tts/tts_list_voices_command.d.ts.map +1 -0
  83. package/dist/src/commands/tts/tts_list_voices_command.js +108 -0
  84. package/dist/src/commands/tts/tts_list_voices_command.js.map +1 -0
  85. package/dist/src/commands/tts/tts_synthesize_command.d.ts +6 -0
  86. package/dist/src/commands/tts/tts_synthesize_command.d.ts.map +1 -0
  87. package/dist/src/commands/tts/tts_synthesize_command.js +351 -0
  88. package/dist/src/commands/tts/tts_synthesize_command.js.map +1 -0
  89. package/dist/src/commands/tts/tts_utils.d.ts +14 -0
  90. package/dist/src/commands/tts/tts_utils.d.ts.map +1 -0
  91. package/dist/src/commands/tts/tts_utils.js +84 -0
  92. package/dist/src/commands/tts/tts_utils.js.map +1 -0
  93. package/dist/src/commands/tts_commands.d.ts +0 -11
  94. package/dist/src/commands/tts_commands.d.ts.map +1 -1
  95. package/dist/src/commands/tts_commands.js +6 -556
  96. package/dist/src/commands/tts_commands.js.map +1 -1
  97. package/dist/src/commands/workspace_command.d.ts +10 -0
  98. package/dist/src/commands/workspace_command.d.ts.map +1 -1
  99. package/dist/src/commands/workspace_command.js +39 -0
  100. package/dist/src/commands/workspace_command.js.map +1 -1
  101. package/dist/src/constants.d.ts +2 -1
  102. package/dist/src/constants.d.ts.map +1 -1
  103. package/dist/src/constants.js +19 -1
  104. package/dist/src/constants.js.map +1 -1
  105. package/dist/src/grpc/core/InworldError.d.ts.map +1 -1
  106. package/dist/src/grpc/core/InworldError.js.map +1 -1
  107. package/dist/src/index.js +139 -0
  108. package/dist/src/index.js.map +1 -0
  109. package/dist/src/services/analytics.d.ts +2 -2
  110. package/dist/src/services/analytics.d.ts.map +1 -1
  111. package/dist/src/services/analytics.js +139 -0
  112. package/dist/src/services/analytics.js.map +1 -0
  113. package/dist/src/services/deploy_service.js +1 -1
  114. package/dist/src/services/deploy_service.js.map +1 -1
  115. package/dist/src/services/graph_loader.d.ts.map +1 -1
  116. package/dist/src/services/graph_loader.js +1 -1
  117. package/dist/src/services/graph_loader.js.map +1 -1
  118. package/dist/src/services/graph_variant_service.d.ts.map +1 -1
  119. package/dist/src/services/graph_variant_service.js +1 -1
  120. package/dist/src/services/graph_variant_service.js.map +1 -1
  121. package/dist/src/services/template_service.d.ts +79 -0
  122. package/dist/src/services/template_service.d.ts.map +1 -0
  123. package/dist/src/services/template_service.js +299 -0
  124. package/dist/src/services/template_service.js.map +1 -0
  125. package/dist/src/services/tts_service.d.ts +138 -71
  126. package/dist/src/services/tts_service.d.ts.map +1 -1
  127. package/dist/src/services/tts_service.js +87 -66
  128. package/dist/src/services/tts_service.js.map +1 -1
  129. package/dist/src/services/update_checker.js +134 -0
  130. package/dist/src/services/update_checker.js.map +1 -0
  131. package/dist/src/services/workspace_service.d.ts +6 -0
  132. package/dist/src/services/workspace_service.d.ts.map +1 -1
  133. package/dist/src/services/workspace_service.js +115 -13
  134. package/dist/src/services/workspace_service.js.map +1 -1
  135. package/dist/src/utils/audio_player.d.ts +10 -0
  136. package/dist/src/utils/audio_player.d.ts.map +1 -0
  137. package/dist/src/utils/audio_player.js +34 -0
  138. package/dist/src/utils/audio_player.js.map +1 -0
  139. package/dist/src/utils/long_running_operations.d.ts.map +1 -1
  140. package/dist/src/utils/long_running_operations.js +1 -1
  141. package/dist/src/utils/long_running_operations.js.map +1 -1
  142. package/dist/src/utils/resource_name_helper.d.ts +5 -0
  143. package/dist/src/utils/resource_name_helper.d.ts.map +1 -1
  144. package/dist/src/utils/resource_name_helper.js +9 -0
  145. package/dist/src/utils/resource_name_helper.js.map +1 -1
  146. package/dist/src/utils/selector.d.ts.map +1 -1
  147. package/dist/src/utils/selector.js +1 -2
  148. package/dist/src/utils/selector.js.map +1 -1
  149. package/dist/src/utils/ui.d.ts.map +1 -1
  150. package/dist/src/utils/ui.js +8 -2
  151. package/dist/src/utils/ui.js.map +1 -1
  152. package/package.json +8 -2
  153. package/dist/index.js.map +0 -7
  154. package/dist/src/templates/llm_tts/README.md +0 -161
  155. package/dist/src/templates/llm_tts/graph.d.ts +0 -2
  156. package/dist/src/templates/llm_tts/graph.d.ts.map +0 -1
  157. package/dist/src/templates/llm_tts/graph.ts +0 -30
  158. package/dist/src/templates/llm_tts/metadata.json +0 -41
  159. package/dist/templates/llm_tts/README.md +0 -155
  160. package/dist/templates/llm_tts/graph.ts +0 -29
  161. 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 { fileURLToPath } from 'url';
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 { selectItem } from '@/utils/selector';
7
+ import { selectItemOrExit } from '@/utils/selector';
10
8
  import * as ui from '@/utils/ui';
11
- const __filename = fileURLToPath(import.meta.url);
12
- const __dirname = path.dirname(__filename);
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
- * Load metadata for a template
12
+ * Check if project has package-lock.json file
33
13
  */
34
- function loadTemplateMetadata(templateDir, basePath) {
35
- const metadataPath = path.join(basePath, templateDir, 'metadata.json');
36
- if (fs.existsSync(metadataPath)) {
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
- * Get available templates with their metadata
19
+ * Ask user to confirm dependency installation
57
20
  */
58
- function getAvailableTemplatesWithMetadata() {
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: '\n📦 Would you like to install dependencies now? (y/n) ',
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 runNpmInstall(directory) {
30
+ async function runPackageInstall(directory) {
97
31
  const { spawn } = await import('child_process');
98
32
  return new Promise((resolve, reject) => {
99
- console.log();
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
- console.log();
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
- const templates = getAvailableTemplatesWithMetadata();
183
- console.log();
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
- console.log();
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
- ui.printListItem(`${chalk.cyan.bold(template.metadata.name)}`);
188
- ui.printListItem(` ${template.metadata.description}`);
189
- if (template.metadata.tags && template.metadata.tags.length > 0) {
190
- ui.printListItem(` Tags: ${template.metadata.tags.join(', ')}`);
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
- if (template.metadata.requirements?.apiKeys) {
193
- ui.printListItem(` Required API Keys: ${template.metadata.requirements.apiKeys.join(', ')}`);
111
+ // Type
112
+ if (template.metadata.type) {
113
+ ui.printBright(` Type: ${ui.dim(template.metadata.type)}`);
194
114
  }
195
- console.log();
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(`Use ${chalk.bold('inworld graph init')} to interactively select a template.`);
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
- // Interactive mode if no template specified
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
- console.log();
212
- ui.printHeader('🚀 Welcome to Inworld Graph Project Initializer!');
213
- console.log();
214
- // Select template using the selector
215
- selectedTemplate = await selectItem({
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: (item) => `${item.metadata.name} - ${item.metadata.description}`,
218
- getIdentifier: (item) => item.directory,
219
- prompt: 'Select a template (enter number or id):',
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
- noItemsMessage: 'No templates found.',
222
- invalidSelectionMessage: 'Invalid selection. Please try again.',
153
+ exitOnFailure: true,
223
154
  });
224
- if (!selectedTemplate) {
225
- console.log();
226
- ui.print('⚠️ No template selected. Exiting.');
227
- return;
228
- }
155
+ selectedTemplateId = selectedTemplate.id;
229
156
  }
230
157
  else {
231
- // Find template by directory name if specified
232
- selectedTemplate =
233
- templates.find((t) => t.directory === options.template) || null;
234
- if (!selectedTemplate) {
235
- ui.printError(`❌ Template not found: ${options.template}`);
236
- ui.print(`Available templates: ${templates.map((t) => t.directory).join(', ')}`);
237
- process.exit(1);
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.defaultProjectName ||
233
+ selectedTemplate.metadata.id ||
244
234
  selectedTemplate.directory;
245
- // If in interactive mode and no name specified, ask for project name
246
- if (!options.template && !options.name) {
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.defaultProjectName}): `, (answer) => {
242
+ rl.question(`\nProject name (${selectedTemplate.metadata.id || selectedTemplate.metadata.name}): `, (answer) => {
253
243
  rl.close();
254
- resolve(answer.trim() || selectedTemplate.metadata.defaultProjectName);
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
- console.log();
264
- ui.print(`⚠️ Directory '${projectName}' already exists.`);
265
- // In interactive mode, ask for confirmation
266
- if (!options.template) {
267
- const confirmOverwrite = await confirm({
268
- message: 'Do you want to overwrite it? (y/n) ',
269
- defaultValue: false,
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
- // Create project directory
284
- fs.mkdirSync(projectDir, { recursive: true });
285
- const graphFileName = 'graph.ts';
286
- const graphFilePath = path.join(projectDir, graphFileName);
287
- const packageJsonPath = path.join(projectDir, 'package.json');
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
- if (selectedTemplate.metadata.requirements?.apiKeys) {
313
- console.log();
314
- ui.print('⚠️ This template requires the following API keys:');
315
- for (const key of selectedTemplate.metadata.requirements.apiKeys) {
316
- ui.print(` • ${key}`);
317
- }
318
- }
319
- if (selectedTemplate.metadata.examples?.curlCommand) {
320
- console.log();
321
- ui.printHeader('📝 Example usage:');
322
- ui.print(` ${selectedTemplate.metadata.examples.curlCommand}`);
323
- }
324
- console.log();
325
- ui.success('✅ Inworld graph project initialized successfully!');
326
- // Ask about npm install if not skipped
327
- if (!options.skipInstall && !options.skipPackageJson) {
328
- const shouldInstall = await promptNpmInstall();
329
- if (shouldInstall) {
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
- catch (_err) {
334
- console.log();
335
- ui.print('⚠️ You can install dependencies manually by running:');
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
- console.log();
341
- ui.printHeader('📌 Next steps:');
342
- ui.print(` 1. ${chalk.bold(`cd ${projectName}`)}`);
343
- if (!options.skipInstall) {
344
- ui.print(` 2. ${chalk.bold('npm install')} (if not already done)`);
345
- ui.print(` 3. ${chalk.bold('npm start')} or ${chalk.bold('npx inworld serve graph.ts')}`);
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
- ui.print(` 2. ${chalk.bold('npm start')} or ${chalk.bold('npx inworld serve graph.ts')}`);
349
- }
350
- if (selectedTemplate.metadata.requirements?.apiKeys) {
351
- console.log();
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>', `Template to use: ${availableTemplates.map((t) => `"${t.directory}"`).join(' or ')}`)
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-package-json', 'Skip creating package.json file')
370
- .option('--skip-readme', 'Skip creating README.md file')
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 Inworld graph project (interactive if no options provided)');
375
- export const initCommandAlias = makeInitCommand(`Alias for "${chalk.bold('inworld graph init')}"`);
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