|
1
|
"use strict"; |
|
2
|
var __defProp = Object.defineProperty; |
|
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor; |
|
4
|
var __getOwnPropNames = Object.getOwnPropertyNames; |
|
5
|
var __hasOwnProp = Object.prototype.hasOwnProperty; |
|
6
|
var __export = (target, all) => { |
|
7
|
for (var name in all) |
|
8
|
__defProp(target, name, { get: all[name], enumerable: true }); |
|
9
|
}; |
|
10
|
var __copyProps = (to, from, except, desc) => { |
|
11
|
if (from && typeof from === "object" || typeof from === "function") { |
|
12
|
for (let key of __getOwnPropNames(from)) |
|
13
|
if (!__hasOwnProp.call(to, key) && key !== except) |
|
14
|
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); |
|
15
|
} |
|
16
|
return to; |
|
17
|
}; |
|
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); |
|
19
|
var command_exports = {}; |
|
20
|
__export(command_exports, { |
|
21
|
declareCommand: () => declareCommand, |
|
22
|
parseCommand: () => parseCommand |
|
23
|
}); |
|
24
|
module.exports = __toCommonJS(command_exports); |
|
25
|
function declareCommand(command) { |
|
26
|
return command; |
|
27
|
} |
|
28
|
function parseCommand(command, args) { |
|
29
|
const shape = command.args ? command.args.shape : {}; |
|
30
|
const argv = args["_"]; |
|
31
|
const options = command.options?.parse({ ...args, _: void 0 }) ?? {}; |
|
32
|
const argsObject = {}; |
|
33
|
let i = 0; |
|
34
|
for (const name of Object.keys(shape)) |
|
35
|
argsObject[name] = argv[++i]; |
|
36
|
let parsedArgsObject = {}; |
|
37
|
try { |
|
38
|
parsedArgsObject = command.args?.parse(argsObject) ?? {}; |
|
39
|
} catch (e) { |
|
40
|
throw new Error(formatZodError(e)); |
|
41
|
} |
|
42
|
const toolName = typeof command.toolName === "function" ? command.toolName(parsedArgsObject, options) : command.toolName; |
|
43
|
const toolParams = command.toolParams(parsedArgsObject, options); |
|
44
|
return { toolName, toolParams }; |
|
45
|
} |
|
46
|
function formatZodError(error) { |
|
47
|
const issue = error.issues[0]; |
|
48
|
if (issue.code === "invalid_type") |
|
49
|
return `${issue.message} in <${issue.path.join(".")}>`; |
|
50
|
return error.issues.map((i) => i.message).join("\n"); |
|
51
|
} |
|
52
|
// Annotate the CommonJS export names for ESM import in node: |
|
53
|
0 && (module.exports = { |
|
54
|
declareCommand, |
|
55
|
parseCommand |
|
56
|
}); |
|
57
|
|