UNPKG

@minecraft/creator-tools

Version:

Minecraft Creator Tools command line and libraries.

85 lines (84 loc) 3.42 kB
"use strict"; // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. Object.defineProperty(exports, "__esModule", { value: true }); exports.ToolCommandBase = exports.ToolCommandExitCode = exports.ToolCommandScope = void 0; /** * Scopes where a ToolCommand can be invoked. * By default, commands are available in all scopes. */ var ToolCommandScope; (function (ToolCommandScope) { /** Available in web/Electron UI (SearchCommandEditor, Home page) */ ToolCommandScope["ui"] = "ui"; /** Available as MCP tool */ ToolCommandScope["mcp"] = "mcp"; /** Available in serve mode interactive terminal */ ToolCommandScope["serveTerminal"] = "serveTerminal"; /** Available in server management HTTP API */ ToolCommandScope["serverApi"] = "serverApi"; /** Available as CLI command (via adapter) */ ToolCommandScope["cli"] = "cli"; })(ToolCommandScope || (exports.ToolCommandScope = ToolCommandScope = {})); /** * Standard exit codes for ToolCommands. * These align with Unix conventions and enable intelligent error handling in CI/CD scripts. */ var ToolCommandExitCode; (function (ToolCommandExitCode) { ToolCommandExitCode[ToolCommandExitCode["Success"] = 0] = "Success"; ToolCommandExitCode[ToolCommandExitCode["GenericError"] = 1] = "GenericError"; ToolCommandExitCode[ToolCommandExitCode["PortConflict"] = 2] = "PortConflict"; ToolCommandExitCode[ToolCommandExitCode["EulaNotAccepted"] = 3] = "EulaNotAccepted"; ToolCommandExitCode[ToolCommandExitCode["NetworkError"] = 4] = "NetworkError"; ToolCommandExitCode[ToolCommandExitCode["CrashOnStartup"] = 5] = "CrashOnStartup"; ToolCommandExitCode[ToolCommandExitCode["Timeout"] = 6] = "Timeout"; ToolCommandExitCode[ToolCommandExitCode["InvalidArguments"] = 7] = "InvalidArguments"; ToolCommandExitCode[ToolCommandExitCode["PermissionDenied"] = 8] = "PermissionDenied"; })(ToolCommandExitCode || (exports.ToolCommandExitCode = ToolCommandExitCode = {})); /** * Base class for ToolCommands providing common functionality. */ class ToolCommandBase { /** * Default completion implementation using argument autocompleteProviders. */ async getCompletions(context, args, partialArg, argIndex) { const argDef = this.metadata.arguments?.[argIndex]; if (!argDef?.autocompleteProvider) { return []; } return argDef.autocompleteProvider(partialArg, context); } /** * Helper to create a success result. */ success(message, data) { return { success: true, message, data }; } /** * Helper to create an error result. */ error(code, message, details) { return { success: false, error: { code, message, details }, }; } /** * Helper to validate required arguments. */ validateRequiredArgs(args) { const requiredArgs = this.metadata.arguments?.filter((a) => a.required) ?? []; for (let i = 0; i < requiredArgs.length; i++) { if (!args[i] || args[i].trim() === "") { return this.error("MISSING_ARGUMENT", `Missing required argument: ${requiredArgs[i].name}`, { argumentName: requiredArgs[i].name, argumentIndex: i, }); } } return undefined; } } exports.ToolCommandBase = ToolCommandBase;