agent-stage 0.2.15 → 0.2.17
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/commands/guide.js +5 -5
- package/dist/commands/init.d.ts +2 -0
- package/dist/commands/init.js +164 -0
- package/dist/commands/page/add.js +5 -40
- package/dist/commands/run/exec.js +1 -1
- package/dist/commands/run/inspect.js +1 -1
- package/dist/commands/run/watch.js +1 -1
- package/dist/commands/serve.d.ts +2 -0
- package/dist/commands/serve.js +238 -0
- package/dist/commands/status.d.ts +2 -0
- package/dist/commands/{dev/status.js → status.js} +17 -19
- package/dist/commands/stop.d.ts +2 -0
- package/dist/commands/stop.js +40 -0
- package/dist/index.js +8 -2
- package/dist/utils/agent-helper.js +5 -5
- package/dist/utils/paths.js +5 -5
- package/dist/utils/tunnel.d.ts +1 -1
- package/dist/utils/tunnel.js +1 -1
- package/package.json +8 -5
- package/dist/commands/dev/index.d.ts +0 -2
- package/dist/commands/dev/index.js +0 -11
- package/dist/commands/dev/init.d.ts +0 -2
- package/dist/commands/dev/init.js +0 -215
- package/dist/commands/dev/start.d.ts +0 -2
- package/dist/commands/dev/start.js +0 -145
- package/dist/commands/dev/status.d.ts +0 -2
- package/dist/commands/dev/stop.d.ts +0 -2
- package/dist/commands/dev/stop.js +0 -45
- package/template/components.json +0 -17
- package/template/index.html +0 -13
- package/template/package.json +0 -41
- package/template/postcss.config.js +0 -6
- package/template/src/components/PageRenderer.tsx +0 -108
- package/template/src/components/bridge-state-provider.tsx +0 -87
- package/template/src/components/ui/button.tsx +0 -55
- package/template/src/components/ui/card.tsx +0 -78
- package/template/src/components/ui/input.tsx +0 -24
- package/template/src/index.css +0 -59
- package/template/src/lib/bridge.ts +0 -53
- package/template/src/lib/utils.ts +0 -6
- package/template/src/main.tsx +0 -23
- package/template/src/pages/counter/store.json +0 -8
- package/template/src/pages/counter/ui.json +0 -108
- package/template/src/pages/test-page/store.json +0 -8
- package/template/src/routeTree.gen.ts +0 -77
- package/template/src/routes/__root.tsx +0 -11
- package/template/src/routes/counter.tsx +0 -19
- package/template/src/routes/index.tsx +0 -46
- package/template/src/vite-env.d.ts +0 -1
- package/template/tailwind.config.js +0 -53
- package/template/tsconfig.json +0 -25
- package/template/tsconfig.node.json +0 -11
- package/template/vite.config.ts +0 -22
package/dist/index.js
CHANGED
|
@@ -7,7 +7,9 @@ import { dirname, join } from 'pathe';
|
|
|
7
7
|
// Read version from package.json
|
|
8
8
|
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
9
9
|
const pkg = JSON.parse(readFileSync(join(__dirname, '..', 'package.json'), 'utf8'));
|
|
10
|
-
import {
|
|
10
|
+
import { initCommand } from './commands/init.js';
|
|
11
|
+
import { stopCommand } from './commands/stop.js';
|
|
12
|
+
import { statusCommand } from './commands/status.js';
|
|
11
13
|
import { pageCommand } from './commands/page/index.js';
|
|
12
14
|
import { runCommand } from './commands/run/index.js';
|
|
13
15
|
import { guideCommand } from './commands/guide.js';
|
|
@@ -15,13 +17,17 @@ import { cleanupCommand } from './commands/cleanup.js';
|
|
|
15
17
|
import { componentsCommand } from './commands/components.js';
|
|
16
18
|
import { doctorCommand } from './commands/doctor.js';
|
|
17
19
|
import { verifyCommand } from './commands/verify.js';
|
|
20
|
+
import { serveCommand } from './commands/serve.js';
|
|
18
21
|
const program = new Command();
|
|
19
22
|
program
|
|
20
23
|
.name('agentstage')
|
|
21
24
|
.description('Agent UI Stage CLI - Create interactive UI for AI agents')
|
|
22
25
|
.version(pkg.version);
|
|
23
26
|
// Register commands
|
|
24
|
-
program.addCommand(
|
|
27
|
+
program.addCommand(initCommand); // init
|
|
28
|
+
program.addCommand(serveCommand); // serve <pageId>
|
|
29
|
+
program.addCommand(stopCommand); // stop
|
|
30
|
+
program.addCommand(statusCommand); // status
|
|
25
31
|
program.addCommand(pageCommand); // page add/rm/ls/manifest
|
|
26
32
|
program.addCommand(runCommand); // run get-state/set-state/exec/inspect/watch
|
|
27
33
|
program.addCommand(guideCommand); // guide
|
|
@@ -53,17 +53,17 @@ const errorGuides = {
|
|
|
53
53
|
// 运行时相关
|
|
54
54
|
'runtime_not_running': {
|
|
55
55
|
message: 'Runtime is not running',
|
|
56
|
-
cause: 'The
|
|
57
|
-
fix: 'Start
|
|
58
|
-
example: 'agentstage
|
|
59
|
-
relatedCommands: ['
|
|
56
|
+
cause: 'The runtime process is not started',
|
|
57
|
+
fix: 'Start a page runtime in another terminal',
|
|
58
|
+
example: 'agentstage serve <pageId>',
|
|
59
|
+
relatedCommands: ['serve', 'status']
|
|
60
60
|
},
|
|
61
61
|
'page_not_connected': {
|
|
62
62
|
message: 'Page is not connected',
|
|
63
63
|
cause: 'Using --live flag but page is not open in browser',
|
|
64
64
|
fix: 'Either remove --live, or open the page in browser first',
|
|
65
65
|
example: '# Option 1: File-only update\nagentstage run set-state mypage \'{...}\'\n\n# Option 2: Open page first\n# Then use --live',
|
|
66
|
-
relatedCommands: ['run set-state', '
|
|
66
|
+
relatedCommands: ['run set-state', 'serve']
|
|
67
67
|
},
|
|
68
68
|
// 路径遍历(安全)
|
|
69
69
|
'path_traversal_detected': {
|
package/dist/utils/paths.js
CHANGED
|
@@ -52,15 +52,15 @@ export async function getPidFile() {
|
|
|
52
52
|
*/
|
|
53
53
|
export async function getPagesDir() {
|
|
54
54
|
const workspace = await getWorkspaceDir();
|
|
55
|
-
// New
|
|
56
|
-
if (existsSync(join(workspace, '
|
|
57
|
-
return join(workspace, '
|
|
55
|
+
// New runtime data structure
|
|
56
|
+
if (existsSync(join(workspace, 'pages'))) {
|
|
57
|
+
return join(workspace, 'pages');
|
|
58
58
|
}
|
|
59
|
-
// Legacy
|
|
59
|
+
// Legacy template structure fallback
|
|
60
60
|
if (existsSync(join(workspace, 'src', 'pages'))) {
|
|
61
61
|
return join(workspace, 'src', 'pages');
|
|
62
62
|
}
|
|
63
|
-
throw new Error('
|
|
63
|
+
throw new Error('Pages directory not found at pages/');
|
|
64
64
|
}
|
|
65
65
|
// 运行时配置文件路径
|
|
66
66
|
export async function getRuntimeConfigFile() {
|
package/dist/utils/tunnel.d.ts
CHANGED
package/dist/utils/tunnel.js
CHANGED
package/package.json
CHANGED
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "agent-stage",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.17",
|
|
4
4
|
"files": [
|
|
5
|
-
"dist"
|
|
6
|
-
"template"
|
|
5
|
+
"dist"
|
|
7
6
|
],
|
|
8
7
|
"type": "module",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "https://github.com/parkgogogo/agent-stage"
|
|
11
|
+
},
|
|
9
12
|
"bin": {
|
|
10
13
|
"agent-stage": "./dist/index.js"
|
|
11
14
|
},
|
|
@@ -16,8 +19,8 @@
|
|
|
16
19
|
"execa": "^9.3.1",
|
|
17
20
|
"pathe": "^1.1.2",
|
|
18
21
|
"picocolors": "^1.1.1",
|
|
19
|
-
"@agentstage/render": "0.2.
|
|
20
|
-
"@agentstage/bridge": "0.1.
|
|
22
|
+
"@agentstage/render": "0.2.5",
|
|
23
|
+
"@agentstage/bridge": "0.1.3"
|
|
21
24
|
},
|
|
22
25
|
"devDependencies": {
|
|
23
26
|
"@types/node": "^22.13.5",
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { Command } from 'commander';
|
|
2
|
-
import { devInitCommand } from './init.js';
|
|
3
|
-
import { devStartCommand } from './start.js';
|
|
4
|
-
import { devStopCommand } from './stop.js';
|
|
5
|
-
import { devStatusCommand } from './status.js';
|
|
6
|
-
export const devCommand = new Command('dev')
|
|
7
|
-
.description('Development commands for Agentstage')
|
|
8
|
-
.addCommand(devInitCommand)
|
|
9
|
-
.addCommand(devStartCommand)
|
|
10
|
-
.addCommand(devStopCommand)
|
|
11
|
-
.addCommand(devStatusCommand);
|
|
@@ -1,215 +0,0 @@
|
|
|
1
|
-
import { Command } from 'commander';
|
|
2
|
-
import * as p from '@clack/prompts';
|
|
3
|
-
import consola from 'consola';
|
|
4
|
-
import c from 'picocolors';
|
|
5
|
-
import { execa } from 'execa';
|
|
6
|
-
import { mkdir, writeFile, readdir, readFile, cp } from 'fs/promises';
|
|
7
|
-
import { existsSync } from 'fs';
|
|
8
|
-
import { resolve, join, dirname } from 'pathe';
|
|
9
|
-
import { homedir } from 'os';
|
|
10
|
-
import { fileURLToPath } from 'url';
|
|
11
|
-
import { setWorkspaceDir } from '../../utils/paths.js';
|
|
12
|
-
import { checkCloudflared, printInstallInstructions } from '../../utils/cloudflared.js';
|
|
13
|
-
const PROJECT_NAME = 'webapp';
|
|
14
|
-
// Get the template directory path (works in both dev and prod)
|
|
15
|
-
function getTemplateDir() {
|
|
16
|
-
const currentFilePath = fileURLToPath(import.meta.url);
|
|
17
|
-
const currentDir = dirname(currentFilePath);
|
|
18
|
-
// Production: template is next to dist
|
|
19
|
-
// From dist/commands/dev/init.js -> dist/ -> package root
|
|
20
|
-
const prodPath = join(currentDir, '..', '..', '..', 'template');
|
|
21
|
-
// Development: template is in the source
|
|
22
|
-
// From packages/cli/src/commands/dev/init.ts -> packages/cli/
|
|
23
|
-
const devPath = join(currentDir, '..', '..', '..', '..', 'template');
|
|
24
|
-
if (existsSync(prodPath)) {
|
|
25
|
-
return prodPath;
|
|
26
|
-
}
|
|
27
|
-
if (existsSync(devPath)) {
|
|
28
|
-
return devPath;
|
|
29
|
-
}
|
|
30
|
-
// Fallback: try current working directory relative paths
|
|
31
|
-
const cwdProdPath = join(process.cwd(), 'packages', 'cli', 'template');
|
|
32
|
-
if (existsSync(cwdProdPath)) {
|
|
33
|
-
return cwdProdPath;
|
|
34
|
-
}
|
|
35
|
-
throw new Error('Template directory not found. Please ensure the CLI is properly installed.');
|
|
36
|
-
}
|
|
37
|
-
export const devInitCommand = new Command('init')
|
|
38
|
-
.description('Initialize a new Agentstage project')
|
|
39
|
-
.option('-y, --yes', 'Use default settings (non-interactive)', false)
|
|
40
|
-
.option('--skip-cloudflared-check', 'Skip cloudflared installation check', false)
|
|
41
|
-
.action(async (options) => {
|
|
42
|
-
const name = PROJECT_NAME;
|
|
43
|
-
const useDefault = options.yes;
|
|
44
|
-
// 1. Check cloudflared installation
|
|
45
|
-
if (!options.skipCloudflaredCheck) {
|
|
46
|
-
const cloudflaredInfo = await checkCloudflared();
|
|
47
|
-
if (!cloudflaredInfo.installed) {
|
|
48
|
-
printInstallInstructions(cloudflaredInfo);
|
|
49
|
-
const shouldContinue = await p.confirm({
|
|
50
|
-
message: 'Continue with initialization? (You can install cloudflared later)',
|
|
51
|
-
initialValue: true,
|
|
52
|
-
});
|
|
53
|
-
if (p.isCancel(shouldContinue) || !shouldContinue) {
|
|
54
|
-
consola.info('Cancelled');
|
|
55
|
-
process.exit(0);
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
else {
|
|
59
|
-
consola.success(`Cloudflare Tunnel available: ${c.dim(cloudflaredInfo.version)}`);
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
// 2. 选择工作目录模式
|
|
63
|
-
let locationMode;
|
|
64
|
-
if (useDefault) {
|
|
65
|
-
locationMode = 'default';
|
|
66
|
-
}
|
|
67
|
-
else {
|
|
68
|
-
const result = await p.select({
|
|
69
|
-
message: 'Where to store the project?',
|
|
70
|
-
options: [
|
|
71
|
-
{
|
|
72
|
-
value: 'default',
|
|
73
|
-
label: `Default (~/.agentstage/${name})`,
|
|
74
|
-
hint: 'Recommended',
|
|
75
|
-
},
|
|
76
|
-
{
|
|
77
|
-
value: 'current',
|
|
78
|
-
label: 'Current directory (./.agentstage)',
|
|
79
|
-
},
|
|
80
|
-
{
|
|
81
|
-
value: 'custom',
|
|
82
|
-
label: 'Custom path',
|
|
83
|
-
},
|
|
84
|
-
],
|
|
85
|
-
});
|
|
86
|
-
if (p.isCancel(result)) {
|
|
87
|
-
consola.info('Cancelled');
|
|
88
|
-
return;
|
|
89
|
-
}
|
|
90
|
-
locationMode = result;
|
|
91
|
-
}
|
|
92
|
-
// 3. 确定目标目录
|
|
93
|
-
let targetDir;
|
|
94
|
-
switch (locationMode) {
|
|
95
|
-
case 'default':
|
|
96
|
-
targetDir = join(homedir(), '.agentstage', name);
|
|
97
|
-
break;
|
|
98
|
-
case 'current':
|
|
99
|
-
targetDir = join(process.cwd(), '.agentstage');
|
|
100
|
-
break;
|
|
101
|
-
case 'custom':
|
|
102
|
-
const customPath = await p.text({
|
|
103
|
-
message: 'Enter custom path:',
|
|
104
|
-
placeholder: '/path/to/project',
|
|
105
|
-
validate: (value) => {
|
|
106
|
-
if (!value || value.trim() === '') {
|
|
107
|
-
return 'Path is required';
|
|
108
|
-
}
|
|
109
|
-
},
|
|
110
|
-
});
|
|
111
|
-
if (p.isCancel(customPath)) {
|
|
112
|
-
consola.info('Cancelled');
|
|
113
|
-
return;
|
|
114
|
-
}
|
|
115
|
-
targetDir = resolve(customPath);
|
|
116
|
-
break;
|
|
117
|
-
default:
|
|
118
|
-
targetDir = join(homedir(), '.agentstage', name);
|
|
119
|
-
}
|
|
120
|
-
// 4. 检查目录
|
|
121
|
-
if (existsSync(targetDir)) {
|
|
122
|
-
const files = await readdirSafe(targetDir);
|
|
123
|
-
if (files.length > 0) {
|
|
124
|
-
// 项目已存在,提示并退出
|
|
125
|
-
console.log();
|
|
126
|
-
consola.info('Project already initialized!');
|
|
127
|
-
console.log(` Location: ${c.cyan(targetDir)}`);
|
|
128
|
-
console.log();
|
|
129
|
-
console.log(` cd ${c.cyan(targetDir)}`);
|
|
130
|
-
console.log(` ${c.cyan('agentstage dev start')}`);
|
|
131
|
-
console.log();
|
|
132
|
-
return;
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
// 5. 保存工作目录配置
|
|
136
|
-
await setWorkspaceDir(targetDir);
|
|
137
|
-
const s = p.spinner();
|
|
138
|
-
try {
|
|
139
|
-
// 6. 复制模板文件
|
|
140
|
-
s.start('Creating project from template...');
|
|
141
|
-
const templateDir = getTemplateDir();
|
|
142
|
-
await mkdir(targetDir, { recursive: true });
|
|
143
|
-
await copyTemplateFiles(templateDir, targetDir);
|
|
144
|
-
s.stop('Project template copied');
|
|
145
|
-
// 7. 更新 package.json 中的 workspace 依赖
|
|
146
|
-
s.start('Configuring project...');
|
|
147
|
-
await configurePackageJson(targetDir);
|
|
148
|
-
s.stop('Project configured');
|
|
149
|
-
// 8. 安装依赖
|
|
150
|
-
s.start('Installing dependencies...');
|
|
151
|
-
await installDependencies(targetDir);
|
|
152
|
-
s.stop('Dependencies installed');
|
|
153
|
-
// 完成
|
|
154
|
-
console.log();
|
|
155
|
-
consola.success('Project created successfully!');
|
|
156
|
-
console.log();
|
|
157
|
-
console.log(` Location: ${c.cyan(targetDir)}`);
|
|
158
|
-
console.log();
|
|
159
|
-
console.log(` cd ${c.cyan(targetDir)}`);
|
|
160
|
-
console.log(` ${c.cyan('agentstage dev start')}`);
|
|
161
|
-
console.log();
|
|
162
|
-
console.log(c.dim('To expose your server to the internet:'));
|
|
163
|
-
console.log(` ${c.cyan('agentstage dev start --tunnel')}`);
|
|
164
|
-
console.log();
|
|
165
|
-
}
|
|
166
|
-
catch (error) {
|
|
167
|
-
s.stop('Failed to create project');
|
|
168
|
-
consola.error(error.message);
|
|
169
|
-
process.exit(1);
|
|
170
|
-
}
|
|
171
|
-
});
|
|
172
|
-
async function readdirSafe(dir) {
|
|
173
|
-
try {
|
|
174
|
-
return await readdir(dir);
|
|
175
|
-
}
|
|
176
|
-
catch {
|
|
177
|
-
return [];
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
async function copyTemplateFiles(templateDir, targetDir) {
|
|
181
|
-
const entries = await readdir(templateDir, { withFileTypes: true });
|
|
182
|
-
for (const entry of entries) {
|
|
183
|
-
const srcPath = join(templateDir, entry.name);
|
|
184
|
-
const destPath = join(targetDir, entry.name);
|
|
185
|
-
if (entry.isDirectory()) {
|
|
186
|
-
await mkdir(destPath, { recursive: true });
|
|
187
|
-
await copyTemplateFiles(srcPath, destPath);
|
|
188
|
-
}
|
|
189
|
-
else {
|
|
190
|
-
await cp(srcPath, destPath);
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
async function configurePackageJson(targetDir) {
|
|
195
|
-
const packageJsonPath = join(targetDir, 'package.json');
|
|
196
|
-
const packageJson = JSON.parse(await readFile(packageJsonPath, 'utf-8'));
|
|
197
|
-
// Replace all workspace:* dependencies with actual npm versions
|
|
198
|
-
// This fixes the EUNSUPPORTEDPROTOCOL error when users run npm install
|
|
199
|
-
const npmVersions = {
|
|
200
|
-
'@agentstage/render': '^0.2.2',
|
|
201
|
-
'@agentstage/bridge': '^0.1.0',
|
|
202
|
-
'agent-stage-bridge': '^0.1.0'
|
|
203
|
-
};
|
|
204
|
-
for (const [dep, version] of Object.entries(npmVersions)) {
|
|
205
|
-
if (packageJson.dependencies?.[dep] === 'workspace:*') {
|
|
206
|
-
packageJson.dependencies[dep] = version;
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
await writeFile(packageJsonPath, JSON.stringify(packageJson, null, 2));
|
|
210
|
-
}
|
|
211
|
-
async function installDependencies(targetDir) {
|
|
212
|
-
// Use npm with --legacy-peer-deps to resolve peer dependency conflicts
|
|
213
|
-
// This is needed because @json-render packages have strict peer deps
|
|
214
|
-
await execa('npm', ['install', '--legacy-peer-deps'], { cwd: targetDir, stdio: 'pipe' });
|
|
215
|
-
}
|
|
@@ -1,145 +0,0 @@
|
|
|
1
|
-
import { Command } from 'commander';
|
|
2
|
-
import * as p from '@clack/prompts';
|
|
3
|
-
import consola from 'consola';
|
|
4
|
-
import c from 'picocolors';
|
|
5
|
-
import { execa } from 'execa';
|
|
6
|
-
import { mkdir, writeFile } from 'fs/promises';
|
|
7
|
-
import { existsSync } from 'fs';
|
|
8
|
-
import { join } from 'pathe';
|
|
9
|
-
import { getWorkspaceDir, saveRuntimeConfig, isInitialized, readRuntimeConfig, } from '../../utils/paths.js';
|
|
10
|
-
import { startTunnel, canStartTunnel, printTunnelInfo } from '../../utils/tunnel.js';
|
|
11
|
-
import { checkCloudflared, printInstallInstructions } from '../../utils/cloudflared.js';
|
|
12
|
-
export const devStartCommand = new Command('start')
|
|
13
|
-
.description('Start the Agentstage Runtime (Vite dev server with Bridge)')
|
|
14
|
-
.option('-p, --port <port>', 'Port to run the web server on', '3000')
|
|
15
|
-
.option('-t, --tunnel', 'Expose server to internet via Cloudflare Tunnel', false)
|
|
16
|
-
.option('--open', 'Open browser automatically', false)
|
|
17
|
-
.action(async (options) => {
|
|
18
|
-
// 1. 检查是否已初始化
|
|
19
|
-
if (!isInitialized()) {
|
|
20
|
-
consola.error('Project not initialized. Please run `agentstage init` first.');
|
|
21
|
-
process.exit(1);
|
|
22
|
-
}
|
|
23
|
-
const workspaceDir = await getWorkspaceDir();
|
|
24
|
-
const port = parseInt(options.port, 10);
|
|
25
|
-
// 2. 检查是否已运行
|
|
26
|
-
const existingConfig = await readRuntimeConfig();
|
|
27
|
-
if (existingConfig) {
|
|
28
|
-
try {
|
|
29
|
-
process.kill(existingConfig.pid, 0);
|
|
30
|
-
consola.warn(`Runtime is already running (PID: ${existingConfig.pid}, Port: ${existingConfig.port})`);
|
|
31
|
-
console.log(` Web: ${c.cyan(`http://localhost:${existingConfig.port}`)}`);
|
|
32
|
-
if (existingConfig.tunnelUrl) {
|
|
33
|
-
console.log(` Public: ${c.cyan(c.underline(existingConfig.tunnelUrl))}`);
|
|
34
|
-
}
|
|
35
|
-
console.log(` Bridge: ${c.cyan(`ws://localhost:${existingConfig.port}/_bridge`)}`);
|
|
36
|
-
return;
|
|
37
|
-
}
|
|
38
|
-
catch {
|
|
39
|
-
// 进程不存在,继续启动
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
// 3. 检查是否需要安装依赖
|
|
43
|
-
const nodeModulesPath = join(workspaceDir, 'node_modules');
|
|
44
|
-
if (!existsSync(nodeModulesPath)) {
|
|
45
|
-
const s = p.spinner();
|
|
46
|
-
s.start('Installing dependencies...');
|
|
47
|
-
try {
|
|
48
|
-
await execa('npm', ['install'], { cwd: workspaceDir, stdio: 'pipe' });
|
|
49
|
-
s.stop('Dependencies installed');
|
|
50
|
-
}
|
|
51
|
-
catch (error) {
|
|
52
|
-
s.stop('Failed to install dependencies');
|
|
53
|
-
consola.error(error.message);
|
|
54
|
-
process.exit(1);
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
// 4. 检查 cloudflared (如果请求了 tunnel)
|
|
58
|
-
let tunnelUrl;
|
|
59
|
-
if (options.tunnel) {
|
|
60
|
-
const canTunnel = await canStartTunnel();
|
|
61
|
-
if (!canTunnel) {
|
|
62
|
-
const info = await checkCloudflared();
|
|
63
|
-
printInstallInstructions(info);
|
|
64
|
-
consola.error('Cannot start with --tunnel: cloudflared not installed');
|
|
65
|
-
process.exit(1);
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
const s = p.spinner();
|
|
69
|
-
s.start('Starting Agentstage Runtime...');
|
|
70
|
-
try {
|
|
71
|
-
// 5. 启动 Vite dev server
|
|
72
|
-
const subprocess = execa('npx', ['vite', '--port', String(port), '--host'], {
|
|
73
|
-
cwd: workspaceDir,
|
|
74
|
-
detached: true,
|
|
75
|
-
stdio: 'ignore',
|
|
76
|
-
});
|
|
77
|
-
await mkdir(join(workspaceDir, '.agentstage'), { recursive: true });
|
|
78
|
-
// 6. 启动 tunnel (如果请求了)
|
|
79
|
-
if (options.tunnel) {
|
|
80
|
-
s.message('Starting Cloudflare Tunnel...');
|
|
81
|
-
try {
|
|
82
|
-
const tunnel = await startTunnel(port);
|
|
83
|
-
tunnelUrl = tunnel.url;
|
|
84
|
-
// Save tunnel info for stop command to use
|
|
85
|
-
const tunnelModulePath = join(workspaceDir, '.agentstage', 'tunnel.mjs');
|
|
86
|
-
// Write tunnel info for stop command to use
|
|
87
|
-
await writeFile(tunnelModulePath, `export const tunnelUrl = '${tunnelUrl}';\nexport const tunnelPid = ${subprocess.pid};\n`);
|
|
88
|
-
}
|
|
89
|
-
catch (tunnelError) {
|
|
90
|
-
s.stop('Tunnel failed to start');
|
|
91
|
-
consola.warn(`Tunnel error: ${tunnelError.message}`);
|
|
92
|
-
consola.info('Continuing without tunnel...');
|
|
93
|
-
// Kill the vite process since we're failing
|
|
94
|
-
subprocess.kill();
|
|
95
|
-
process.exit(1);
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
// 7. 保存运行时配置
|
|
99
|
-
const config = {
|
|
100
|
-
pid: subprocess.pid,
|
|
101
|
-
port,
|
|
102
|
-
startedAt: new Date().toISOString(),
|
|
103
|
-
tunnelUrl,
|
|
104
|
-
};
|
|
105
|
-
await saveRuntimeConfig(config);
|
|
106
|
-
// 8. 等待一下确保服务启动
|
|
107
|
-
await new Promise((resolve) => setTimeout(resolve, 2000));
|
|
108
|
-
s.stop('Runtime started successfully');
|
|
109
|
-
console.log();
|
|
110
|
-
consola.success('Agentstage Runtime is running');
|
|
111
|
-
console.log(` Web: ${c.cyan(`http://localhost:${port}`)}`);
|
|
112
|
-
if (tunnelUrl) {
|
|
113
|
-
printTunnelInfo(tunnelUrl);
|
|
114
|
-
}
|
|
115
|
-
console.log(` Bridge: ${c.cyan(`ws://localhost:${port}/_bridge`)}`);
|
|
116
|
-
console.log(` Workspace: ${c.gray(workspaceDir)}`);
|
|
117
|
-
console.log();
|
|
118
|
-
if (options.open) {
|
|
119
|
-
const openUrl = tunnelUrl || `http://localhost:${port}`;
|
|
120
|
-
try {
|
|
121
|
-
await execa('open', [openUrl]);
|
|
122
|
-
}
|
|
123
|
-
catch {
|
|
124
|
-
// Ignore open errors
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
// Keep process alive to maintain tunnel
|
|
128
|
-
if (options.tunnel && tunnelUrl) {
|
|
129
|
-
console.log(c.dim('Press Ctrl+C to stop'));
|
|
130
|
-
process.on('SIGINT', async () => {
|
|
131
|
-
console.log();
|
|
132
|
-
consola.info('Shutting down...');
|
|
133
|
-
subprocess.kill();
|
|
134
|
-
process.exit(0);
|
|
135
|
-
});
|
|
136
|
-
// Keep running
|
|
137
|
-
await new Promise(() => { });
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
catch (error) {
|
|
141
|
-
s.stop('Failed to start runtime');
|
|
142
|
-
consola.error(error.message);
|
|
143
|
-
process.exit(1);
|
|
144
|
-
}
|
|
145
|
-
});
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import { Command } from 'commander';
|
|
2
|
-
import consola from 'consola';
|
|
3
|
-
import c from 'picocolors';
|
|
4
|
-
import { readRuntimeConfig, removeRuntimeConfig, isInitialized } from '../../utils/paths.js';
|
|
5
|
-
export const devStopCommand = new Command('stop')
|
|
6
|
-
.description('Stop the Agentstage Runtime')
|
|
7
|
-
.action(async () => {
|
|
8
|
-
if (!isInitialized()) {
|
|
9
|
-
consola.error('Project not initialized. Please run `agentstage init` first.');
|
|
10
|
-
process.exit(1);
|
|
11
|
-
}
|
|
12
|
-
const config = await readRuntimeConfig();
|
|
13
|
-
if (!config) {
|
|
14
|
-
consola.warn('Runtime is not running');
|
|
15
|
-
return;
|
|
16
|
-
}
|
|
17
|
-
try {
|
|
18
|
-
// Check if process exists
|
|
19
|
-
process.kill(config.pid, 0);
|
|
20
|
-
// Kill the process
|
|
21
|
-
process.kill(config.pid, 'SIGTERM');
|
|
22
|
-
// Wait a bit and check if it's still running
|
|
23
|
-
await new Promise((resolve) => setTimeout(resolve, 1000));
|
|
24
|
-
try {
|
|
25
|
-
process.kill(config.pid, 0);
|
|
26
|
-
// Still running, force kill
|
|
27
|
-
process.kill(config.pid, 'SIGKILL');
|
|
28
|
-
}
|
|
29
|
-
catch {
|
|
30
|
-
// Process already stopped
|
|
31
|
-
}
|
|
32
|
-
await removeRuntimeConfig();
|
|
33
|
-
consola.success('Runtime stopped');
|
|
34
|
-
console.log(` PID: ${c.gray(config.pid)}`);
|
|
35
|
-
console.log(` Port: ${c.gray(config.port)}`);
|
|
36
|
-
if (config.tunnelUrl) {
|
|
37
|
-
console.log(` Tunnel: ${c.gray(config.tunnelUrl)}`);
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
catch {
|
|
41
|
-
// Process doesn't exist, clean up stale config
|
|
42
|
-
await removeRuntimeConfig();
|
|
43
|
-
consola.info('Runtime was not running (stale config cleaned up)');
|
|
44
|
-
}
|
|
45
|
-
});
|
package/template/components.json
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"$schema": "https://ui.shadcn.com/schema.json",
|
|
3
|
-
"style": "default",
|
|
4
|
-
"rsc": false,
|
|
5
|
-
"tsx": true,
|
|
6
|
-
"tailwind": {
|
|
7
|
-
"config": "tailwind.config.js",
|
|
8
|
-
"css": "src/index.css",
|
|
9
|
-
"baseColor": "neutral",
|
|
10
|
-
"cssVariables": true,
|
|
11
|
-
"prefix": ""
|
|
12
|
-
},
|
|
13
|
-
"aliases": {
|
|
14
|
-
"components": "@/components",
|
|
15
|
-
"utils": "@/lib/utils"
|
|
16
|
-
}
|
|
17
|
-
}
|
package/template/index.html
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
<!doctype html>
|
|
2
|
-
<html lang="en">
|
|
3
|
-
<head>
|
|
4
|
-
<meta charset="UTF-8" />
|
|
5
|
-
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
|
|
6
|
-
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
7
|
-
<title>Agentstage App</title>
|
|
8
|
-
</head>
|
|
9
|
-
<body>
|
|
10
|
-
<div id="root"></div>
|
|
11
|
-
<script type="module" src="/src/main.tsx"></script>
|
|
12
|
-
</body>
|
|
13
|
-
</html>
|
package/template/package.json
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "agentstage-app",
|
|
3
|
-
"private": true,
|
|
4
|
-
"version": "0.0.0",
|
|
5
|
-
"type": "module",
|
|
6
|
-
"scripts": {
|
|
7
|
-
"dev": "vite",
|
|
8
|
-
"build": "tsc && vite build",
|
|
9
|
-
"preview": "vite preview",
|
|
10
|
-
"type-check": "tsc --noEmit"
|
|
11
|
-
},
|
|
12
|
-
"dependencies": {
|
|
13
|
-
"@agentstage/render": "workspace:*",
|
|
14
|
-
"@tanstack/react-router": "^1.114.3",
|
|
15
|
-
"@tanstack/router-core": "^1.114.3",
|
|
16
|
-
"@tanstack/router-devtools": "^1.114.3",
|
|
17
|
-
"agent-stage-bridge": "workspace:*",
|
|
18
|
-
"class-variance-authority": "^0.7.0",
|
|
19
|
-
"clsx": "^2.1.0",
|
|
20
|
-
"lucide-react": "^0.564.0",
|
|
21
|
-
"react": "^19.0.0",
|
|
22
|
-
"react-dom": "^19.0.0",
|
|
23
|
-
"tailwind-merge": "^2.2.0",
|
|
24
|
-
"tailwindcss-animate": "^1.0.7",
|
|
25
|
-
"zod": "^3.23.0",
|
|
26
|
-
"zustand": "^4.5.0"
|
|
27
|
-
},
|
|
28
|
-
"devDependencies": {
|
|
29
|
-
"@radix-ui/react-slot": "^1.0.2",
|
|
30
|
-
"@tanstack/router-generator": "^1.114.3",
|
|
31
|
-
"@tanstack/router-plugin": "^1.114.3",
|
|
32
|
-
"@types/react": "^19.0.0",
|
|
33
|
-
"@types/react-dom": "^19.0.0",
|
|
34
|
-
"@vitejs/plugin-react": "^4.2.1",
|
|
35
|
-
"autoprefixer": "^10.4.17",
|
|
36
|
-
"postcss": "^8.5.0",
|
|
37
|
-
"tailwindcss": "^4.0.0",
|
|
38
|
-
"typescript": "^5.2.2",
|
|
39
|
-
"vite": "^5.4.21"
|
|
40
|
-
}
|
|
41
|
-
}
|