farseer-cli 1.0.9 → 1.0.10
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/app.js +344 -316
- package/dist/commands/apps.js +83 -103
- package/dist/commands/checkout.js +156 -134
- package/dist/commands/config.js +126 -124
- package/dist/commands/diff.js +194 -169
- package/dist/commands/dimensions.js +122 -137
- package/dist/commands/files.js +77 -88
- package/dist/commands/install.js +77 -74
- package/dist/commands/list.js +74 -89
- package/dist/commands/login.js +101 -126
- package/dist/commands/logout.js +42 -57
- package/dist/commands/mcp-server.js +24 -39
- package/dist/commands/model.js +176 -184
- package/dist/commands/pull.js +276 -248
- package/dist/commands/push.js +222 -200
- package/dist/commands/run.js +322 -274
- package/dist/commands/status.js +170 -147
- package/dist/commands/variables.js +192 -168
- package/dist/commands/whoami.js +45 -61
- package/dist/index.js +115 -117
- package/dist/mcp/index.js +17 -33
- package/dist/mcp/prompts/workflows.js +146 -191
- package/dist/mcp/resources/documentation.js +149 -158
- package/dist/mcp/server.js +34 -50
- package/dist/mcp/tools/appTools.js +278 -307
- package/dist/mcp/tools/authTools.js +123 -130
- package/dist/mcp/tools/dataTools.js +271 -275
- package/dist/mcp/tools/modelTools.js +233 -265
- package/dist/mcp/tools/runTools.js +205 -199
- package/dist/mcp/tools/syncTools.js +315 -341
- package/dist/mcp/utils/helpers.js +124 -117
- package/dist/services/appSyncService.js +438 -379
- package/dist/services/configService.js +144 -154
- package/dist/services/farseerApi.js +401 -401
- package/dist/services/farseerFactory.js +274 -208
- package/dist/services/farseerService.js +488 -455
- package/dist/services/syncService.js +732 -657
- package/dist/utils/constants.js +20 -45
- package/dist/utils/helpers.js +366 -333
- package/dist/utils/logger.js +43 -74
- package/package.json +8 -1
- package/dist/commands/app.js.map +0 -7
- package/dist/commands/apps.js.map +0 -7
- package/dist/commands/checkout.js.map +0 -7
- package/dist/commands/config.js.map +0 -7
- package/dist/commands/diff.js.map +0 -7
- package/dist/commands/dimensions.js.map +0 -7
- package/dist/commands/files.js.map +0 -7
- package/dist/commands/install.js.map +0 -7
- package/dist/commands/list.js.map +0 -7
- package/dist/commands/login.js.map +0 -7
- package/dist/commands/logout.js.map +0 -7
- package/dist/commands/mcp-server.js.map +0 -7
- package/dist/commands/model.js.map +0 -7
- package/dist/commands/pull.js.map +0 -7
- package/dist/commands/push.js.map +0 -7
- package/dist/commands/run.js.map +0 -7
- package/dist/commands/status.js.map +0 -7
- package/dist/commands/variables.js.map +0 -7
- package/dist/commands/whoami.js.map +0 -7
- package/dist/index.js.map +0 -7
- package/dist/mcp/index.js.map +0 -7
- package/dist/mcp/prompts/workflows.js.map +0 -7
- package/dist/mcp/resources/documentation.js.map +0 -7
- package/dist/mcp/server.js.map +0 -7
- package/dist/mcp/tools/appTools.js.map +0 -7
- package/dist/mcp/tools/authTools.js.map +0 -7
- package/dist/mcp/tools/dataTools.js.map +0 -7
- package/dist/mcp/tools/modelTools.js.map +0 -7
- package/dist/mcp/tools/runTools.js.map +0 -7
- package/dist/mcp/tools/syncTools.js.map +0 -7
- package/dist/mcp/utils/helpers.js.map +0 -7
- package/dist/services/appSyncService.js.map +0 -7
- package/dist/services/configService.js.map +0 -7
- package/dist/services/farseerApi.js.map +0 -7
- package/dist/services/farseerFactory.js.map +0 -7
- package/dist/services/farseerService.js.map +0 -7
- package/dist/services/syncService.js.map +0 -7
- package/dist/utils/constants.js.map +0 -7
- package/dist/utils/helpers.js.map +0 -7
- package/dist/utils/logger.js.map +0 -7
|
@@ -1,87 +1,107 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
var
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
-
mod
|
|
26
|
-
));
|
|
27
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
-
var runTools_exports = {};
|
|
29
|
-
__export(runTools_exports, {
|
|
30
|
-
registerRunTools: () => registerRunTools
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* App Execution Tools
|
|
4
|
+
*
|
|
5
|
+
* Tools for running Farseer apps locally.
|
|
6
|
+
*/
|
|
7
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
8
|
+
if (k2 === undefined) k2 = k;
|
|
9
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
10
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
11
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
12
|
+
}
|
|
13
|
+
Object.defineProperty(o, k2, desc);
|
|
14
|
+
}) : (function(o, m, k, k2) {
|
|
15
|
+
if (k2 === undefined) k2 = k;
|
|
16
|
+
o[k2] = m[k];
|
|
17
|
+
}));
|
|
18
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
19
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
20
|
+
}) : function(o, v) {
|
|
21
|
+
o["default"] = v;
|
|
31
22
|
});
|
|
32
|
-
|
|
33
|
-
var
|
|
34
|
-
|
|
35
|
-
var
|
|
36
|
-
var
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
23
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
24
|
+
var ownKeys = function(o) {
|
|
25
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
26
|
+
var ar = [];
|
|
27
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
28
|
+
return ar;
|
|
29
|
+
};
|
|
30
|
+
return ownKeys(o);
|
|
31
|
+
};
|
|
32
|
+
return function (mod) {
|
|
33
|
+
if (mod && mod.__esModule) return mod;
|
|
34
|
+
var result = {};
|
|
35
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
36
|
+
__setModuleDefault(result, mod);
|
|
37
|
+
return result;
|
|
38
|
+
};
|
|
39
|
+
})();
|
|
40
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
41
|
+
exports.registerRunTools = registerRunTools;
|
|
42
|
+
const zod_1 = require("zod");
|
|
43
|
+
const child_process_1 = require("child_process");
|
|
44
|
+
const fs = __importStar(require("fs"));
|
|
45
|
+
const path = __importStar(require("path"));
|
|
46
|
+
const farseerFactory_1 = require("../../services/farseerFactory");
|
|
47
|
+
const configService_1 = require("../../services/configService");
|
|
48
|
+
const farseerService_1 = require("../../services/farseerService");
|
|
49
|
+
const helpers_1 = require("../../utils/helpers");
|
|
50
|
+
const helpers_2 = require("../utils/helpers");
|
|
42
51
|
async function getRunCredentials(organisation, tenant) {
|
|
43
|
-
|
|
44
|
-
|
|
52
|
+
// First try API key config
|
|
53
|
+
const credential = (0, configService_1.getCredential)(tenant);
|
|
54
|
+
if (credential) {
|
|
55
|
+
return {
|
|
56
|
+
tenantId: credential.tenantId,
|
|
57
|
+
apiKey: credential.apiKey,
|
|
58
|
+
basePath: credential.basePath,
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
// Try user auth (browser login)
|
|
62
|
+
const auth = (0, configService_1.getUserAuth)();
|
|
63
|
+
if (!auth) {
|
|
64
|
+
return null;
|
|
65
|
+
}
|
|
66
|
+
// Check if token needs refresh
|
|
67
|
+
if (!(0, configService_1.isUserAuthValid)()) {
|
|
68
|
+
const refreshed = await (0, farseerService_1.refreshAccessToken)(auth.refreshToken, auth.realm || 'master');
|
|
69
|
+
if (!refreshed) {
|
|
70
|
+
return null;
|
|
71
|
+
}
|
|
72
|
+
// Save refreshed token
|
|
73
|
+
(0, configService_1.setUserAuth)({
|
|
74
|
+
accessToken: refreshed.accessToken,
|
|
75
|
+
refreshToken: refreshed.refreshToken,
|
|
76
|
+
expiresAt: new Date(Date.now() + refreshed.expiresIn * 1000).toISOString(),
|
|
77
|
+
realm: auth.realm,
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
const updatedAuth = (0, configService_1.getUserAuth)();
|
|
81
|
+
if (!updatedAuth)
|
|
82
|
+
return null;
|
|
45
83
|
return {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
84
|
+
tenantId: tenant,
|
|
85
|
+
accessToken: updatedAuth.accessToken,
|
|
86
|
+
basePath: (0, configService_1.generateBasePath)(organisation),
|
|
49
87
|
};
|
|
50
|
-
}
|
|
51
|
-
const auth = (0, import_configService.getUserAuth)();
|
|
52
|
-
if (!auth) {
|
|
53
|
-
return null;
|
|
54
|
-
}
|
|
55
|
-
if (!(0, import_configService.isUserAuthValid)()) {
|
|
56
|
-
const refreshed = await (0, import_farseerService.refreshAccessToken)(auth.refreshToken, auth.realm || "master");
|
|
57
|
-
if (!refreshed) {
|
|
58
|
-
return null;
|
|
59
|
-
}
|
|
60
|
-
(0, import_configService.setUserAuth)({
|
|
61
|
-
accessToken: refreshed.accessToken,
|
|
62
|
-
refreshToken: refreshed.refreshToken,
|
|
63
|
-
expiresAt: new Date(Date.now() + refreshed.expiresIn * 1e3).toISOString(),
|
|
64
|
-
realm: auth.realm
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
|
-
const updatedAuth = (0, import_configService.getUserAuth)();
|
|
68
|
-
if (!updatedAuth) return null;
|
|
69
|
-
return {
|
|
70
|
-
tenantId: tenant,
|
|
71
|
-
accessToken: updatedAuth.accessToken,
|
|
72
|
-
basePath: (0, import_configService.generateBasePath)(organisation)
|
|
73
|
-
};
|
|
74
88
|
}
|
|
89
|
+
// Define schemas outside of tool registration to avoid deep type instantiation
|
|
75
90
|
const runAppSchema = {
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
91
|
+
organisation: zod_1.z
|
|
92
|
+
.string()
|
|
93
|
+
.optional()
|
|
94
|
+
.describe('Farseer organisation (subdomain). If omitted, uses checked-out org or saved mapping.'),
|
|
95
|
+
tenant: zod_1.z.string().optional().describe('Tenant ID. Uses checked-out tenant if omitted.'),
|
|
96
|
+
appName: zod_1.z.string().describe('Name of the app to run'),
|
|
97
|
+
argumentOverrides: zod_1.z
|
|
98
|
+
.record(zod_1.z.string(), zod_1.z.string())
|
|
99
|
+
.optional()
|
|
100
|
+
.describe('Override argument values (Name: Value pairs)'),
|
|
80
101
|
};
|
|
81
102
|
function registerRunTools(server) {
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
`Run a Farseer app locally.
|
|
103
|
+
// farseer_run_app - Run an app locally
|
|
104
|
+
server.tool('farseer_run_app', `Run a Farseer app locally.
|
|
85
105
|
|
|
86
106
|
This executes the app's entrypoint script using npx tsx with credentials automatically injected.
|
|
87
107
|
The script's FarseerClient() constructor picks up the injected env vars - no hardcoded credentials needed.
|
|
@@ -102,132 +122,118 @@ Requirements:
|
|
|
102
122
|
Arguments can be overridden using the argumentOverrides parameter.
|
|
103
123
|
Arguments not overridden use their default values from app config.
|
|
104
124
|
|
|
105
|
-
If no tenant is specified, uses the currently checked-out tenant.`,
|
|
106
|
-
|
|
125
|
+
If no tenant is specified, uses the currently checked-out tenant.`, runAppSchema,
|
|
126
|
+
// @ts-expect-error TS2589 - MCP SDK deep type inference with zod schemas
|
|
107
127
|
async (params) => {
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
}
|
|
112
|
-
const { organisation, tenant } = resolved;
|
|
113
|
-
const clientResult = await (0, import_farseerFactory.getFarseerClientWithFallback)(organisation, tenant);
|
|
114
|
-
if (!clientResult) {
|
|
115
|
-
return (0, import_helpers2.authRequiredResponse)(tenant);
|
|
116
|
-
}
|
|
117
|
-
try {
|
|
118
|
-
const app = await clientResult.client.getAppByName(params.appName);
|
|
119
|
-
if (!app) {
|
|
120
|
-
return (0, import_helpers2.errorResponse)(`App "${params.appName}" not found`, "NOT_FOUND");
|
|
121
|
-
}
|
|
122
|
-
if (!app.mainScriptFileId || app.scriptFiles.length === 0) {
|
|
123
|
-
return (0, import_helpers2.errorResponse)(
|
|
124
|
-
`App "${params.appName}" has no scripts configured. Configure it with farseer_configure_app.`,
|
|
125
|
-
"VALIDATION_ERROR"
|
|
126
|
-
);
|
|
127
|
-
}
|
|
128
|
-
const mainScript = app.scriptFiles.find((s) => s.id === app.mainScriptFileId);
|
|
129
|
-
if (!mainScript) {
|
|
130
|
-
return (0, import_helpers2.errorResponse)(`Entrypoint script not found for app "${params.appName}"`, "NOT_FOUND");
|
|
131
|
-
}
|
|
132
|
-
const credentials = await getRunCredentials(organisation, tenant);
|
|
133
|
-
if (!credentials) {
|
|
134
|
-
return (0, import_helpers2.authRequiredResponse)(tenant);
|
|
128
|
+
const resolved = (0, helpers_2.resolveOrgAndTenant)(params);
|
|
129
|
+
if (!resolved) {
|
|
130
|
+
return (0, helpers_2.tenantRequiredResponse)();
|
|
135
131
|
}
|
|
136
|
-
const
|
|
137
|
-
const
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
return (0, import_helpers2.errorResponse)(
|
|
141
|
-
`Script not found locally: ${mainScript.name}. Run farseer_pull first.`,
|
|
142
|
-
"NOT_FOUND"
|
|
143
|
-
);
|
|
132
|
+
const { organisation, tenant } = resolved;
|
|
133
|
+
const clientResult = await (0, farseerFactory_1.getFarseerClientWithFallback)(organisation, tenant);
|
|
134
|
+
if (!clientResult) {
|
|
135
|
+
return (0, helpers_2.authRequiredResponse)(tenant);
|
|
144
136
|
}
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
137
|
+
try {
|
|
138
|
+
// Get app details
|
|
139
|
+
const app = await clientResult.client.getAppByName(params.appName);
|
|
140
|
+
if (!app) {
|
|
141
|
+
return (0, helpers_2.errorResponse)(`App "${params.appName}" not found`, 'NOT_FOUND');
|
|
142
|
+
}
|
|
143
|
+
const runScripts = app.scriptFiles ?? [];
|
|
144
|
+
if (!app.mainScriptFileId || runScripts.length === 0) {
|
|
145
|
+
return (0, helpers_2.errorResponse)(`App "${params.appName}" has no scripts configured. Configure it with farseer_configure_app.`, 'VALIDATION_ERROR');
|
|
146
|
+
}
|
|
147
|
+
// Find entrypoint script
|
|
148
|
+
const mainScript = runScripts.find((s) => s.id === app.mainScriptFileId);
|
|
149
|
+
if (!mainScript) {
|
|
150
|
+
return (0, helpers_2.errorResponse)(`Entrypoint script not found for app "${params.appName}"`, 'NOT_FOUND');
|
|
151
|
+
}
|
|
152
|
+
// Get run credentials
|
|
153
|
+
const credentials = await getRunCredentials(organisation, tenant);
|
|
154
|
+
if (!credentials) {
|
|
155
|
+
return (0, helpers_2.authRequiredResponse)(tenant);
|
|
156
|
+
}
|
|
157
|
+
const tenantDir = (0, helpers_1.getTenantDir)(tenant);
|
|
158
|
+
const srcDir = (0, helpers_1.getTenantSrcDir)(tenant);
|
|
159
|
+
const scriptPath = path.resolve(srcDir, mainScript.name);
|
|
160
|
+
// Check if script exists locally
|
|
161
|
+
if (!fs.existsSync(scriptPath)) {
|
|
162
|
+
return (0, helpers_2.errorResponse)(`Script not found locally: ${mainScript.name}. Run farseer_pull first.`, 'NOT_FOUND');
|
|
163
|
+
}
|
|
164
|
+
// Check if node_modules exists
|
|
165
|
+
const nodeModulesPath = path.join(tenantDir, 'node_modules');
|
|
166
|
+
if (!fs.existsSync(nodeModulesPath)) {
|
|
167
|
+
return (0, helpers_2.errorResponse)(`Dependencies not installed. Run "farseer install ${tenant}" in terminal first.`, 'VALIDATION_ERROR');
|
|
168
|
+
}
|
|
169
|
+
// Build arguments
|
|
170
|
+
const appArgs = {};
|
|
171
|
+
// Start with defaults
|
|
172
|
+
for (const arg of app.expectedArguments) {
|
|
173
|
+
appArgs[arg.name] = arg.defaultValue;
|
|
174
|
+
}
|
|
175
|
+
// Apply overrides
|
|
176
|
+
if (params.argumentOverrides) {
|
|
177
|
+
for (const [name, value] of Object.entries(params.argumentOverrides)) {
|
|
178
|
+
appArgs[name] = value;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
// Build environment
|
|
182
|
+
const envVars = {
|
|
183
|
+
...process.env,
|
|
184
|
+
TENANT_ID: credentials.tenantId,
|
|
185
|
+
FARSEER_URL: credentials.basePath,
|
|
186
|
+
};
|
|
187
|
+
if (credentials.apiKey) {
|
|
188
|
+
envVars.FARSEER_API_KEY = credentials.apiKey;
|
|
189
|
+
}
|
|
190
|
+
if (credentials.accessToken) {
|
|
191
|
+
envVars.FARSEER_ACCESS_TOKEN = credentials.accessToken;
|
|
192
|
+
}
|
|
193
|
+
// Build command line arguments (in order)
|
|
194
|
+
const cmdArgs = [];
|
|
195
|
+
for (const arg of app.expectedArguments) {
|
|
196
|
+
cmdArgs.push(appArgs[arg.name] ?? arg.defaultValue);
|
|
197
|
+
}
|
|
198
|
+
// Run the script
|
|
199
|
+
return new Promise((resolve) => {
|
|
200
|
+
let stdout = '';
|
|
201
|
+
let stderr = '';
|
|
202
|
+
const child = (0, child_process_1.spawn)('npx', ['tsx', `files/Scripts/${mainScript.name}`, ...cmdArgs], {
|
|
203
|
+
cwd: tenantDir,
|
|
204
|
+
shell: true,
|
|
205
|
+
env: envVars,
|
|
206
|
+
});
|
|
207
|
+
child.stdout?.on('data', (data) => {
|
|
208
|
+
stdout += data.toString();
|
|
209
|
+
});
|
|
210
|
+
child.stderr?.on('data', (data) => {
|
|
211
|
+
stderr += data.toString();
|
|
212
|
+
});
|
|
213
|
+
child.on('close', (code) => {
|
|
214
|
+
resolve((0, helpers_2.successResponse)({
|
|
215
|
+
tenant,
|
|
216
|
+
app: params.appName,
|
|
217
|
+
script: mainScript.name,
|
|
218
|
+
arguments: appArgs,
|
|
219
|
+
exitCode: code ?? 0,
|
|
220
|
+
stdout: stdout.slice(0, 10000), // Limit output size
|
|
221
|
+
stderr: stderr.slice(0, 5000),
|
|
222
|
+
truncated: stdout.length > 10000 || stderr.length > 5000,
|
|
223
|
+
}));
|
|
224
|
+
});
|
|
225
|
+
child.on('error', (err) => {
|
|
226
|
+
resolve((0, helpers_2.errorResponse)(`Failed to run script: ${err.message}. Make sure tsx is installed: npm install -g tsx`, 'UNKNOWN'));
|
|
227
|
+
});
|
|
228
|
+
// Timeout after 5 minutes
|
|
229
|
+
setTimeout(() => {
|
|
230
|
+
child.kill();
|
|
231
|
+
resolve((0, helpers_2.errorResponse)('Script execution timed out after 5 minutes', 'UNKNOWN'));
|
|
232
|
+
}, 5 * 60 * 1000);
|
|
233
|
+
});
|
|
151
234
|
}
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
appArgs[arg.name] = arg.defaultValue;
|
|
155
|
-
}
|
|
156
|
-
if (params.argumentOverrides) {
|
|
157
|
-
for (const [name, value] of Object.entries(params.argumentOverrides)) {
|
|
158
|
-
appArgs[name] = value;
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
const envVars = {
|
|
162
|
-
...process.env,
|
|
163
|
-
TENANT_ID: credentials.tenantId,
|
|
164
|
-
FARSEER_URL: credentials.basePath
|
|
165
|
-
};
|
|
166
|
-
if (credentials.apiKey) {
|
|
167
|
-
envVars.FARSEER_API_KEY = credentials.apiKey;
|
|
235
|
+
catch (error) {
|
|
236
|
+
return (0, helpers_2.errorResponse)(`Run app failed: ${error instanceof Error ? error.message : 'Unknown error'}`, 'NETWORK_ERROR');
|
|
168
237
|
}
|
|
169
|
-
|
|
170
|
-
envVars.FARSEER_ACCESS_TOKEN = credentials.accessToken;
|
|
171
|
-
}
|
|
172
|
-
const cmdArgs = [];
|
|
173
|
-
for (const arg of app.expectedArguments) {
|
|
174
|
-
cmdArgs.push(appArgs[arg.name] ?? arg.defaultValue);
|
|
175
|
-
}
|
|
176
|
-
return new Promise((resolve) => {
|
|
177
|
-
let stdout = "";
|
|
178
|
-
let stderr = "";
|
|
179
|
-
const child = (0, import_child_process.spawn)("npx", ["tsx", `files/Scripts/${mainScript.name}`, ...cmdArgs], {
|
|
180
|
-
cwd: tenantDir,
|
|
181
|
-
shell: true,
|
|
182
|
-
env: envVars
|
|
183
|
-
});
|
|
184
|
-
child.stdout?.on("data", (data) => {
|
|
185
|
-
stdout += data.toString();
|
|
186
|
-
});
|
|
187
|
-
child.stderr?.on("data", (data) => {
|
|
188
|
-
stderr += data.toString();
|
|
189
|
-
});
|
|
190
|
-
child.on("close", (code) => {
|
|
191
|
-
resolve(
|
|
192
|
-
(0, import_helpers2.successResponse)({
|
|
193
|
-
tenant,
|
|
194
|
-
app: params.appName,
|
|
195
|
-
script: mainScript.name,
|
|
196
|
-
arguments: appArgs,
|
|
197
|
-
exitCode: code ?? 0,
|
|
198
|
-
stdout: stdout.slice(0, 1e4),
|
|
199
|
-
// Limit output size
|
|
200
|
-
stderr: stderr.slice(0, 5e3),
|
|
201
|
-
truncated: stdout.length > 1e4 || stderr.length > 5e3
|
|
202
|
-
})
|
|
203
|
-
);
|
|
204
|
-
});
|
|
205
|
-
child.on("error", (err) => {
|
|
206
|
-
resolve(
|
|
207
|
-
(0, import_helpers2.errorResponse)(
|
|
208
|
-
`Failed to run script: ${err.message}. Make sure tsx is installed: npm install -g tsx`,
|
|
209
|
-
"UNKNOWN"
|
|
210
|
-
)
|
|
211
|
-
);
|
|
212
|
-
});
|
|
213
|
-
setTimeout(() => {
|
|
214
|
-
child.kill();
|
|
215
|
-
resolve(
|
|
216
|
-
(0, import_helpers2.errorResponse)("Script execution timed out after 5 minutes", "UNKNOWN")
|
|
217
|
-
);
|
|
218
|
-
}, 5 * 60 * 1e3);
|
|
219
|
-
});
|
|
220
|
-
} catch (error) {
|
|
221
|
-
return (0, import_helpers2.errorResponse)(
|
|
222
|
-
`Run app failed: ${error instanceof Error ? error.message : "Unknown error"}`,
|
|
223
|
-
"NETWORK_ERROR"
|
|
224
|
-
);
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
);
|
|
238
|
+
});
|
|
228
239
|
}
|
|
229
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
230
|
-
0 && (module.exports = {
|
|
231
|
-
registerRunTools
|
|
232
|
-
});
|
|
233
|
-
//# sourceMappingURL=runTools.js.map
|