extension-commands.ts•15.9 kB
// Extension Commands - 扩展命令
// Element Commands - 元素操作命令
export const ElementCommands = {
// Element.GetText - 获取元素文本
getText: {
name: 'mqscript_element_gettext',
description: 'Get text from UI element',
inputSchema: {
type: 'object' as const,
properties: {
elementId: {
type: 'string',
description: 'Element ID or selector'
},
resultVariable: {
type: 'string',
description: 'Variable name to store result',
default: 'elementText'
}
},
required: ['elementId']
},
handler: async (args: { elementId: string; resultVariable?: string }) => {
const { elementId, resultVariable = 'elementText' } = args;
const script = `${resultVariable} = Element.GetText("${elementId}")`;
return {
content: [
{
type: 'text',
text: `Generated MQScript get element text command:\n\`\`\`\n${script}\n\`\`\`\n\nThis gets text from element "${elementId}" and stores it in variable "${resultVariable}".`
}
]
};
}
},
// Element.Click - 点击元素
click: {
name: 'mqscript_element_click',
description: 'Click on UI element',
inputSchema: {
type: 'object' as const,
properties: {
elementId: {
type: 'string',
description: 'Element ID or selector'
}
},
required: ['elementId']
},
handler: async (args: { elementId: string }) => {
const { elementId } = args;
const script = `Element.Click("${elementId}")`;
return {
content: [
{
type: 'text',
text: `Generated MQScript element click command:\n\`\`\`\n${script}\n\`\`\`\n\nThis clicks on element "${elementId}".`
}
]
};
}
},
// Element.SetText - 设置元素文本
setText: {
name: 'mqscript_element_settext',
description: 'Set text to UI element',
inputSchema: {
type: 'object' as const,
properties: {
elementId: {
type: 'string',
description: 'Element ID or selector'
},
text: {
type: 'string',
description: 'Text to set'
}
},
required: ['elementId', 'text']
},
handler: async (args: { elementId: string; text: string }) => {
const { elementId, text } = args;
const script = `Element.SetText("${elementId}", "${text}")`;
return {
content: [
{
type: 'text',
text: `Generated MQScript set element text command:\n\`\`\`\n${script}\n\`\`\`\n\nThis sets text of element "${elementId}" to "${text}".`
}
]
};
}
},
// Element.Exists - 检查元素是否存在
exists: {
name: 'mqscript_element_exists',
description: 'Check if UI element exists',
inputSchema: {
type: 'object' as const,
properties: {
elementId: {
type: 'string',
description: 'Element ID or selector'
},
resultVariable: {
type: 'string',
description: 'Variable name to store result',
default: 'elementExists'
}
},
required: ['elementId']
},
handler: async (args: { elementId: string; resultVariable?: string }) => {
const { elementId, resultVariable = 'elementExists' } = args;
const script = `${resultVariable} = Element.Exists("${elementId}")`;
return {
content: [
{
type: 'text',
text: `Generated MQScript element exists command:\n\`\`\`\n${script}\n\`\`\`\n\nThis checks if element "${elementId}" exists and stores result in "${resultVariable}".`
}
]
};
}
}
};
// Device Commands - 设备操作命令
export const DeviceCommands = {
// Device.GetInfo - 获取设备信息
getInfo: {
name: 'mqscript_device_getinfo',
description: 'Get device information',
inputSchema: {
type: 'object' as const,
properties: {
infoType: {
type: 'string',
description: 'Type of device info to get',
enum: ['model', 'brand', 'version', 'screenWidth', 'screenHeight', 'dpi'],
default: 'model'
},
resultVariable: {
type: 'string',
description: 'Variable name to store result',
default: 'deviceInfo'
}
},
required: []
},
handler: async (args: { infoType?: string; resultVariable?: string }) => {
const { infoType = 'model', resultVariable = 'deviceInfo' } = args;
const script = `${resultVariable} = Device.GetInfo("${infoType}")`;
return {
content: [
{
type: 'text',
text: `Generated MQScript get device info command:\n\`\`\`\n${script}\n\`\`\`\n\nThis gets device ${infoType} and stores it in variable "${resultVariable}".`
}
]
};
}
},
// Device.Vibrate - 设备震动
vibrate: {
name: 'mqscript_device_vibrate',
description: 'Make device vibrate',
inputSchema: {
type: 'object' as const,
properties: {
duration: {
type: 'number',
description: 'Vibration duration in milliseconds',
default: 200
}
},
required: []
},
handler: async (args: { duration?: number }) => {
const { duration = 200 } = args;
const script = `Device.Vibrate(${duration})`;
return {
content: [
{
type: 'text',
text: `Generated MQScript device vibrate command:\n\`\`\`\n${script}\n\`\`\`\n\nThis makes the device vibrate for ${duration} milliseconds.`
}
]
};
}
},
// Device.SetBrightness - 设置屏幕亮度
setBrightness: {
name: 'mqscript_device_setbrightness',
description: 'Set screen brightness',
inputSchema: {
type: 'object' as const,
properties: {
brightness: {
type: 'number',
description: 'Brightness level (0-255)',
minimum: 0,
maximum: 255
}
},
required: ['brightness']
},
handler: async (args: { brightness: number }) => {
const { brightness } = args;
const script = `Device.SetBrightness(${brightness})`;
return {
content: [
{
type: 'text',
text: `Generated MQScript set brightness command:\n\`\`\`\n${script}\n\`\`\`\n\nThis sets screen brightness to ${brightness}.`
}
]
};
}
},
// Device.SetVolume - 设置音量
setVolume: {
name: 'mqscript_device_setvolume',
description: 'Set device volume',
inputSchema: {
type: 'object' as const,
properties: {
volume: {
type: 'number',
description: 'Volume level (0-15)',
minimum: 0,
maximum: 15
},
streamType: {
type: 'string',
description: 'Volume stream type',
enum: ['music', 'ring', 'alarm', 'notification'],
default: 'music'
}
},
required: ['volume']
},
handler: async (args: { volume: number; streamType?: string }) => {
const { volume, streamType = 'music' } = args;
const script = `Device.SetVolume(${volume}, "${streamType}")`;
return {
content: [
{
type: 'text',
text: `Generated MQScript set volume command:\n\`\`\`\n${script}\n\`\`\`\n\nThis sets ${streamType} volume to ${volume}.`
}
]
};
}
}
};
// Phone Commands - 电话操作命令
export const PhoneCommands = {
// Phone.Call - 拨打电话
call: {
name: 'mqscript_phone_call',
description: 'Make a phone call',
inputSchema: {
type: 'object' as const,
properties: {
phoneNumber: {
type: 'string',
description: 'Phone number to call'
}
},
required: ['phoneNumber']
},
handler: async (args: { phoneNumber: string }) => {
const { phoneNumber } = args;
const script = `Phone.Call("${phoneNumber}")`;
return {
content: [
{
type: 'text',
text: `Generated MQScript phone call command:\n\`\`\`\n${script}\n\`\`\`\n\nThis makes a call to ${phoneNumber}.`
}
]
};
}
},
// Phone.SendSMS - 发送短信
sendSMS: {
name: 'mqscript_phone_sendsms',
description: 'Send SMS message',
inputSchema: {
type: 'object' as const,
properties: {
phoneNumber: {
type: 'string',
description: 'Phone number to send SMS to'
},
message: {
type: 'string',
description: 'SMS message content'
}
},
required: ['phoneNumber', 'message']
},
handler: async (args: { phoneNumber: string; message: string }) => {
const { phoneNumber, message } = args;
const script = `Phone.SendSMS("${phoneNumber}", "${message}")`;
return {
content: [
{
type: 'text',
text: `Generated MQScript send SMS command:\n\`\`\`\n${script}\n\`\`\`\n\nThis sends SMS "${message}" to ${phoneNumber}.`
}
]
};
}
},
// Phone.GetCallState - 获取通话状态
getCallState: {
name: 'mqscript_phone_getcallstate',
description: 'Get current call state',
inputSchema: {
type: 'object' as const,
properties: {
resultVariable: {
type: 'string',
description: 'Variable name to store call state',
default: 'callState'
}
},
required: []
},
handler: async (args: { resultVariable?: string }) => {
const { resultVariable = 'callState' } = args;
const script = `${resultVariable} = Phone.GetCallState()`;
return {
content: [
{
type: 'text',
text: `Generated MQScript get call state command:\n\`\`\`\n${script}\n\`\`\`\n\nThis gets current call state and stores it in "${resultVariable}".`
}
]
};
}
}
};
// System Commands - 系统操作命令
export const SysCommands = {
// Sys.Exit - 退出脚本
exit: {
name: 'mqscript_sys_exit',
description: 'Exit the script',
inputSchema: {
type: 'object' as const,
properties: {
exitCode: {
type: 'number',
description: 'Exit code',
default: 0
}
},
required: []
},
handler: async (args: { exitCode?: number }) => {
const { exitCode = 0 } = args;
const script = `Sys.Exit(${exitCode})`;
return {
content: [
{
type: 'text',
text: `Generated MQScript exit command:\n\`\`\`\n${script}\n\`\`\`\n\nThis exits the script with code ${exitCode}.`
}
]
};
}
},
// Sys.GetTime - 获取系统时间
getTime: {
name: 'mqscript_sys_gettime',
description: 'Get current system time',
inputSchema: {
type: 'object' as const,
properties: {
format: {
type: 'string',
description: 'Time format string',
default: 'yyyy-MM-dd HH:mm:ss'
},
resultVariable: {
type: 'string',
description: 'Variable name to store time',
default: 'currentTime'
}
},
required: []
},
handler: async (args: { format?: string; resultVariable?: string }) => {
const { format = 'yyyy-MM-dd HH:mm:ss', resultVariable = 'currentTime' } = args;
const script = `${resultVariable} = Sys.GetTime("${format}")`;
return {
content: [
{
type: 'text',
text: `Generated MQScript get time command:\n\`\`\`\n${script}\n\`\`\`\n\nThis gets current time in format "${format}" and stores it in "${resultVariable}".`
}
]
};
}
},
// Sys.Shell - 执行系统命令
shell: {
name: 'mqscript_sys_shell',
description: 'Execute system shell command',
inputSchema: {
type: 'object' as const,
properties: {
command: {
type: 'string',
description: 'Shell command to execute'
},
waitForCompletion: {
type: 'boolean',
description: 'Wait for command completion',
default: true
},
resultVariable: {
type: 'string',
description: 'Variable name to store result',
default: 'shellResult'
}
},
required: ['command']
},
handler: async (args: { command: string; waitForCompletion?: boolean; resultVariable?: string }) => {
const { command, waitForCompletion = true, resultVariable = 'shellResult' } = args;
const script = `${resultVariable} = Sys.Shell("${command}", ${waitForCompletion})`;
return {
content: [
{
type: 'text',
text: `Generated MQScript shell command:\n\`\`\`\n${script}\n\`\`\`\n\nThis executes shell command "${command}" with wait=${waitForCompletion}.`
}
]
};
}
},
// Sys.GetEnv - 获取环境变量
getEnv: {
name: 'mqscript_sys_getenv',
description: 'Get environment variable',
inputSchema: {
type: 'object' as const,
properties: {
varName: {
type: 'string',
description: 'Environment variable name'
},
resultVariable: {
type: 'string',
description: 'Variable name to store result',
default: 'envValue'
}
},
required: ['varName']
},
handler: async (args: { varName: string; resultVariable?: string }) => {
const { varName, resultVariable = 'envValue' } = args;
const script = `${resultVariable} = Sys.GetEnv("${varName}")`;
return {
content: [
{
type: 'text',
text: `Generated MQScript get environment variable command:\n\`\`\`\n${script}\n\`\`\`\n\nThis gets environment variable "${varName}" and stores it in "${resultVariable}".`
}
]
};
}
},
// Sys.SetEnv - 设置环境变量
setEnv: {
name: 'mqscript_sys_setenv',
description: 'Set environment variable',
inputSchema: {
type: 'object' as const,
properties: {
varName: {
type: 'string',
description: 'Environment variable name'
},
value: {
type: 'string',
description: 'Environment variable value'
}
},
required: ['varName', 'value']
},
handler: async (args: { varName: string; value: string }) => {
const { varName, value } = args;
const script = `Sys.SetEnv("${varName}", "${value}")`;
return {
content: [
{
type: 'text',
text: `Generated MQScript set environment variable command:\n\`\`\`\n${script}\n\`\`\`\n\nThis sets environment variable "${varName}" to "${value}".`
}
]
};
}
},
// Sys.Sleep - 系统休眠
sleep: {
name: 'mqscript_sys_sleep',
description: 'Sleep for specified duration',
inputSchema: {
type: 'object' as const,
properties: {
milliseconds: {
type: 'number',
description: 'Sleep duration in milliseconds'
}
},
required: ['milliseconds']
},
handler: async (args: { milliseconds: number }) => {
const { milliseconds } = args;
const script = `Sys.Sleep(${milliseconds})`;
return {
content: [
{
type: 'text',
text: `Generated MQScript sleep command:\n\`\`\`\n${script}\n\`\`\`\n\nThis sleeps for ${milliseconds} milliseconds.`
}
]
};
}
}
};