mirror of
https://github.com/fofolee/uTools-quickcommand.git
synced 2025-06-07 21:46:12 +08:00
优化以下编排中以下功能生成的描述:AI问答、模拟按键、系统命令、ubrowser、按键序列、函数返回
This commit is contained in:
parent
8ea4bad14d
commit
2e94f7897c
@ -29,7 +29,7 @@ import { defineComponent } from "vue";
|
|||||||
import ButtonGroup from "components/composer/common/ButtonGroup.vue";
|
import ButtonGroup from "components/composer/common/ButtonGroup.vue";
|
||||||
import { newVarInputVal } from "js/composer/varInputValManager";
|
import { newVarInputVal } from "js/composer/varInputValManager";
|
||||||
import VariableInput from "components/composer/common/VariableInput.vue";
|
import VariableInput from "components/composer/common/VariableInput.vue";
|
||||||
import { parseFunction, stringifyArgv } from "js/composer/formatString";
|
import { stringifyArgv } from "js/composer/formatString";
|
||||||
import AISelector from "components/ai/AISelector.vue";
|
import AISelector from "components/ai/AISelector.vue";
|
||||||
export default defineComponent({
|
export default defineComponent({
|
||||||
name: "AskAIEditor",
|
name: "AskAIEditor",
|
||||||
@ -69,30 +69,18 @@ export default defineComponent({
|
|||||||
computed: {
|
computed: {
|
||||||
argvs() {
|
argvs() {
|
||||||
return (
|
return (
|
||||||
this.modelValue.argvs || this.parseCodeToArgvs(this.modelValue.code)
|
this.modelValue.argvs || window.lodashM.cloneDeep(this.defaultArgvs)
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
parseCodeToArgvs(code) {
|
|
||||||
const argvs = window.lodashM.cloneDeep(this.defaultArgvs);
|
|
||||||
if (!code) return argvs;
|
|
||||||
try {
|
|
||||||
const variableFormatPaths = ["arg0.prompt"];
|
|
||||||
const params = parseFunction(code, { variableFormatPaths });
|
|
||||||
return params;
|
|
||||||
} catch (e) {
|
|
||||||
console.error("解析参数失败:", e);
|
|
||||||
}
|
|
||||||
return argvs;
|
|
||||||
},
|
|
||||||
generateCode(argvs = this.argvs) {
|
generateCode(argvs = this.argvs) {
|
||||||
return `${this.modelValue.value}(${stringifyArgv(
|
return `${this.modelValue.value}(${stringifyArgv(
|
||||||
argvs.content
|
argvs.content
|
||||||
)}, ${JSON.stringify(argvs.apiConfig)})`;
|
)}, ${JSON.stringify(argvs.apiConfig)})`;
|
||||||
},
|
},
|
||||||
getSummary(argvs) {
|
getSummary(argvs) {
|
||||||
return "问AI:" + argvs.content.prompt;
|
return "问AI:" + stringifyArgv(argvs.content.prompt);
|
||||||
},
|
},
|
||||||
updateArgvs(keyPath, newValue) {
|
updateArgvs(keyPath, newValue) {
|
||||||
const newArgvs = { ...this.argvs };
|
const newArgvs = { ...this.argvs };
|
||||||
|
@ -438,7 +438,7 @@ export default defineComponent({
|
|||||||
computed: {
|
computed: {
|
||||||
argvs() {
|
argvs() {
|
||||||
return (
|
return (
|
||||||
this.modelValue.argvs || this.parseCodeToArgvs(this.modelValue.code)
|
this.modelValue.argvs || window.lodashM.cloneDeep(this.defaultArgvs)
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
mainKeyDisplay() {
|
mainKeyDisplay() {
|
||||||
@ -622,44 +622,7 @@ export default defineComponent({
|
|||||||
...this.argvs,
|
...this.argvs,
|
||||||
...argv,
|
...argv,
|
||||||
};
|
};
|
||||||
this.$emit("update:modelValue", {
|
this.updateModelValue(newArgvs);
|
||||||
...this.modelValue,
|
|
||||||
argvs: newArgvs,
|
|
||||||
code: this.generateCode(newArgvs),
|
|
||||||
});
|
|
||||||
},
|
|
||||||
parseCodeToArgvs(code) {
|
|
||||||
const argvs = window.lodashM.cloneDeep(this.defaultArgvs);
|
|
||||||
if (!code) return argvs;
|
|
||||||
try {
|
|
||||||
const result = parseFunction(code);
|
|
||||||
if (!result || !result.argvs || !result.argvs[0]) return argvs;
|
|
||||||
|
|
||||||
const keys = result.argvs[0];
|
|
||||||
const options = result.argvs[1] || {};
|
|
||||||
|
|
||||||
if (keys.length > 0) {
|
|
||||||
argvs.mainKey = keys[0];
|
|
||||||
Object.keys(argvs.modifiers).forEach((key) => {
|
|
||||||
// 在非 Mac 系统上,将 meta 转换为 command
|
|
||||||
const modKey = !isMac && key === "command" ? "meta" : key;
|
|
||||||
argvs.modifiers[key] = keys.slice(1).includes(modKey);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// 解析选项对象
|
|
||||||
if (options) {
|
|
||||||
if (options.repeatCount) argvs.repeatCount = options.repeatCount;
|
|
||||||
if (options.repeatInterval)
|
|
||||||
argvs.repeatInterval = options.repeatInterval;
|
|
||||||
if (options.keyDelay) argvs.keyDelay = options.keyDelay;
|
|
||||||
}
|
|
||||||
|
|
||||||
return argvs;
|
|
||||||
} catch (e) {
|
|
||||||
console.error("Failed to parse key string:", e);
|
|
||||||
return argvs;
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
handleKeyInput(val) {
|
handleKeyInput(val) {
|
||||||
let newMainKey;
|
let newMainKey;
|
||||||
@ -703,16 +666,24 @@ export default defineComponent({
|
|||||||
.join(" + ");
|
.join(" + ");
|
||||||
return `${modifiers} + ${shortcut.mainKey}`;
|
return `${modifiers} + ${shortcut.mainKey}`;
|
||||||
},
|
},
|
||||||
|
getSummary(argvs) {
|
||||||
|
const modifiers = Object.entries(argvs.modifiers)
|
||||||
|
.filter(([_, active]) => active)
|
||||||
|
.map(([key]) => this.modifierLabels[key])
|
||||||
|
.join(" + ");
|
||||||
|
return modifiers ? `${modifiers} + ${argvs.mainKey}` : argvs.mainKey;
|
||||||
},
|
},
|
||||||
mounted() {
|
updateModelValue(argvs) {
|
||||||
const argvs = this.modelValue.argvs || this.defaultArgvs;
|
|
||||||
if (!this.modelValue.code) {
|
|
||||||
this.$emit("update:modelValue", {
|
this.$emit("update:modelValue", {
|
||||||
...this.modelValue,
|
...this.modelValue,
|
||||||
argvs,
|
argvs: argvs,
|
||||||
code: this.generateCode(argvs),
|
code: this.generateCode(argvs),
|
||||||
|
summary: this.getSummary(argvs),
|
||||||
});
|
});
|
||||||
}
|
},
|
||||||
|
},
|
||||||
|
mounted() {
|
||||||
|
this.updateModelValue(this.argvs);
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
@ -459,7 +459,7 @@ export default defineComponent({
|
|||||||
computed: {
|
computed: {
|
||||||
argvs() {
|
argvs() {
|
||||||
return (
|
return (
|
||||||
this.modelValue.argvs || this.parseCodeToArgvs(this.modelValue.code)
|
this.modelValue.argvs || window.lodashM.cloneDeep(this.defaultArgvs)
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -608,15 +608,26 @@ export default defineComponent({
|
|||||||
}
|
}
|
||||||
return `${this.modelValue.value}(${JSON.stringify(keySequence)})`;
|
return `${this.modelValue.value}(${JSON.stringify(keySequence)})`;
|
||||||
},
|
},
|
||||||
updateValue(newArgvs) {
|
updateValue(newArgvs = this.argvs) {
|
||||||
const updatedModelValue = {
|
const updatedModelValue = {
|
||||||
...this.modelValue,
|
...this.modelValue,
|
||||||
argvs: newArgvs || this.argvs,
|
argvs: newArgvs,
|
||||||
code: this.generateCode(newArgvs || this.argvs),
|
code: this.generateCode(newArgvs),
|
||||||
|
summary: this.getSummary(newArgvs),
|
||||||
};
|
};
|
||||||
|
|
||||||
this.$emit("update:modelValue", updatedModelValue);
|
this.$emit("update:modelValue", updatedModelValue);
|
||||||
},
|
},
|
||||||
|
getSingleSummary(item) {
|
||||||
|
const modifiers = Object.entries(item.modifiers)
|
||||||
|
.filter(([_, active]) => active)
|
||||||
|
.map(([key]) => this.modifierLabels[key])
|
||||||
|
.join(" + ");
|
||||||
|
return modifiers ? `${modifiers} + ${item.mainKey}` : item.mainKey;
|
||||||
|
},
|
||||||
|
getSummary(argvs) {
|
||||||
|
return argvs.sequence.map(this.getSingleSummary).join("; ");
|
||||||
|
},
|
||||||
appendSequence(newSequence) {
|
appendSequence(newSequence) {
|
||||||
const startId = Date.now();
|
const startId = Date.now();
|
||||||
this.argvs.sequence.push(
|
this.argvs.sequence.push(
|
||||||
@ -627,37 +638,6 @@ export default defineComponent({
|
|||||||
);
|
);
|
||||||
this.updateValue();
|
this.updateValue();
|
||||||
},
|
},
|
||||||
parseCodeToArgvs(code) {
|
|
||||||
const argvs = window.lodashM.cloneDeep(this.defaultArgvs);
|
|
||||||
if (!code) return argvs;
|
|
||||||
try {
|
|
||||||
const match = code.match(/\((.*)\)/s);
|
|
||||||
if (match) {
|
|
||||||
const args = eval(`[${match[1]}]`);
|
|
||||||
if (Array.isArray(args[0])) {
|
|
||||||
argvs.sequence = args[0].map((keys) => {
|
|
||||||
const mainKey = keys[0];
|
|
||||||
const modifiers = {
|
|
||||||
control: keys.includes("control"),
|
|
||||||
alt: keys.includes("alt"),
|
|
||||||
shift: keys.includes("shift"),
|
|
||||||
command:
|
|
||||||
!isMac && keys.includes("meta")
|
|
||||||
? true
|
|
||||||
: keys.includes("command"),
|
|
||||||
};
|
|
||||||
return { mainKey, modifiers, id: Date.now() + Math.random() };
|
|
||||||
});
|
|
||||||
if (args[1] && args[1].interval) {
|
|
||||||
argvs.interval = args[1].interval;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (e) {
|
|
||||||
console.error("Failed to parse existing code:", e);
|
|
||||||
}
|
|
||||||
return argvs;
|
|
||||||
},
|
|
||||||
toggleModifier(index, key) {
|
toggleModifier(index, key) {
|
||||||
// 创建新的 argvs 对象
|
// 创建新的 argvs 对象
|
||||||
const newArgvs = {
|
const newArgvs = {
|
||||||
@ -678,10 +658,7 @@ export default defineComponent({
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
mounted() {
|
mounted() {
|
||||||
const argvs = this.modelValue.argvs || this.defaultArgvs;
|
this.updateValue(this.argvs);
|
||||||
if (!this.modelValue.code) {
|
|
||||||
this.updateValue(argvs);
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
@ -132,7 +132,7 @@
|
|||||||
|
|
||||||
<script>
|
<script>
|
||||||
import { defineComponent } from "vue";
|
import { defineComponent } from "vue";
|
||||||
import { parseFunction, stringifyArgv } from "js/composer/formatString";
|
import { stringifyArgv } from "js/composer/formatString";
|
||||||
import { newVarInputVal } from "js/composer/varInputValManager";
|
import { newVarInputVal } from "js/composer/varInputValManager";
|
||||||
import VariableInput from "components/composer/common/VariableInput.vue";
|
import VariableInput from "components/composer/common/VariableInput.vue";
|
||||||
import NumberInput from "components/composer/common/NumberInput.vue";
|
import NumberInput from "components/composer/common/NumberInput.vue";
|
||||||
@ -182,9 +182,7 @@ export default defineComponent({
|
|||||||
argvs: {
|
argvs: {
|
||||||
get() {
|
get() {
|
||||||
return (
|
return (
|
||||||
this.modelValue.argvs ||
|
this.modelValue.argvs || window.lodashM.cloneDeep(this.defaultArgvs)
|
||||||
this.parseCodeToArgvs(this.modelValue.code) ||
|
|
||||||
this.defaultArgvs
|
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
set(value) {
|
set(value) {
|
||||||
@ -193,32 +191,6 @@ export default defineComponent({
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
parseCodeToArgvs(code) {
|
|
||||||
if (!code) return null;
|
|
||||||
|
|
||||||
// 定义需要使用variable格式的路径
|
|
||||||
const variableFormatPaths = [
|
|
||||||
"arg0", // 命令字符串
|
|
||||||
"arg1.cwd", // 工作目录
|
|
||||||
"arg1.env.**", // 环境变量
|
|
||||||
];
|
|
||||||
|
|
||||||
// 解析代码
|
|
||||||
const result = parseFunction(code, { variableFormatPaths });
|
|
||||||
if (!result) return this.defaultArgvs;
|
|
||||||
|
|
||||||
// 返回解析结果
|
|
||||||
const [command, options = {}] = result.argvs;
|
|
||||||
return {
|
|
||||||
command: command || this.defaultArgvs.command,
|
|
||||||
options: {
|
|
||||||
...this.defaultArgvs.options,
|
|
||||||
...options,
|
|
||||||
cwd: options.cwd || this.defaultArgvs.options.cwd,
|
|
||||||
env: options.env || this.defaultArgvs.options.env,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
},
|
|
||||||
generateCode(argvs) {
|
generateCode(argvs) {
|
||||||
const args = [];
|
const args = [];
|
||||||
|
|
||||||
@ -260,7 +232,7 @@ export default defineComponent({
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
getSummary(argvs) {
|
getSummary(argvs) {
|
||||||
return argvs.command.value;
|
return stringifyArgv(argvs.command);
|
||||||
},
|
},
|
||||||
updateModelValue(argvs) {
|
updateModelValue(argvs) {
|
||||||
this.$emit("update:modelValue", {
|
this.$emit("update:modelValue", {
|
||||||
@ -272,10 +244,7 @@ export default defineComponent({
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
mounted() {
|
mounted() {
|
||||||
const argvs = this.modelValue.argvs || this.defaultArgvs;
|
this.updateModelValue(this.argvs);
|
||||||
if (!this.modelValue.code) {
|
|
||||||
this.updateModelValue(argvs);
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
@ -50,6 +50,7 @@ import UBrowserBasic from "components/composer/ubrowser/UBrowserBasic.vue";
|
|||||||
import UBrowserOperations from "components/composer/ubrowser/UBrowserOperations.vue";
|
import UBrowserOperations from "components/composer/ubrowser/UBrowserOperations.vue";
|
||||||
import UBrowserRun from "components/composer/ubrowser/UBrowserRun.vue";
|
import UBrowserRun from "components/composer/ubrowser/UBrowserRun.vue";
|
||||||
import { generateUBrowserCode } from "js/composer/generateUBrowserCode";
|
import { generateUBrowserCode } from "js/composer/generateUBrowserCode";
|
||||||
|
import { stringifyArgv } from "src/js/composer/formatString";
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: "UBrowserEditor",
|
name: "UBrowserEditor",
|
||||||
@ -83,7 +84,7 @@ export default {
|
|||||||
return this.modelValue.argvs || this.defaultArgvs;
|
return this.modelValue.argvs || this.defaultArgvs;
|
||||||
},
|
},
|
||||||
summary() {
|
summary() {
|
||||||
const goto = this.argvs.goto?.url || "";
|
const goto = stringifyArgv(this.argvs.goto?.url || "");
|
||||||
return `访问 ${goto}`;
|
return `访问 ${goto}`;
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -112,9 +113,6 @@ export default {
|
|||||||
code: this.generateCode(),
|
code: this.generateCode(),
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
parseCodeToArgvs(code) {
|
|
||||||
// TODO: 实现代码解析逻辑
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user