@agentlang/cli 0.10.4 → 0.10.6

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.
@@ -0,0 +1,193 @@
1
+ /* eslint-disable no-console */
2
+ import path from 'path';
3
+ import { existsSync } from 'fs';
4
+ import { unlink } from 'fs/promises';
5
+ import chalk from 'chalk';
6
+ import { simpleGit } from 'simple-git';
7
+ export class GitHubService {
8
+ /**
9
+ * Push changes to GitHub repository
10
+ * Creates the repository if it doesn't exist, configures remote, and pushes
11
+ * Repositories are always created under the user's account
12
+ */
13
+ async pushToGitHub(appPath, options) {
14
+ const { githubToken, githubUsername, repoName } = options;
15
+ try {
16
+ let progressMessage = 'Checking GitHub repository...';
17
+ console.log(chalk.blue(`[GitHubService] ${progressMessage}`));
18
+ try {
19
+ const response = await fetch(`https://api.github.com/repos/${githubUsername}/${repoName}`, {
20
+ headers: {
21
+ Authorization: `token ${githubToken}`,
22
+ Accept: 'application/vnd.github.v3+json',
23
+ },
24
+ });
25
+ if (response.ok) {
26
+ progressMessage = 'GitHub repository found.';
27
+ console.log(chalk.green(`[GitHubService] ${progressMessage}`));
28
+ }
29
+ else if (response.status === 404) {
30
+ progressMessage = 'Creating GitHub repository...';
31
+ console.log(chalk.yellow(`[GitHubService] ${progressMessage}`));
32
+ const createResponse = await fetch('https://api.github.com/user/repos', {
33
+ method: 'POST',
34
+ headers: {
35
+ Authorization: `token ${githubToken}`,
36
+ Accept: 'application/vnd.github.v3+json',
37
+ 'Content-Type': 'application/json',
38
+ },
39
+ body: JSON.stringify({
40
+ name: repoName,
41
+ private: true,
42
+ auto_init: false, // Don't auto-init since we'll push our own content
43
+ }),
44
+ });
45
+ if (!createResponse.ok) {
46
+ const errorData = (await createResponse.json().catch(() => ({})));
47
+ throw new Error(`Failed to create GitHub repository: ${createResponse.statusText} - ${errorData.message || ''}`);
48
+ }
49
+ progressMessage = 'GitHub repository created.';
50
+ console.log(chalk.green(`[GitHubService] ${progressMessage}`));
51
+ }
52
+ else {
53
+ const errorData = (await response.json().catch(() => ({})));
54
+ throw new Error(`Failed to check repository: ${response.statusText} - ${errorData.message || ''}`);
55
+ }
56
+ }
57
+ catch (error) {
58
+ const errorMessage = error instanceof Error ? error.message : String(error);
59
+ if (errorMessage.includes('Failed to')) {
60
+ throw error;
61
+ }
62
+ throw new Error(`Failed to check/create GitHub repository: ${errorMessage}`);
63
+ }
64
+ progressMessage = 'Initializing git repository...';
65
+ console.log(chalk.blue(`[GitHubService] ${progressMessage}`));
66
+ const git = simpleGit(appPath);
67
+ const isRepo = await git.checkIsRepo();
68
+ if (!isRepo) {
69
+ progressMessage = 'Initializing git repository...';
70
+ console.log(chalk.yellow(`[GitHubService] ${progressMessage}`));
71
+ await git.init();
72
+ await git.checkoutLocalBranch('main');
73
+ }
74
+ try {
75
+ await git.addConfig('user.name', githubUsername, false, 'local');
76
+ await git.addConfig('user.email', githubUsername, false, 'local');
77
+ }
78
+ catch (_a) {
79
+ // Config might already exist
80
+ }
81
+ progressMessage = 'Configuring git remote...';
82
+ console.log(chalk.blue(`[GitHubService] ${progressMessage}`));
83
+ const remotes = await git.getRemotes(true);
84
+ const originRemote = remotes.find(r => r.name === 'origin');
85
+ const expectedRemoteUrl = `https://${githubUsername}:${githubToken}@github.com/${githubUsername}/${repoName}.git`;
86
+ if (originRemote) {
87
+ if (originRemote.refs.fetch !== expectedRemoteUrl) {
88
+ progressMessage = 'Updating remote URL...';
89
+ console.log(chalk.yellow(`[GitHubService] ${progressMessage}`));
90
+ await git.remote(['set-url', 'origin', expectedRemoteUrl]);
91
+ }
92
+ }
93
+ else {
94
+ progressMessage = 'Adding remote origin...';
95
+ console.log(chalk.yellow(`[GitHubService] ${progressMessage}`));
96
+ await git.addRemote('origin', expectedRemoteUrl);
97
+ }
98
+ progressMessage = 'Checking for changes to push...';
99
+ console.log(chalk.blue(`[GitHubService] ${progressMessage}`));
100
+ const status = await git.status();
101
+ const currentBranch = status.current || 'main';
102
+ // Check if there are any commits to push
103
+ try {
104
+ // Check if we're ahead of remote
105
+ const branchStatus = await git.status();
106
+ // Try to fetch remote refs to see if remote branch exists
107
+ try {
108
+ await git.fetch(['origin', currentBranch]);
109
+ }
110
+ catch (_b) {
111
+ // Remote branch might not exist yet, which is fine
112
+ }
113
+ // Check if we have commits ahead of remote
114
+ if (branchStatus.ahead === 0) {
115
+ // Check if remote branch exists by trying to list remote branches
116
+ try {
117
+ const remotes = await git.getRemotes(true);
118
+ const hasOrigin = remotes.some(r => r.name === 'origin');
119
+ if (hasOrigin) {
120
+ // Try to check if remote branch exists
121
+ try {
122
+ await git.listRemote(['--heads', 'origin', currentBranch]);
123
+ // Remote branch exists and we're not ahead
124
+ return {
125
+ success: true,
126
+ message: 'Repository is up to date. Nothing to push.',
127
+ };
128
+ }
129
+ catch (_c) {
130
+ // Remote branch doesn't exist, check if we have local commits
131
+ const localLog = await git.log();
132
+ if (localLog.total === 0) {
133
+ return {
134
+ success: true,
135
+ message: 'No commits to push. Please commit your changes first.',
136
+ };
137
+ }
138
+ // We have local commits but no remote, proceed with push
139
+ }
140
+ }
141
+ else {
142
+ // No origin remote, check if we have local commits
143
+ const localLog = await git.log();
144
+ if (localLog.total === 0) {
145
+ return {
146
+ success: true,
147
+ message: 'No commits to push. Please commit your changes first.',
148
+ };
149
+ }
150
+ }
151
+ }
152
+ catch (_d) {
153
+ // If we can't check, proceed with push
154
+ }
155
+ }
156
+ // We have commits ahead, proceed with push
157
+ }
158
+ catch (error) {
159
+ // If we can't determine status, try to push anyway
160
+ // This handles edge cases where git status might fail
161
+ const errorMessage = error instanceof Error ? error.message : String(error);
162
+ console.warn(chalk.yellow(`[GitHubService] Could not determine push status, attempting push anyway: ${errorMessage}`));
163
+ }
164
+ progressMessage = 'Pushing to GitHub...';
165
+ console.log(chalk.blue(`[GitHubService] ${progressMessage}`));
166
+ await git.push(['-u', 'origin', currentBranch]);
167
+ // Clean up any potential git index locks that might interfere with file operations
168
+ // This ensures file endpoints continue to work after push
169
+ const indexLockPath = path.join(appPath, '.git', 'index.lock');
170
+ try {
171
+ if (existsSync(indexLockPath)) {
172
+ console.log(chalk.yellow('[GitHubService] Removing stale git index lock...'));
173
+ await unlink(indexLockPath);
174
+ }
175
+ }
176
+ catch (_e) {
177
+ // Ignore errors when cleaning up lock file
178
+ }
179
+ const successMessage = `Successfully pushed to GitHub: ${githubUsername}/${repoName}`;
180
+ console.log(chalk.green(`[GitHubService] ${successMessage}`));
181
+ return {
182
+ success: true,
183
+ message: successMessage,
184
+ };
185
+ }
186
+ catch (error) {
187
+ const errorMessage = error instanceof Error ? error.message : String(error);
188
+ console.error(chalk.red(`[GitHubService] Failed to push to GitHub: ${errorMessage}`));
189
+ throw error;
190
+ }
191
+ }
192
+ }
193
+ //# sourceMappingURL=GitHubService.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"GitHubService.js","sourceRoot":"","sources":["../../../src/studio/services/GitHubService.ts"],"names":[],"mappings":"AAAA,+BAA+B;AAC/B,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,UAAU,EAAE,MAAM,IAAI,CAAC;AAChC,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAEvC,MAAM,OAAO,aAAa;IACxB;;;;OAIG;IACH,KAAK,CAAC,YAAY,CAChB,OAAe,EACf,OAIC;QAED,MAAM,EAAE,WAAW,EAAE,cAAc,EAAE,QAAQ,EAAE,GAAG,OAAO,CAAC;QAE1D,IAAI,CAAC;YACH,IAAI,eAAe,GAAG,+BAA+B,CAAC;YACtD,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,mBAAmB,eAAe,EAAE,CAAC,CAAC,CAAC;YAE9D,IAAI,CAAC;gBACH,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,gCAAgC,cAAc,IAAI,QAAQ,EA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AkD,CAAC,CAAC,CAAC;oBAC9E,MAAM,MAAM,CAAC,aAAa,CAAC,CAAC;gBAC9B,CAAC;YACH,CAAC;YAAC,WAAM,CAAC;gBACP,2CAA2C;YAC7C,CAAC;YAED,MAAM,cAAc,GAAG,kCAAkC,cAAc,IAAI,QAAQ,EAAE,CAAC;YACtF,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,mBAAmB,cAAc,EAAE,CAAC,CAAC,CAAC;YAC9D,OAAO;gBACL,OAAO,EAAE,IAAI;gBACb,OAAO,EAAE,cAAc;aACxB,CAAC;QACJ,CAAC;QAAC,OAAO,KAAc,EAAE,CAAC;YACxB,MAAM,YAAY,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;YAC5E,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,6CAA6C,YAAY,EAAE,CAAC,CAAC,CAAC;YACtF,MAAM,KAAK,CAAC;QACd,CAAC;IACH,CAAC;CACF"}
@@ -0,0 +1,50 @@
1
+ import { AppManagementService } from './AppManagementService.js';
2
+ import { AppRuntimeService } from './AppRuntimeService.js';
3
+ import { GitHubService } from './GitHubService.js';
4
+ import { WorkspaceService } from './WorkspaceService.js';
5
+ export class StudioServer {
6
+ constructor(workspaceRoot, initialAppPath, fileService) {
7
+ this.appManagementService = new AppManagementService(workspaceRoot);
8
+ this.appRuntimeService = new AppRuntimeService(fileService);
9
+ this.githubService = new GitHubService();
10
+ this.workspaceService = new WorkspaceService(workspaceRoot, initialAppPath);
11
+ }
12
+ getWorkspaceRoot() {
13
+ return this.workspaceService.getWorkspaceInfo(this.appRuntimeService.getCurrentApp()).workspaceRoot;
14
+ }
15
+ getInitialAppPath() {
16
+ return this.workspaceService.getWorkspaceInfo(this.appRuntimeService.getCurrentApp()).initialAppPath;
17
+ }
18
+ discoverApps() {
19
+ return this.workspaceService.discoverApps();
20
+ }
21
+ getWorkspaceInfo() {
22
+ return this.workspaceService.getWorkspaceInfo(this.appRuntimeService.getCurrentApp());
23
+ }
24
+ async createApp(name) {
25
+ return this.appManagementService.createApp(name);
26
+ }
27
+ async forkApp(sourcePath, newAppName, options) {
28
+ return this.appManagementService.forkApp(sourcePath, newAppName, options);
29
+ }
30
+ async deleteApp(appPath) {
31
+ const currentAppPath = this.appRuntimeService.getCurrentApp();
32
+ if (currentAppPath === appPath) {
33
+ this.appRuntimeService.stopApp(true, this.getWorkspaceRoot());
34
+ }
35
+ return this.appManagementService.deleteApp(appPath);
36
+ }
37
+ async launchApp(appPath) {
38
+ return this.appRuntimeService.launchApp(appPath);
39
+ }
40
+ stopApp(resetToRoot = true) {
41
+ this.appRuntimeService.stopApp(resetToRoot, this.getWorkspaceRoot());
42
+ }
43
+ getCurrentApp() {
44
+ return this.appRuntimeService.getCurrentApp();
45
+ }
46
+ async pushToGitHub(appPath, options) {
47
+ return this.githubService.pushToGitHub(appPath, options);
48
+ }
49
+ }
50
+ //# sourceMappingURL=StudioServer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"StudioServer.js","sourceRoot":"","sources":["../../../src/studio/services/StudioServer.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AACjE,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAC3D,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAIzD,MAAM,OAAO,YAAY;IAMvB,YAAY,aAAqB,EAAE,cAA6B,EAAE,WAAwB;QACxF,IAAI,CAAC,oBAAoB,GAAG,IAAI,oBAAoB,CAAC,aAAa,CAAC,CAAC;QACpE,IAAI,CAAC,iBAAiB,GAAG,IAAI,iBAAiB,CAAC,WAAW,CAAC,CAAC;QAC5D,IAAI,CAAC,aAAa,GAAG,IAAI,aAAa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,SAAS,CAAC,OAAe;QAC7B,OAAO,IAAI,CAAC,iBAAiB,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC;IACnD,CAAC;IAED,OAAO,CAAC,WAAW,GAAG,IAAI;QACxB,IAAI,CAAC,iBAAiB,CAAC,OAAO,CAAC,WAAW,EAAE,IAAI,CAAC,gBAAgB,EAAE,CAAC,CAAC;IACvE,CAAC;IAED,aAAa;QACX,OAAO,IAAI,CAAC,iBAAiB,CAAC,aAAa,EAAE,CAAC;IAChD,CAAC;IAED,KAAK,CAAC,YAAY,CAChB,OAAe,EACf,OAIC;QAED,OAAO,IAAI,CAAC,aAAa,CAAC,YAAY,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;IAC3D,CAAC;CACF"}
@@ -0,0 +1,48 @@
1
+ /* eslint-disable no-console */
2
+ import path from 'path';
3
+ import { readdirSync, statSync } from 'fs';
4
+ import { isValidAgentlangProject, ignoredPaths } from '../utils.js';
5
+ export class WorkspaceService {
6
+ constructor(workspaceRoot, initialAppPath) {
7
+ this.workspaceRoot = workspaceRoot;
8
+ this.initialAppPath = initialAppPath;
9
+ }
10
+ discoverApps() {
11
+ const apps = [];
12
+ try {
13
+ const files = readdirSync(this.workspaceRoot);
14
+ for (const file of files) {
15
+ const fullPath = path.join(this.workspaceRoot, file);
16
+ try {
17
+ const stat = statSync(fullPath);
18
+ if (stat.isDirectory() && !ignoredPaths.has(file)) {
19
+ // Use the helper function to check if it's a valid project
20
+ if (isValidAgentlangProject(fullPath)) {
21
+ apps.push({
22
+ name: file,
23
+ path: fullPath,
24
+ isInitialApp: fullPath === this.initialAppPath,
25
+ });
26
+ }
27
+ }
28
+ }
29
+ catch (_a) {
30
+ // Ignore access errors
31
+ }
32
+ }
33
+ }
34
+ catch (error) {
35
+ console.warn('Failed to discover apps:', error);
36
+ }
37
+ return apps;
38
+ }
39
+ getWorkspaceInfo(currentApp) {
40
+ return {
41
+ workspaceRoot: this.workspaceRoot,
42
+ initialAppPath: this.initialAppPath,
43
+ currentApp,
44
+ apps: this.discoverApps(),
45
+ };
46
+ }
47
+ }
48
+ //# sourceMappingURL=WorkspaceService.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"WorkspaceService.js","sourceRoot":"","sources":["../../../src/studio/services/WorkspaceService.ts"],"names":[],"mappings":"AAAA,+BAA+B;AAC/B,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,IAAI,CAAC;AAC3C,OAAO,EAAE,uBAAuB,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAGpE,MAAM,OAAO,gBAAgB;IAC3B,YACU,aAAqB,EACrB,cAA6B;QAD7B,kBAAa,GAAb,aAAa,CAAQ;QACrB,mBAAc,GAAd,cAAc,CAAe;IACpC,CAAC;IAEJ,YAAY;QACV,MAAM,IAAI,GAAc,EAAE,CAAC;QAC3B,IAAI,CAAC;YACH,MAAM,KAAK,GAAG,WAAW,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;YAC9C,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;gBACzB,MAAM,QAAQ,GAAG,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,aAAa,EAAE,IAAI,CAAC,CAAC;gBACrD,IAAI,CAAC;oBACH,MAAM,IAAI,GAAG,QAAQ,CAAC,QAAQ,CAAC,CAAC;oBAChC,IAAI,IAAI,CAAC,WAAW,EAAE,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC;wBAClD,2DAA2D;wBAC3D,IAAI,uBAAuB,CAAC,QAAQ,CAAC,EAAE,CAAC;4BACtC,IAAI,CAAC,IAAI,CAAC;gCACR,IAAI,EAAE,IAAI;gCACV,IAAI,EAAE,QAAQ;gCACd,YAAY,EAAE,QAAQ,KAAK,IAAI,CAAC,cAAc;6BAC/C,CAAC,CAAC;wBACL,CAAC;oBACH,CAAC;gBACH,CAAC;gBAAC,WAAM,CAAC;oBACP,uBAAuB;gBACzB,CAAC;YACH,CAAC;QACH,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO,CAAC,IAAI,CAAC,0BAA0B,EAAE,KAAK,CAAC,CAAC;QAClD,CAAC;QACD,OAAO,IAAI,CAAC;IACd,CAAC;IAED,gBAAgB,CAAC,UAAyB;QACxC,OAAO;YACL,aAAa,EAAE,IAAI,CAAC,aAAa;YACjC,cAAc,EAAE,IAAI,CAAC,cAAc;YACnC,UAAU;YACV,IAAI,EAAE,IAAI,CAAC,YAAY,EAAE;SAC1B,CAAC;IACJ,CAAC;CACF"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/studio/types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,99 @@
1
+ import path from 'path';
2
+ import { existsSync, readdirSync, statSync } from 'fs';
3
+ import { fileURLToPath } from 'url';
4
+ const __filename = fileURLToPath(import.meta.url);
5
+ const __dirname = path.dirname(__filename);
6
+ export const ignoredPaths = new Set(['node_modules', '.git', 'dist', 'out', 'logs']);
7
+ /**
8
+ * Check if a directory is a valid Agentlang project
9
+ * A valid project has either a package.json or .al files
10
+ */
11
+ export function isValidAgentlangProject(dirPath) {
12
+ try {
13
+ // Check for package.json
14
+ if (existsSync(path.join(dirPath, 'package.json'))) {
15
+ return true;
16
+ }
17
+ // Check for .al files in the directory
18
+ const files = readdirSync(dirPath);
19
+ return files.some(f => f.endsWith('.al'));
20
+ }
21
+ catch (_a) {
22
+ return false;
23
+ }
24
+ }
25
+ /**
26
+ * Smart Parent Detection: Determine the workspace root
27
+ * If the given directory is itself a project, use its parent as the workspace root
28
+ * This allows sibling projects to be discovered and new projects to be created as siblings
29
+ */
30
+ export function getWorkspaceRoot(dirPath) {
31
+ const isProject = isValidAgentlangProject(dirPath);
32
+ if (isProject) {
33
+ const parentDir = path.dirname(dirPath);
34
+ // Check if parent has other valid projects (siblings)
35
+ try {
36
+ const siblings = readdirSync(parentDir).filter(name => {
37
+ if (ignoredPaths.has(name))
38
+ return false;
39
+ const siblingPath = path.join(parentDir, name);
40
+ try {
41
+ return statSync(siblingPath).isDirectory() && isValidAgentlangProject(siblingPath);
42
+ }
43
+ catch (_a) {
44
+ return false;
45
+ }
46
+ });
47
+ // If there are sibling projects (including current), use parent as workspace
48
+ if (siblings.length >= 1) {
49
+ return {
50
+ workspaceRoot: parentDir,
51
+ initialAppPath: dirPath, // The project we launched from
52
+ };
53
+ }
54
+ }
55
+ catch (_a) {
56
+ // If we can't read parent, fall back to using dirPath as workspace
57
+ }
58
+ // Even if no siblings, if dirPath is a project, use parent as workspace
59
+ // This allows creating new sibling projects
60
+ return {
61
+ workspaceRoot: parentDir,
62
+ initialAppPath: dirPath,
63
+ };
64
+ }
65
+ // dirPath is not a project, use it as workspace root
66
+ return {
67
+ workspaceRoot: dirPath,
68
+ initialAppPath: null,
69
+ };
70
+ }
71
+ export function findLStudioPath(projectDir) {
72
+ // First, try to find @agentlang/lstudio in the project's node_modules
73
+ // Check for dist subfolder first (local development)
74
+ const projectLStudioDistPath = path.join(projectDir, 'node_modules', '@agentlang', 'lstudio', 'dist');
75
+ if (existsSync(projectLStudioDistPath) && existsSync(path.join(projectLStudioDistPath, 'index.html'))) {
76
+ return projectLStudioDistPath;
77
+ }
78
+ // Check root of package (npm installed version)
79
+ const projectLStudioRootPath = path.join(projectDir, 'node_modules', '@agentlang', 'lstudio');
80
+ if (existsSync(path.join(projectLStudioRootPath, 'index.html'))) {
81
+ return projectLStudioRootPath;
82
+ }
83
+ // If not found, try agentlang-cli's node_modules
84
+ // Check for dist subfolder first
85
+ // Note: We need to go up one level from src/studio to get to root, then to node_modules if running from src
86
+ // But if this file is in dist, __dirname structure might be different.
87
+ // Assuming standard structure where this runs from dist/studio or src/studio
88
+ const cliLStudioDistPath = path.join(__dirname, '..', '..', 'node_modules', '@agentlang', 'lstudio', 'dist');
89
+ if (existsSync(cliLStudioDistPath) && existsSync(path.join(cliLStudioDistPath, 'index.html'))) {
90
+ return cliLStudioDistPath;
91
+ }
92
+ // Check root of package in cli's node_modules
93
+ const cliLStudioRootPath = path.join(__dirname, '..', '..', 'node_modules', '@agentlang', 'lstudio');
94
+ if (existsSync(path.join(cliLStudioRootPath, 'index.html'))) {
95
+ return cliLStudioRootPath;
96
+ }
97
+ return null;
98
+ }
99
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/studio/utils.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,IAAI,CAAC;AACvD,OAAO,EAAE,aAAa,EAAE,MAAM,KAAK,CAAC;AAEpC,MAAM,UAAU,GAAG,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAClD,MAAM,SAAS,GAAG,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;AAE3C,MAAM,CAAC,MAAM,YAAY,GAAG,IAAI,GAAG,CAAC,CAAC,cAAc,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC,CAAC;AASrF;;;GAGG;AACH,MAAM,UAAU,uBAAuB,CAAC,OAAe;IACrD,IAAI,CAAC;QACH,yBAAyB;QACzB,IAAI,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,cAAc,CAAC,CAAC,EAAE,CAAC;YACnD,OAAO,IAAI,CAAC;QACd,CAAC;QAED,uCAAuC;QACvC,MAAM,KAAK,GAAG,WAAW,CAAC,OAAO,CAAC,CAAC;QACnC,OAAO,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC;IAC5C,CAAC;IAAC,WAAM,CAAC;QACP,OAAO,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