genkit-cli
Version:
CLI for interacting with the Google Genkit AI framework
68 lines • 2.28 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.McpRuntimeManager = void 0;
exports.getCommonSchema = getCommonSchema;
exports.resolveProjectRoot = resolveProjectRoot;
const zod_1 = require("zod");
const manager_utils_1 = require("../utils/manager-utils");
function getCommonSchema(explicitProjectRoot, shape = {}) {
return !explicitProjectRoot
? shape
: {
projectRoot: zod_1.z
.string()
.describe('The path to the current project root (a.k.a workspace directory or project directory); type: string'),
...shape,
};
}
function resolveProjectRoot(explicitProjectRoot, opts, fallback) {
if (explicitProjectRoot && !opts?.projectRoot) {
return {
content: [
{ type: 'text', text: 'Project root is required for this tool.' },
],
isError: true,
};
}
return opts?.projectRoot ?? fallback;
}
class McpRuntimeManager {
manager;
currentProjectRoot;
async getManager(projectRoot) {
if (this.manager && this.currentProjectRoot === projectRoot) {
return this.manager;
}
if (this.manager) {
await this.manager.stop();
}
this.manager = await (0, manager_utils_1.startManager)({
projectRoot,
manageHealth: true,
});
this.currentProjectRoot = projectRoot;
return this.manager;
}
async getManagerWithDevProcess(params) {
const { projectRoot, command, args, timeout, explicitProjectRoot } = params;
if (this.manager) {
await this.manager.stop();
}
const devManager = await (0, manager_utils_1.startDevProcessManager)(projectRoot, command, args, {
nonInteractive: true,
healthCheck: timeout !== 0,
timeout,
cwd: explicitProjectRoot ? projectRoot : undefined,
});
this.manager = devManager.manager;
this.currentProjectRoot = projectRoot;
return this.manager;
}
async kill() {
if (this.manager) {
await this.manager.stop();
}
}
}
exports.McpRuntimeManager = McpRuntimeManager;
//# sourceMappingURL=utils.js.map