plugin-commands.ts•17 kB
// Plugin Commands - 插件命令
// CJson Commands - JSON操作命令
export const CJsonCommands = {
// CJson.Parse - 解析JSON字符串
parse: {
name: 'mqscript_cjson_parse',
description: 'Parse JSON string to object',
inputSchema: {
type: 'object' as const,
properties: {
jsonString: {
type: 'string',
description: 'JSON string to parse'
},
resultVariable: {
type: 'string',
description: 'Variable name to store parsed object',
default: 'jsonObj'
}
},
required: ['jsonString']
},
handler: async (args: { jsonString: string; resultVariable?: string }) => {
const { jsonString, resultVariable = 'jsonObj' } = args;
const script = `${resultVariable} = CJson.Parse("${jsonString}")`;
return {
content: [
{
type: 'text',
text: `Generated MQScript CJson parse command:\n\`\`\`\n${script}\n\`\`\`\n\nThis parses JSON string and stores result in "${resultVariable}".`
}
]
};
}
},
// CJson.Stringify - 对象转JSON字符串
stringify: {
name: 'mqscript_cjson_stringify',
description: 'Convert object to JSON string',
inputSchema: {
type: 'object' as const,
properties: {
objectVariable: {
type: 'string',
description: 'Object variable name to convert'
},
resultVariable: {
type: 'string',
description: 'Variable name to store JSON string',
default: 'jsonString'
}
},
required: ['objectVariable']
},
handler: async (args: { objectVariable: string; resultVariable?: string }) => {
const { objectVariable, resultVariable = 'jsonString' } = args;
const script = `${resultVariable} = CJson.Stringify(${objectVariable})`;
return {
content: [
{
type: 'text',
text: `Generated MQScript CJson stringify command:\n\`\`\`\n${script}\n\`\`\`\n\nThis converts object "${objectVariable}" to JSON string in "${resultVariable}".`
}
]
};
}
},
// CJson.Get - 获取JSON对象属性值
get: {
name: 'mqscript_cjson_get',
description: 'Get value from JSON object',
inputSchema: {
type: 'object' as const,
properties: {
objectVariable: {
type: 'string',
description: 'JSON object variable name'
},
path: {
type: 'string',
description: 'Property path (e.g., "data.items[0].name")'
},
resultVariable: {
type: 'string',
description: 'Variable name to store result',
default: 'value'
}
},
required: ['objectVariable', 'path']
},
handler: async (args: { objectVariable: string; path: string; resultVariable?: string }) => {
const { objectVariable, path, resultVariable = 'value' } = args;
const script = `${resultVariable} = CJson.Get(${objectVariable}, "${path}")`;
return {
content: [
{
type: 'text',
text: `Generated MQScript CJson get command:\n\`\`\`\n${script}\n\`\`\`\n\nThis gets value at path "${path}" from object "${objectVariable}".`
}
]
};
}
},
// CJson.Set - 设置JSON对象属性值
set: {
name: 'mqscript_cjson_set',
description: 'Set value in JSON object',
inputSchema: {
type: 'object' as const,
properties: {
objectVariable: {
type: 'string',
description: 'JSON object variable name'
},
path: {
type: 'string',
description: 'Property path (e.g., "data.items[0].name")'
},
value: {
type: 'string',
description: 'Value to set'
}
},
required: ['objectVariable', 'path', 'value']
},
handler: async (args: { objectVariable: string; path: string; value: string }) => {
const { objectVariable, path, value } = args;
const script = `CJson.Set(${objectVariable}, "${path}", "${value}")`;
return {
content: [
{
type: 'text',
text: `Generated MQScript CJson set command:\n\`\`\`\n${script}\n\`\`\`\n\nThis sets value "${value}" at path "${path}" in object "${objectVariable}".`
}
]
};
}
}
};
// DateTime Commands - 日期时间操作命令
export const DateTimeCommands = {
// DateTime.Now - 获取当前时间
now: {
name: 'mqscript_datetime_now',
description: 'Get current date and time',
inputSchema: {
type: 'object' as const,
properties: {
format: {
type: 'string',
description: 'Date format string',
default: 'yyyy-MM-dd HH:mm:ss'
},
resultVariable: {
type: 'string',
description: 'Variable name to store result',
default: 'now'
}
},
required: []
},
handler: async (args: { format?: string; resultVariable?: string }) => {
const { format = 'yyyy-MM-dd HH:mm:ss', resultVariable = 'now' } = args;
const script = `${resultVariable} = DateTime.Now("${format}")`;
return {
content: [
{
type: 'text',
text: `Generated MQScript DateTime now command:\n\`\`\`\n${script}\n\`\`\`\n\nThis gets current time in format "${format}" and stores it in "${resultVariable}".`
}
]
};
}
},
// DateTime.Format - 格式化日期时间
format: {
name: 'mqscript_datetime_format',
description: 'Format date time with specified format',
inputSchema: {
type: 'object' as const,
properties: {
dateTimeVariable: {
type: 'string',
description: 'DateTime variable name'
},
format: {
type: 'string',
description: 'Target format string',
default: 'yyyy-MM-dd'
},
resultVariable: {
type: 'string',
description: 'Variable name to store result',
default: 'formattedDate'
}
},
required: ['dateTimeVariable']
},
handler: async (args: { dateTimeVariable: string; format?: string; resultVariable?: string }) => {
const { dateTimeVariable, format = 'yyyy-MM-dd', resultVariable = 'formattedDate' } = args;
const script = `${resultVariable} = DateTime.Format(${dateTimeVariable}, "${format}")`;
return {
content: [
{
type: 'text',
text: `Generated MQScript DateTime format command:\n\`\`\`\n${script}\n\`\`\`\n\nThis formats "${dateTimeVariable}" to format "${format}".`
}
]
};
}
},
// DateTime.AddDays - 添加天数
addDays: {
name: 'mqscript_datetime_adddays',
description: 'Add days to date time',
inputSchema: {
type: 'object' as const,
properties: {
dateTimeVariable: {
type: 'string',
description: 'DateTime variable name'
},
days: {
type: 'number',
description: 'Number of days to add'
},
resultVariable: {
type: 'string',
description: 'Variable name to store result',
default: 'newDate'
}
},
required: ['dateTimeVariable', 'days']
},
handler: async (args: { dateTimeVariable: string; days: number; resultVariable?: string }) => {
const { dateTimeVariable, days, resultVariable = 'newDate' } = args;
const script = `${resultVariable} = DateTime.AddDays(${dateTimeVariable}, ${days})`;
return {
content: [
{
type: 'text',
text: `Generated MQScript DateTime add days command:\n\`\`\`\n${script}\n\`\`\`\n\nThis adds ${days} days to "${dateTimeVariable}".`
}
]
};
}
},
// DateTime.Compare - 比较两个日期时间
compare: {
name: 'mqscript_datetime_compare',
description: 'Compare two date times',
inputSchema: {
type: 'object' as const,
properties: {
dateTime1: {
type: 'string',
description: 'First DateTime variable name'
},
dateTime2: {
type: 'string',
description: 'Second DateTime variable name'
},
resultVariable: {
type: 'string',
description: 'Variable name to store comparison result',
default: 'compareResult'
}
},
required: ['dateTime1', 'dateTime2']
},
handler: async (args: { dateTime1: string; dateTime2: string; resultVariable?: string }) => {
const { dateTime1, dateTime2, resultVariable = 'compareResult' } = args;
const script = `${resultVariable} = DateTime.Compare(${dateTime1}, ${dateTime2})`;
return {
content: [
{
type: 'text',
text: `Generated MQScript DateTime compare command:\n\`\`\`\n${script}\n\`\`\`\n\nThis compares "${dateTime1}" with "${dateTime2}" and stores result in "${resultVariable}".`
}
]
};
}
}
};
// File Commands - 文件操作命令
export const FileCommands = {
// File.Read - 读取文件
read: {
name: 'mqscript_file_read',
description: 'Read file content',
inputSchema: {
type: 'object' as const,
properties: {
filePath: {
type: 'string',
description: 'File path to read'
},
encoding: {
type: 'string',
description: 'File encoding',
enum: ['UTF-8', 'GBK', 'ASCII'],
default: 'UTF-8'
},
resultVariable: {
type: 'string',
description: 'Variable name to store file content',
default: 'fileContent'
}
},
required: ['filePath']
},
handler: async (args: { filePath: string; encoding?: string; resultVariable?: string }) => {
const { filePath, encoding = 'UTF-8', resultVariable = 'fileContent' } = args;
const script = `${resultVariable} = File.Read("${filePath}", "${encoding}")`;
return {
content: [
{
type: 'text',
text: `Generated MQScript file read command:\n\`\`\`\n${script}\n\`\`\`\n\nThis reads file "${filePath}" with encoding "${encoding}" and stores content in "${resultVariable}".`
}
]
};
}
},
// File.Write - 写入文件
write: {
name: 'mqscript_file_write',
description: 'Write content to file',
inputSchema: {
type: 'object' as const,
properties: {
filePath: {
type: 'string',
description: 'File path to write'
},
content: {
type: 'string',
description: 'Content to write'
},
encoding: {
type: 'string',
description: 'File encoding',
enum: ['UTF-8', 'GBK', 'ASCII'],
default: 'UTF-8'
},
append: {
type: 'boolean',
description: 'Append to file instead of overwrite',
default: false
}
},
required: ['filePath', 'content']
},
handler: async (args: { filePath: string; content: string; encoding?: string; append?: boolean }) => {
const { filePath, content, encoding = 'UTF-8', append = false } = args;
const script = `File.Write("${filePath}", "${content}", "${encoding}", ${append})`;
return {
content: [
{
type: 'text',
text: `Generated MQScript file write command:\n\`\`\`\n${script}\n\`\`\`\n\nThis writes content to file "${filePath}" with encoding "${encoding}", append=${append}.`
}
]
};
}
},
// File.Exists - 检查文件是否存在
exists: {
name: 'mqscript_file_exists',
description: 'Check if file exists',
inputSchema: {
type: 'object' as const,
properties: {
filePath: {
type: 'string',
description: 'File path to check'
},
resultVariable: {
type: 'string',
description: 'Variable name to store result',
default: 'fileExists'
}
},
required: ['filePath']
},
handler: async (args: { filePath: string; resultVariable?: string }) => {
const { filePath, resultVariable = 'fileExists' } = args;
const script = `${resultVariable} = File.Exists("${filePath}")`;
return {
content: [
{
type: 'text',
text: `Generated MQScript file exists command:\n\`\`\`\n${script}\n\`\`\`\n\nThis checks if file "${filePath}" exists and stores result in "${resultVariable}".`
}
]
};
}
},
// File.Delete - 删除文件
delete: {
name: 'mqscript_file_delete',
description: 'Delete file',
inputSchema: {
type: 'object' as const,
properties: {
filePath: {
type: 'string',
description: 'File path to delete'
}
},
required: ['filePath']
},
handler: async (args: { filePath: string }) => {
const { filePath } = args;
const script = `File.Delete("${filePath}")`;
return {
content: [
{
type: 'text',
text: `Generated MQScript file delete command:\n\`\`\`\n${script}\n\`\`\`\n\nThis deletes file "${filePath}".`
}
]
};
}
},
// File.Copy - 复制文件
copy: {
name: 'mqscript_file_copy',
description: 'Copy file',
inputSchema: {
type: 'object' as const,
properties: {
sourcePath: {
type: 'string',
description: 'Source file path'
},
destinationPath: {
type: 'string',
description: 'Destination file path'
},
overwrite: {
type: 'boolean',
description: 'Overwrite destination if exists',
default: false
}
},
required: ['sourcePath', 'destinationPath']
},
handler: async (args: { sourcePath: string; destinationPath: string; overwrite?: boolean }) => {
const { sourcePath, destinationPath, overwrite = false } = args;
const script = `File.Copy("${sourcePath}", "${destinationPath}", ${overwrite})`;
return {
content: [
{
type: 'text',
text: `Generated MQScript file copy command:\n\`\`\`\n${script}\n\`\`\`\n\nThis copies file from "${sourcePath}" to "${destinationPath}", overwrite=${overwrite}.`
}
]
};
}
}
};
// TURING Commands - 图灵机器人命令
export const TuringCommands = {
// TURING.Chat - 与图灵机器人对话
chat: {
name: 'mqscript_turing_chat',
description: 'Chat with TURING robot',
inputSchema: {
type: 'object' as const,
properties: {
apiKey: {
type: 'string',
description: 'TURING API key'
},
userId: {
type: 'string',
description: 'User ID for conversation context'
},
message: {
type: 'string',
description: 'Message to send'
},
resultVariable: {
type: 'string',
description: 'Variable name to store response',
default: 'turingResponse'
}
},
required: ['apiKey', 'userId', 'message']
},
handler: async (args: { apiKey: string; userId: string; message: string; resultVariable?: string }) => {
const { apiKey, userId, message, resultVariable = 'turingResponse' } = args;
const script = `${resultVariable} = TURING.Chat("${apiKey}", "${userId}", "${message}")`;
return {
content: [
{
type: 'text',
text: `Generated MQScript TURING chat command:\n\`\`\`\n${script}\n\`\`\`\n\nThis sends message "${message}" to TURING robot and stores response in "${resultVariable}".`
}
]
};
}
},
// TURING.SetConfig - 设置图灵机器人配置
setConfig: {
name: 'mqscript_turing_setconfig',
description: 'Set TURING robot configuration',
inputSchema: {
type: 'object' as const,
properties: {
apiKey: {
type: 'string',
description: 'TURING API key'
},
secretKey: {
type: 'string',
description: 'TURING secret key'
},
userId: {
type: 'string',
description: 'Default user ID'
}
},
required: ['apiKey']
},
handler: async (args: { apiKey: string; secretKey?: string; userId?: string }) => {
const { apiKey, secretKey = '', userId = '' } = args;
const script = `TURING.SetConfig("${apiKey}", "${secretKey}", "${userId}")`;
return {
content: [
{
type: 'text',
text: `Generated MQScript TURING set config command:\n\`\`\`\n${script}\n\`\`\`\n\nThis sets TURING robot configuration with API key.`
}
]
};
}
}
};