agent-stage 0.2.14 → 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.
Files changed (68) hide show
  1. package/dist/commands/guide.js +5 -5
  2. package/dist/commands/init.d.ts +1 -1
  3. package/dist/commands/init.js +94 -138
  4. package/dist/commands/page/add.js +5 -40
  5. package/dist/commands/run/exec.js +1 -1
  6. package/dist/commands/run/inspect.js +1 -1
  7. package/dist/commands/run/watch.js +1 -1
  8. package/dist/commands/serve.d.ts +2 -0
  9. package/dist/commands/serve.js +238 -0
  10. package/dist/commands/status.d.ts +1 -1
  11. package/dist/commands/status.js +41 -40
  12. package/dist/commands/stop.d.ts +1 -1
  13. package/dist/commands/stop.js +26 -44
  14. package/dist/index.js +16 -30
  15. package/dist/utils/agent-helper.js +5 -5
  16. package/dist/utils/paths.js +5 -5
  17. package/dist/utils/tunnel.d.ts +1 -1
  18. package/dist/utils/tunnel.js +1 -1
  19. package/package.json +8 -5
  20. package/dist/commands/dev/index.d.ts +0 -2
  21. package/dist/commands/dev/index.js +0 -11
  22. package/dist/commands/dev/init.d.ts +0 -2
  23. package/dist/commands/dev/init.js +0 -215
  24. package/dist/commands/dev/start.d.ts +0 -2
  25. package/dist/commands/dev/start.js +0 -145
  26. package/dist/commands/dev/status.d.ts +0 -2
  27. package/dist/commands/dev/status.js +0 -55
  28. package/dist/commands/dev/stop.d.ts +0 -2
  29. package/dist/commands/dev/stop.js +0 -45
  30. package/dist/commands/exec.d.ts +0 -2
  31. package/dist/commands/exec.js +0 -75
  32. package/dist/commands/inspect.d.ts +0 -2
  33. package/dist/commands/inspect.js +0 -62
  34. package/dist/commands/ls.d.ts +0 -2
  35. package/dist/commands/ls.js +0 -132
  36. package/dist/commands/restart.d.ts +0 -2
  37. package/dist/commands/restart.js +0 -90
  38. package/dist/commands/rm-page.d.ts +0 -2
  39. package/dist/commands/rm-page.js +0 -32
  40. package/dist/commands/start.d.ts +0 -2
  41. package/dist/commands/start.js +0 -82
  42. package/dist/commands/watch.d.ts +0 -2
  43. package/dist/commands/watch.js +0 -54
  44. package/template/components.json +0 -17
  45. package/template/index.html +0 -13
  46. package/template/package.json +0 -41
  47. package/template/postcss.config.js +0 -6
  48. package/template/src/components/PageRenderer.tsx +0 -108
  49. package/template/src/components/bridge-state-provider.tsx +0 -87
  50. package/template/src/components/ui/button.tsx +0 -55
  51. package/template/src/components/ui/card.tsx +0 -78
  52. package/template/src/components/ui/input.tsx +0 -24
  53. package/template/src/index.css +0 -59
  54. package/template/src/lib/bridge.ts +0 -53
  55. package/template/src/lib/utils.ts +0 -6
  56. package/template/src/main.tsx +0 -23
  57. package/template/src/pages/counter/store.json +0 -8
  58. package/template/src/pages/counter/ui.json +0 -108
  59. package/template/src/pages/test-page/store.json +0 -8
  60. package/template/src/routeTree.gen.ts +0 -77
  61. package/template/src/routes/__root.tsx +0 -11
  62. package/template/src/routes/counter.tsx +0 -19
  63. package/template/src/routes/index.tsx +0 -46
  64. package/template/src/vite-env.d.ts +0 -1
  65. package/template/tailwind.config.js +0 -53
  66. package/template/tsconfig.json +0 -25
  67. package/template/tsconfig.node.json +0 -11
  68. package/template/vite.config.ts +0 -22
