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.
Files changed (81) hide show
  1. package/dist/commands/app.js +344 -316
  2. package/dist/commands/apps.js +83 -103
  3. package/dist/commands/checkout.js +156 -134
  4. package/dist/commands/config.js +126 -124
  5. package/dist/commands/diff.js +194 -169
  6. package/dist/commands/dimensions.js +122 -137
  7. package/dist/commands/files.js +77 -88
  8. package/dist/commands/install.js +77 -74
  9. package/dist/commands/list.js +74 -89
  10. package/dist/commands/login.js +101 -126
  11. package/dist/commands/logout.js +42 -57
  12. package/dist/commands/mcp-server.js +24 -39
  13. package/dist/commands/model.js +176 -184
  14. package/dist/commands/pull.js +276 -248
  15. package/dist/commands/push.js +222 -200
  16. package/dist/commands/run.js +322 -274
  17. package/dist/commands/status.js +170 -147
  18. package/dist/commands/variables.js +192 -168
  19. package/dist/commands/whoami.js +45 -61
  20. package/dist/index.js +115 -117
  21. package/dist/mcp/index.js +17 -33
  22. package/dist/mcp/prompts/workflows.js +146 -191
  23. package/dist/mcp/resources/documentation.js +149 -158
  24. package/dist/mcp/server.js +34 -50
  25. package/dist/mcp/tools/appTools.js +278 -307
  26. package/dist/mcp/tools/authTools.js +123 -130
  27. package/dist/mcp/tools/dataTools.js +271 -275
  28. package/dist/mcp/tools/modelTools.js +233 -265
  29. package/dist/mcp/tools/runTools.js +205 -199
  30. package/dist/mcp/tools/syncTools.js +315 -341
  31. package/dist/mcp/utils/helpers.js +124 -117
  32. package/dist/services/appSyncService.js +438 -379
  33. package/dist/services/configService.js +144 -154
  34. package/dist/services/farseerApi.js +401 -401
  35. package/dist/services/farseerFactory.js +274 -208
  36. package/dist/services/farseerService.js +488 -455
  37. package/dist/services/syncService.js +732 -657
  38. package/dist/utils/constants.js +20 -45
  39. package/dist/utils/helpers.js +366 -333
  40. package/dist/utils/logger.js +43 -74
  41. package/package.json +8 -1
  42. package/dist/commands/app.js.map +0 -7
  43. package/dist/commands/apps.js.map +0 -7
  44. package/dist/commands/checkout.js.map +0 -7
  45. package/dist/commands/config.js.map +0 -7
  46. package/dist/commands/diff.js.map +0 -7
  47. package/dist/commands/dimensions.js.map +0 -7
  48. package/dist/commands/files.js.map +0 -7
  49. package/dist/commands/install.js.map +0 -7
  50. package/dist/commands/list.js.map +0 -7
  51. package/dist/commands/login.js.map +0 -7
  52. package/dist/commands/logout.js.map +0 -7
  53. package/dist/commands/mcp-server.js.map +0 -7
  54. package/dist/commands/model.js.map +0 -7
  55. package/dist/commands/pull.js.map +0 -7
  56. package/dist/commands/push.js.map +0 -7
  57. package/dist/commands/run.js.map +0 -7
  58. package/dist/commands/status.js.map +0 -7
  59. package/dist/commands/variables.js.map +0 -7
  60. package/dist/commands/whoami.js.map +0 -7
  61. package/dist/index.js.map +0 -7
  62. package/dist/mcp/index.js.map +0 -7
  63. package/dist/mcp/prompts/workflows.js.map +0 -7
  64. package/dist/mcp/resources/documentation.js.map +0 -7
  65. package/dist/mcp/server.js.map +0 -7
  66. package/dist/mcp/tools/appTools.js.map +0 -7
  67. package/dist/mcp/tools/authTools.js.map +0 -7
  68. package/dist/mcp/tools/dataTools.js.map +0 -7
  69. package/dist/mcp/tools/modelTools.js.map +0 -7
  70. package/dist/mcp/tools/runTools.js.map +0 -7
  71. package/dist/mcp/tools/syncTools.js.map +0 -7
  72. package/dist/mcp/utils/helpers.js.map +0 -7
  73. package/dist/services/appSyncService.js.map +0 -7
  74. package/dist/services/configService.js.map +0 -7
  75. package/dist/services/farseerApi.js.map +0 -7
  76. package/dist/services/farseerFactory.js.map +0 -7
  77. package/dist/services/farseerService.js.map +0 -7
  78. package/dist/services/syncService.js.map +0 -7
  79. package/dist/utils/constants.js.map +0 -7
  80. package/dist/utils/helpers.js.map +0 -7
  81. package/dist/utils/logger.js.map +0 -7
@@ -1,87 +1,107 @@
1
- var __create = Object.create;
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __getProtoOf = Object.getPrototypeOf;
6
- var __hasOwnProp = Object.prototype.hasOwnProperty;
7
- var __export = (target, all) => {
8
- for (var name in all)
9
- __defProp(target, name, { get: all[name], enumerable: true });
10
- };
11
- var __copyProps = (to, from, except, desc) => {
12
- if (from && typeof from === "object" || typeof from === "function") {
13
- for (let key of __getOwnPropNames(from))
14
- if (!__hasOwnProp.call(to, key) && key !== except)
15
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
- }
17
- return to;
18
- };
19
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
- // If the importer is in node compatibility mode or this is not an ESM
21
- // file that has been converted to a CommonJS file using a Babel-
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
- module.exports = __toCommonJS(runTools_exports);
33
- var import_zod = require("zod");
34
- var import_child_process = require("child_process");
35
- var fs = __toESM(require("fs"));
36
- var path = __toESM(require("path"));
37
- var import_farseerFactory = require("../../services/farseerFactory");
38
- var import_configService = require("../../services/configService");
39
- var import_farseerService = require("../../services/farseerService");
40
- var import_helpers = require("../../utils/helpers");
41
- var import_helpers2 = require("../utils/helpers");
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
- const credential = (0, import_configService.getCredential)(tenant);
44
- if (credential) {
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
- tenantId: credential.tenantId,
47
- apiKey: credential.apiKey,
48
- basePath: credential.basePath
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
- organisation: import_zod.z.string().optional().describe("Farseer organisation (subdomain). If omitted, uses checked-out org or saved mapping."),
77
- tenant: import_zod.z.string().optional().describe("Tenant ID. Uses checked-out tenant if omitted."),
78
- appName: import_zod.z.string().describe("Name of the app to run"),
79
- argumentOverrides: import_zod.z.record(import_zod.z.string(), import_zod.z.string()).optional().describe("Override argument values (Name: Value pairs)")
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
- server.tool(
83
- "farseer_run_app",
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
- runAppSchema,
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
- const resolved = (0, import_helpers2.resolveOrgAndTenant)(params);
109
- if (!resolved) {
110
- return (0, import_helpers2.tenantRequiredResponse)();
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 tenantDir = (0, import_helpers.getTenantDir)(tenant);
137
- const srcDir = (0, import_helpers.getTenantSrcDir)(tenant);
138
- const scriptPath = path.resolve(srcDir, mainScript.name);
139
- if (!fs.existsSync(scriptPath)) {
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
- const nodeModulesPath = path.join(tenantDir, "node_modules");
146
- if (!fs.existsSync(nodeModulesPath)) {
147
- return (0, import_helpers2.errorResponse)(
148
- `Dependencies not installed. Run "farseer install ${tenant}" in terminal first.`,
149
- "VALIDATION_ERROR"
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
- const appArgs = {};
153
- for (const arg of app.expectedArguments) {
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
- if (credentials.accessToken) {
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