@@ -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,2 +0,0 @@
1
- import { Command } from 'commander';
2
- export declare const devStartCommand: Command;
@@ -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,2 +0,0 @@
1
- import { Command } from 'commander';
2
- export declare const devStatusCommand: Command;
@@ -1,55 +0,0 @@
1
- import { Command } from 'commander';
2
- import consola from 'consola';
3
- import c from 'picocolors';
4
- import { readRuntimeConfig, isInitialized, getWorkspaceDir } from '../../utils/paths.js';
5
- import { checkCloudflared } from '../../utils/cloudflared.js';
6
- export const devStatusCommand = new Command('status')
7
- .description('Check the Agentstage Runtime status')
8
- .action(async () => {
9
- if (!isInitialized()) {
10
- consola.error('Project not initialized. Please run `agentstage init` first.');
11
- process.exit(1);
12
- }
13
- const workspaceDir = await getWorkspaceDir();
14
- const config = await readRuntimeConfig();
15
- console.log();
16
- console.log(c.bold('Workspace:'), c.cyan(workspaceDir));
17
- console.log();
18
- // Check cloudflared
19
- const cloudflared = await checkCloudflared();
20
- console.log(c.bold('Cloudflare Tunnel:'));
21
- if (cloudflared.installed) {
22
- console.log(` Status: ${c.green('✓ installed')}`);
23
- console.log(` Version: ${c.gray(cloudflared.version || 'unknown')}`);
24
- }
25
- else {
26
- console.log(` Status: ${c.yellow('✗ not installed')}`);
27
- console.log(` Install: ${c.gray(cloudflared.installCommand)}`);
28
- }
29
- console.log();
30
- // Check runtime
31
- console.log(c.bold('Runtime:'));
32
- if (!config) {
33
- console.log(` Status: ${c.gray('stopped')}`);
34
- }
35
- else {
36
- try {
37
- process.kill(config.pid, 0);
38
- console.log(` Status: ${c.green('running')}`);
39
- console.log(` PID: ${c.gray(config.pid)}`);
40
- console.log(` Port: ${c.cyan(config.port)}`);
41
- console.log(` Local: ${c.cyan(`http://localhost:${config.port}`)}`);
42
- if (config.tunnelUrl) {
43
- console.log(` Public: ${c.cyan(c.underline(config.tunnelUrl))}`);
44
- }
45
- console.log(` Bridge: ${c.cyan(`ws://localhost:${config.port}/_bridge`)}`);
46
- console.log(` Started: ${c.gray(new Date(config.startedAt).toLocaleString())}`);
47
- }
48
- catch {
49
- console.log(` Status: ${c.yellow('stale (process not found)')}`);
50
- console.log(` Last PID: ${c.gray(config.pid)}`);
51
- console.log(` Last Port: ${c.gray(config.port)}`);
52
- }
53
- }
54
- console.log();
55
- });
@@ -1,2 +0,0 @@
1
- import { Command } from 'commander';
2
- export declare const devStopCommand: Command;
@@ -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
- });
@@ -1,2 +0,0 @@
1
- import { Command } from 'commander';
2
- export declare const execCommand: Command;
@@ -1,75 +0,0 @@
1
- import { Command } from 'commander';
2
- import consola from 'consola';
3
- import { join } from 'pathe';
4
- import { FileStore } from '@agentstage/bridge';
5
- import { BridgeClient } from '@agentstage/bridge/sdk';
6
- import { isInitialized, readRuntimeConfig, getPagesDir } from '../utils/paths.js';
7
- export const execCommand = new Command('exec')
8
- .description('Execute an action on a page or set state')
9
- .argument('<page>', 'Page ID')
10
- .argument('[action]', 'Action name')
11
- .argument('[payload]', 'Action payload as JSON')
12
- .option('-s, --state <json>', 'Set state directly')
13
- .option('--wait [timeoutMs]', 'Wait for browser ACK (optional timeout in ms)')
14
- .action(async (pageId, action, payload, options) => {
15
- try {
16
- if (!isInitialized()) {
17
- consola.error('Project not initialized. Please run `agentstage init` first.');
18
- process.exit(1);
19
- }
20
- const pagesDir = await getPagesDir();
21
- const fileStore = new FileStore({ pagesDir });
22
- const storePath = join(pagesDir, pageId, 'store.json');
23
- if (options.state) {
24
- const state = JSON.parse(options.state);
25
- const waitForAck = options.wait !== undefined && options.wait !== false;
26
- if (waitForAck) {
27
- const timeoutMs = typeof options.wait === 'string' && Number.isFinite(Number(options.wait))
28
- ? Number(options.wait)
29
- : 5000;
30
- const config = await readRuntimeConfig();
31
- if (!config) {
32
- consola.error('Bridge runtime is not running. Start it first or remove --wait.');
33
- process.exit(1);
34
- }
35
- const client = new BridgeClient(`ws://localhost:${config.port}/_bridge`);
36
- await client.connect();
37
- try {
38
- const result = await client.setStateByKey(pageId, 'main', state, {
39
- waitForAck: true,
40
- timeoutMs,
41
- });
42
- consola.success(`State updated with ACK (${storePath}, v${result.version})`);
43
- }
44
- finally {
45
- client.disconnect();
46
- }
47
- }
48
- else {
49
- const saved = await fileStore.save(pageId, {
50
- state,
51
- version: 0,
52
- updatedAt: new Date().toISOString(),
53
- pageId,
54
- });
55
- consola.success(`State updated (${storePath}, v${saved.version})`);
56
- }
57
- }
58
- else if (action) {
59
- // 保留命令参数兼容性,但文件模式仅支持直接写 state
60
- if (payload) {
61
- JSON.parse(payload);
62
- }
63
- consola.error('File mode only supports --state. Action dispatch requires a live Bridge connection.');
64
- process.exit(1);
65
- }
66
- else {
67
- consola.error('Please specify an action or use --state');
68
- process.exit(1);
69
- }
70
- }
71
- catch (error) {
72
- consola.error('Failed to execute:', error.message);
73
- process.exit(1);
74
- }
75
- });
@@ -1,2 +0,0 @@
1
- import { Command } from 'commander';
2
- export declare const inspectCommand: Command;
@@ -1,62 +0,0 @@
1
- import { Command } from 'commander';
2
- import consola from 'consola';
3
- import c from 'picocolors';
4
- import { BridgeClient } from '@agentstage/bridge/sdk';
5
- import { readRuntimeConfig, isInitialized } from '../utils/paths.js';
6
- export const inspectCommand = new Command('inspect')
7
- .description('Inspect a page\'s schema, actions, and current state')
8
- .argument('<page>', 'Page ID')
9
- .action(async (pageId) => {
10
- try {
11
- // 1. 检查是否已初始化
12
- if (!isInitialized()) {
13
- consola.error('Project not initialized. Please run `agentstage init` first.');
14
- process.exit(1);
15
- }
16
- // 2. 检查是否已启动
17
- const config = await readRuntimeConfig();
18
- if (!config) {
19
- consola.error('Runtime is not running. Please run `agentstage start` first.');
20
- process.exit(1);
21
- }
22
- const client = new BridgeClient(`ws://localhost:${config.port}/_bridge`);
23
- await client.connect();
24
- // 查找 page 对应的 store
25
- const stores = await client.listStores();
26
- const pageStores = stores.filter(s => s.pageId === pageId);
27
- if (pageStores.length === 0) {
28
- consola.error(`Page "${pageId}" not found or not connected`);
29
- client.disconnect();
30
- process.exit(1);
31
- }
32
- for (const storeInfo of pageStores) {
33
- const description = await client.describe?.(storeInfo.id);
34
- const state = await client.getState?.(storeInfo.id);
35
- console.log();
36
- console.log(c.bold(`${pageId}/${storeInfo.storeKey}`));
37
- console.log(c.gray('─'.repeat(40)));
38
- if (description) {
39
- console.log(c.bold('Schema:'));
40
- console.log(JSON.stringify(description.schema, null, 2));
41
- console.log();
42
- console.log(c.bold('Actions:'));
43
- if (description.actions) {
44
- for (const [name, action] of Object.entries(description.actions)) {
45
- console.log(` ${c.cyan(name)} - ${action.description || ''}`);
46
- }
47
- }
48
- console.log();
49
- }
50
- if (state) {
51
- console.log(c.bold('Current State:'));
52
- console.log(JSON.stringify(state.state, null, 2));
53
- }
54
- }
55
- console.log();
56
- client.disconnect();
57
- }
58
- catch (error) {
59
- consola.error('Failed to inspect page:', error.message);
60
- process.exit(1);
61
- }
62
- });
@@ -1,2 +0,0 @@
1
- import { Command } from 'commander';
2
- export declare const lsCommand: Command;