@auto-mas/auto-mas-plugin-adapter-bettergi 0.2.1 → 0.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/server/adapters.js +23 -9
- package/dist/server/builtin-plugins/adapter-bettergi.js +2 -1
- package/dist/server/community/vault.js +65 -0
- package/dist/server/execution.js +111 -30
- package/dist/server/features.js +31 -0
- package/dist/server/game-plugins/bettergi.js +44 -5
- package/dist/server/game-plugins/native-config.js +275 -0
- package/dist/server/maa/account-settings.js +73 -0
- package/dist/server/maa/native-worker-source.js +196 -196
- package/dist/server/maa/project.js +27 -9
- package/package.json +1 -1
- package/dist/server/storage.js +0 -76
|
@@ -1,198 +1,198 @@
|
|
|
1
1
|
// Runs with the project's chosen Python binding and native libraries, in a separate process.
|
|
2
|
-
export const nativeWorkerSource = String.raw `
|
|
3
|
-
import json
|
|
4
|
-
import os
|
|
5
|
-
import re
|
|
6
|
-
import subprocess
|
|
7
|
-
import sys
|
|
8
|
-
from importlib.metadata import version
|
|
9
|
-
from pathlib import Path
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
def say(message):
|
|
13
|
-
print(message, flush=True)
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
def require(job, label):
|
|
17
|
-
if not job.wait().succeeded:
|
|
18
|
-
raise RuntimeError(label)
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
def executable(command, directory, agent_python=None):
|
|
22
|
-
if agent_python and re.fullmatch(r'python3?(?:\.exe)?', command, re.IGNORECASE):
|
|
23
|
-
return agent_python
|
|
24
|
-
expanded = command.replace('{PROJECT_DIR}', directory)
|
|
25
|
-
candidate = Path(directory, expanded)
|
|
26
|
-
if Path(expanded).is_absolute() or '/' in expanded or '\\' in expanded or candidate.is_file():
|
|
27
|
-
return str(candidate)
|
|
28
|
-
if sys.platform == 'win32' and Path(str(candidate) + '.exe').is_file():
|
|
29
|
-
return str(candidate) + '.exe'
|
|
30
|
-
return expanded
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
def launch(command, args, directory, env, agent_python):
|
|
34
|
-
program = executable(command['executable'], directory, agent_python)
|
|
35
|
-
return subprocess.Popen([program, *args], cwd=directory, env=env, stdin=subprocess.DEVNULL)
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
def methods(enum, value, default):
|
|
39
|
-
names = value if isinstance(value, list) else value.split('|') if isinstance(value, str) else [default]
|
|
40
|
-
result = 0
|
|
41
|
-
for name in names:
|
|
42
|
-
result |= int(enum[name.strip()])
|
|
43
|
-
return result
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
def make_controller(job):
|
|
47
|
-
from maa.controller import AdbController, Win32Controller
|
|
48
|
-
from maa.define import MaaWin32ScreencapMethodEnum, MaaWin32InputMethodEnum
|
|
49
|
-
from maa.toolkit import Toolkit
|
|
50
|
-
|
|
51
|
-
definition = job['controller']
|
|
52
|
-
selection = job['input']
|
|
53
|
-
if definition['type'] == 'Adb':
|
|
54
|
-
adb = selection.get('adbPath')
|
|
55
|
-
address = selection.get('address')
|
|
56
|
-
if adb:
|
|
57
|
-
adb = executable(adb, job['directory'])
|
|
58
|
-
devices = [item for item in Toolkit.find_adb_devices(adb) if not address or item.address == address]
|
|
59
|
-
if len(devices) > 1:
|
|
60
|
-
raise RuntimeError('发现多个 ADB 设备,请选择设备地址')
|
|
61
|
-
if devices:
|
|
62
|
-
device = devices[0]
|
|
63
|
-
return AdbController(device.adb_path, device.address, device.screencap_methods, device.input_methods, device.config)
|
|
64
|
-
if adb and address:
|
|
65
|
-
return AdbController(adb, address)
|
|
66
|
-
raise RuntimeError('原生运行器未发现所选 ADB 设备')
|
|
67
|
-
|
|
68
|
-
if definition['type'] != 'Win32' or sys.platform != 'win32':
|
|
69
|
-
raise RuntimeError('原生运行器仅支持 ADB 和 Windows Win32 控制器')
|
|
70
|
-
config = definition.get('win32') or {}
|
|
71
|
-
handle = selection.get('windowHandle')
|
|
72
|
-
if handle is None:
|
|
73
|
-
class_filter = config.get('class_regex')
|
|
74
|
-
window_filter = config.get('window_regex')
|
|
75
|
-
if not class_filter and not window_filter:
|
|
76
|
-
raise RuntimeError('请选择 Win32 窗口或声明窗口过滤条件')
|
|
77
|
-
windows = [item for item in Toolkit.find_desktop_windows()
|
|
78
|
-
if (not class_filter or re.search(class_filter, item.class_name))
|
|
79
|
-
and (not window_filter or re.search(window_filter, item.window_name))]
|
|
80
|
-
if len(windows) != 1:
|
|
81
|
-
raise RuntimeError('Win32 窗口匹配数为 ' + str(len(windows)) + ',请选择唯一窗口')
|
|
82
|
-
handle = windows[0].hwnd
|
|
83
|
-
elif not isinstance(handle, int) or handle <= 0:
|
|
84
|
-
raise RuntimeError('Win32 窗口句柄必须是正整数')
|
|
85
|
-
|
|
86
|
-
return Win32Controller(handle,
|
|
87
|
-
methods(MaaWin32ScreencapMethodEnum, config.get('screencap'), 'Background'),
|
|
88
|
-
methods(MaaWin32InputMethodEnum, config.get('mouse'), 'PostMessage'),
|
|
89
|
-
methods(MaaWin32InputMethodEnum, config.get('keyboard'), 'PostMessage'))
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
def configure_display(controller, definition):
|
|
93
|
-
if definition.get('display_raw') is True:
|
|
94
|
-
controller.set_screenshot_use_raw_size(True)
|
|
95
|
-
elif isinstance(definition.get('display_expand'), list) and len(definition['display_expand']) == 2:
|
|
96
|
-
controller.set_screenshot_target_expand(*definition['display_expand'])
|
|
97
|
-
elif isinstance(definition.get('display_long_side'), int):
|
|
98
|
-
controller.set_screenshot_target_long_side(definition['display_long_side'])
|
|
99
|
-
else:
|
|
100
|
-
controller.set_screenshot_target_short_side(definition.get('display_short_side') or 720)
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
def run(job, framework_version):
|
|
104
|
-
from maa.agent_client import AgentClient
|
|
105
|
-
from maa.resource import Resource
|
|
106
|
-
from maa.tasker import Tasker
|
|
107
|
-
|
|
108
|
-
directory = job['directory']
|
|
109
|
-
agent_python = job['input'].get('agentPython')
|
|
110
|
-
env = dict(os.environ, **job['agentEnvironment'], PI_CLIENT_MAAFW_VERSION=framework_version)
|
|
111
|
-
# Agent executables own their libraries. Apply the override only to this worker.
|
|
112
|
-
env.pop('MAAFW_BINARY_PATH', None)
|
|
113
|
-
for index, pretask in enumerate(job['pretasks'], 1):
|
|
114
|
-
say(f'执行前置任务 {index}')
|
|
115
|
-
cwd = pretask.get('directory', directory)
|
|
116
|
-
args = [arg.replace('{PROJECT_DIR}', cwd) for arg in pretask['args']]
|
|
117
|
-
if pretask.get('optionArgument'):
|
|
118
|
-
args.append(pretask['optionArgument'])
|
|
119
|
-
if launch(pretask, args, cwd, env, agent_python).wait() != 0:
|
|
120
|
-
raise RuntimeError(f'前置任务 {index} 执行失败')
|
|
121
|
-
|
|
122
|
-
resource = Resource()
|
|
123
|
-
for path in [*job['resourcePaths'], *job['attachedPaths']]:
|
|
124
|
-
require(resource.post_bundle(path), '原生运行器无法加载资源:' + path)
|
|
125
|
-
controller = make_controller(job)
|
|
126
|
-
configure_display(controller, job['controller'])
|
|
127
|
-
require(controller.post_connection(), '原生运行器无法连接控制目标')
|
|
128
|
-
tasker = Tasker()
|
|
129
|
-
if not tasker.bind(resource, controller):
|
|
130
|
-
raise RuntimeError('原生运行器无法绑定资源及控制器')
|
|
131
|
-
agents = []
|
|
132
|
-
try:
|
|
133
|
-
for index, agent in enumerate(job['agents'], 1):
|
|
134
|
-
say(f'启动 Agent {index}')
|
|
135
|
-
client = AgentClient(agent.get('identifier'))
|
|
136
|
-
if not client.identifier or not client.bind(resource) or not client.register_sink(resource, controller, tasker):
|
|
137
|
-
raise RuntimeError(f'Agent {index} 无法绑定 MaaFramework')
|
|
138
|
-
client.set_timeout(15_000)
|
|
139
|
-
cwd = agent.get('directory', directory)
|
|
140
|
-
args = [arg.replace('{PROJECT_DIR}', cwd) for arg in agent['args']] + [client.identifier]
|
|
141
|
-
process = launch(agent, args, cwd, env, agent_python)
|
|
142
|
-
agents.append((client, process))
|
|
143
|
-
if not client.connect():
|
|
144
|
-
raise RuntimeError(f'Agent {index} 无法连接')
|
|
145
|
-
for task in job['tasks']:
|
|
146
|
-
say('开始任务 ' + task['name'])
|
|
147
|
-
require(tasker.post_task(task['entry'], task['override']), '任务执行失败:' + task['name'])
|
|
148
|
-
if any(process.poll() is not None for _, process in agents):
|
|
149
|
-
raise RuntimeError('Agent 提前退出')
|
|
150
|
-
say('完成任务 ' + task['name'])
|
|
151
|
-
finally:
|
|
152
|
-
for client, process in reversed(agents):
|
|
153
|
-
try:
|
|
154
|
-
if client.connected:
|
|
155
|
-
client.disconnect()
|
|
156
|
-
finally:
|
|
157
|
-
if process.poll() is None:
|
|
158
|
-
process.terminate()
|
|
159
|
-
try:
|
|
160
|
-
process.wait(timeout=2)
|
|
161
|
-
except subprocess.TimeoutExpired:
|
|
162
|
-
process.kill()
|
|
163
|
-
process.wait()
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
def main():
|
|
167
|
-
if len(sys.argv) > 1:
|
|
168
|
-
request = json.loads(Path(sys.argv[1]).read_text(encoding='utf-8'))
|
|
169
|
-
else:
|
|
170
|
-
request = json.load(sys.stdin)
|
|
171
|
-
path = request['nativeLibraries']
|
|
172
|
-
os.environ['MAAFW_BINARY_PATH'] = path
|
|
173
|
-
dll_directory = os.add_dll_directory(path) if sys.platform == 'win32' else None
|
|
174
|
-
try:
|
|
175
|
-
from maa.library import Library
|
|
176
|
-
binding_version = version('maafw')
|
|
177
|
-
framework_version = Library.version()
|
|
178
|
-
number = lambda value: re.match(r'^v?(\d+\.\d+\.\d+)', value)
|
|
179
|
-
binding_number = number(binding_version)
|
|
180
|
-
library_number = number(framework_version)
|
|
181
|
-
if not binding_number or not library_number or binding_number.group(1) != library_number.group(1):
|
|
182
|
-
raise RuntimeError(f'MaaFramework 原生库 {framework_version} 与 Python 绑定 {binding_version} 不匹配')
|
|
183
|
-
if request.get('job') is not None:
|
|
184
|
-
say('MaaFramework 项目原生运行库 ' + framework_version)
|
|
185
|
-
run(request['job'], framework_version)
|
|
186
|
-
say('MAS_MAA_NATIVE_DONE ' + framework_version)
|
|
187
|
-
finally:
|
|
188
|
-
if dll_directory:
|
|
189
|
-
dll_directory.close()
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
if __name__ == '__main__':
|
|
193
|
-
try:
|
|
194
|
-
main()
|
|
195
|
-
except Exception as error:
|
|
196
|
-
say('MAS_MAA_NATIVE_ERROR ' + str(error).replace('\n', ' ')[:400])
|
|
197
|
-
sys.exit(1)
|
|
2
|
+
export const nativeWorkerSource = String.raw `
|
|
3
|
+
import json
|
|
4
|
+
import os
|
|
5
|
+
import re
|
|
6
|
+
import subprocess
|
|
7
|
+
import sys
|
|
8
|
+
from importlib.metadata import version
|
|
9
|
+
from pathlib import Path
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def say(message):
|
|
13
|
+
print(message, flush=True)
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def require(job, label):
|
|
17
|
+
if not job.wait().succeeded:
|
|
18
|
+
raise RuntimeError(label)
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def executable(command, directory, agent_python=None):
|
|
22
|
+
if agent_python and re.fullmatch(r'python3?(?:\.exe)?', command, re.IGNORECASE):
|
|
23
|
+
return agent_python
|
|
24
|
+
expanded = command.replace('{PROJECT_DIR}', directory)
|
|
25
|
+
candidate = Path(directory, expanded)
|
|
26
|
+
if Path(expanded).is_absolute() or '/' in expanded or '\\' in expanded or candidate.is_file():
|
|
27
|
+
return str(candidate)
|
|
28
|
+
if sys.platform == 'win32' and Path(str(candidate) + '.exe').is_file():
|
|
29
|
+
return str(candidate) + '.exe'
|
|
30
|
+
return expanded
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def launch(command, args, directory, env, agent_python):
|
|
34
|
+
program = executable(command['executable'], directory, agent_python)
|
|
35
|
+
return subprocess.Popen([program, *args], cwd=directory, env=env, stdin=subprocess.DEVNULL)
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def methods(enum, value, default):
|
|
39
|
+
names = value if isinstance(value, list) else value.split('|') if isinstance(value, str) else [default]
|
|
40
|
+
result = 0
|
|
41
|
+
for name in names:
|
|
42
|
+
result |= int(enum[name.strip()])
|
|
43
|
+
return result
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def make_controller(job):
|
|
47
|
+
from maa.controller import AdbController, Win32Controller
|
|
48
|
+
from maa.define import MaaWin32ScreencapMethodEnum, MaaWin32InputMethodEnum
|
|
49
|
+
from maa.toolkit import Toolkit
|
|
50
|
+
|
|
51
|
+
definition = job['controller']
|
|
52
|
+
selection = job['input']
|
|
53
|
+
if definition['type'] == 'Adb':
|
|
54
|
+
adb = selection.get('adbPath')
|
|
55
|
+
address = selection.get('address')
|
|
56
|
+
if adb:
|
|
57
|
+
adb = executable(adb, job['directory'])
|
|
58
|
+
devices = [item for item in Toolkit.find_adb_devices(adb) if not address or item.address == address]
|
|
59
|
+
if len(devices) > 1:
|
|
60
|
+
raise RuntimeError('发现多个 ADB 设备,请选择设备地址')
|
|
61
|
+
if devices:
|
|
62
|
+
device = devices[0]
|
|
63
|
+
return AdbController(device.adb_path, device.address, device.screencap_methods, device.input_methods, device.config)
|
|
64
|
+
if adb and address:
|
|
65
|
+
return AdbController(adb, address)
|
|
66
|
+
raise RuntimeError('原生运行器未发现所选 ADB 设备')
|
|
67
|
+
|
|
68
|
+
if definition['type'] != 'Win32' or sys.platform != 'win32':
|
|
69
|
+
raise RuntimeError('原生运行器仅支持 ADB 和 Windows Win32 控制器')
|
|
70
|
+
config = definition.get('win32') or {}
|
|
71
|
+
handle = selection.get('windowHandle')
|
|
72
|
+
if handle is None:
|
|
73
|
+
class_filter = config.get('class_regex')
|
|
74
|
+
window_filter = config.get('window_regex')
|
|
75
|
+
if not class_filter and not window_filter:
|
|
76
|
+
raise RuntimeError('请选择 Win32 窗口或声明窗口过滤条件')
|
|
77
|
+
windows = [item for item in Toolkit.find_desktop_windows()
|
|
78
|
+
if (not class_filter or re.search(class_filter, item.class_name))
|
|
79
|
+
and (not window_filter or re.search(window_filter, item.window_name))]
|
|
80
|
+
if len(windows) != 1:
|
|
81
|
+
raise RuntimeError('Win32 窗口匹配数为 ' + str(len(windows)) + ',请选择唯一窗口')
|
|
82
|
+
handle = windows[0].hwnd
|
|
83
|
+
elif not isinstance(handle, int) or handle <= 0:
|
|
84
|
+
raise RuntimeError('Win32 窗口句柄必须是正整数')
|
|
85
|
+
|
|
86
|
+
return Win32Controller(handle,
|
|
87
|
+
methods(MaaWin32ScreencapMethodEnum, config.get('screencap'), 'Background'),
|
|
88
|
+
methods(MaaWin32InputMethodEnum, config.get('mouse'), 'PostMessage'),
|
|
89
|
+
methods(MaaWin32InputMethodEnum, config.get('keyboard'), 'PostMessage'))
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
def configure_display(controller, definition):
|
|
93
|
+
if definition.get('display_raw') is True:
|
|
94
|
+
controller.set_screenshot_use_raw_size(True)
|
|
95
|
+
elif isinstance(definition.get('display_expand'), list) and len(definition['display_expand']) == 2:
|
|
96
|
+
controller.set_screenshot_target_expand(*definition['display_expand'])
|
|
97
|
+
elif isinstance(definition.get('display_long_side'), int):
|
|
98
|
+
controller.set_screenshot_target_long_side(definition['display_long_side'])
|
|
99
|
+
else:
|
|
100
|
+
controller.set_screenshot_target_short_side(definition.get('display_short_side') or 720)
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
def run(job, framework_version):
|
|
104
|
+
from maa.agent_client import AgentClient
|
|
105
|
+
from maa.resource import Resource
|
|
106
|
+
from maa.tasker import Tasker
|
|
107
|
+
|
|
108
|
+
directory = job['directory']
|
|
109
|
+
agent_python = job['input'].get('agentPython')
|
|
110
|
+
env = dict(os.environ, **job['agentEnvironment'], PI_CLIENT_MAAFW_VERSION=framework_version)
|
|
111
|
+
# Agent executables own their libraries. Apply the override only to this worker.
|
|
112
|
+
env.pop('MAAFW_BINARY_PATH', None)
|
|
113
|
+
for index, pretask in enumerate(job['pretasks'], 1):
|
|
114
|
+
say(f'执行前置任务 {index}')
|
|
115
|
+
cwd = pretask.get('directory', directory)
|
|
116
|
+
args = [arg.replace('{PROJECT_DIR}', cwd) for arg in pretask['args']]
|
|
117
|
+
if pretask.get('optionArgument'):
|
|
118
|
+
args.append(pretask['optionArgument'])
|
|
119
|
+
if launch(pretask, args, cwd, env, agent_python).wait() != 0:
|
|
120
|
+
raise RuntimeError(f'前置任务 {index} 执行失败')
|
|
121
|
+
|
|
122
|
+
resource = Resource()
|
|
123
|
+
for path in [*job['resourcePaths'], *job['attachedPaths']]:
|
|
124
|
+
require(resource.post_bundle(path), '原生运行器无法加载资源:' + path)
|
|
125
|
+
controller = make_controller(job)
|
|
126
|
+
configure_display(controller, job['controller'])
|
|
127
|
+
require(controller.post_connection(), '原生运行器无法连接控制目标')
|
|
128
|
+
tasker = Tasker()
|
|
129
|
+
if not tasker.bind(resource, controller):
|
|
130
|
+
raise RuntimeError('原生运行器无法绑定资源及控制器')
|
|
131
|
+
agents = []
|
|
132
|
+
try:
|
|
133
|
+
for index, agent in enumerate(job['agents'], 1):
|
|
134
|
+
say(f'启动 Agent {index}')
|
|
135
|
+
client = AgentClient(agent.get('identifier'))
|
|
136
|
+
if not client.identifier or not client.bind(resource) or not client.register_sink(resource, controller, tasker):
|
|
137
|
+
raise RuntimeError(f'Agent {index} 无法绑定 MaaFramework')
|
|
138
|
+
client.set_timeout(15_000)
|
|
139
|
+
cwd = agent.get('directory', directory)
|
|
140
|
+
args = [arg.replace('{PROJECT_DIR}', cwd) for arg in agent['args']] + [client.identifier]
|
|
141
|
+
process = launch(agent, args, cwd, env, agent_python)
|
|
142
|
+
agents.append((client, process))
|
|
143
|
+
if not client.connect():
|
|
144
|
+
raise RuntimeError(f'Agent {index} 无法连接')
|
|
145
|
+
for task in job['tasks']:
|
|
146
|
+
say('开始任务 ' + task['name'])
|
|
147
|
+
require(tasker.post_task(task['entry'], task['override']), '任务执行失败:' + task['name'])
|
|
148
|
+
if any(process.poll() is not None for _, process in agents):
|
|
149
|
+
raise RuntimeError('Agent 提前退出')
|
|
150
|
+
say('完成任务 ' + task['name'])
|
|
151
|
+
finally:
|
|
152
|
+
for client, process in reversed(agents):
|
|
153
|
+
try:
|
|
154
|
+
if client.connected:
|
|
155
|
+
client.disconnect()
|
|
156
|
+
finally:
|
|
157
|
+
if process.poll() is None:
|
|
158
|
+
process.terminate()
|
|
159
|
+
try:
|
|
160
|
+
process.wait(timeout=2)
|
|
161
|
+
except subprocess.TimeoutExpired:
|
|
162
|
+
process.kill()
|
|
163
|
+
process.wait()
|
|
164
|
+
|
|
165
|
+
|
|
166
|
+
def main():
|
|
167
|
+
if len(sys.argv) > 1:
|
|
168
|
+
request = json.loads(Path(sys.argv[1]).read_text(encoding='utf-8'))
|
|
169
|
+
else:
|
|
170
|
+
request = json.load(sys.stdin)
|
|
171
|
+
path = request['nativeLibraries']
|
|
172
|
+
os.environ['MAAFW_BINARY_PATH'] = path
|
|
173
|
+
dll_directory = os.add_dll_directory(path) if sys.platform == 'win32' else None
|
|
174
|
+
try:
|
|
175
|
+
from maa.library import Library
|
|
176
|
+
binding_version = version('maafw')
|
|
177
|
+
framework_version = Library.version()
|
|
178
|
+
number = lambda value: re.match(r'^v?(\d+\.\d+\.\d+)', value)
|
|
179
|
+
binding_number = number(binding_version)
|
|
180
|
+
library_number = number(framework_version)
|
|
181
|
+
if not binding_number or not library_number or binding_number.group(1) != library_number.group(1):
|
|
182
|
+
raise RuntimeError(f'MaaFramework 原生库 {framework_version} 与 Python 绑定 {binding_version} 不匹配')
|
|
183
|
+
if request.get('job') is not None:
|
|
184
|
+
say('MaaFramework 项目原生运行库 ' + framework_version)
|
|
185
|
+
run(request['job'], framework_version)
|
|
186
|
+
say('MAS_MAA_NATIVE_DONE ' + framework_version)
|
|
187
|
+
finally:
|
|
188
|
+
if dll_directory:
|
|
189
|
+
dll_directory.close()
|
|
190
|
+
|
|
191
|
+
|
|
192
|
+
if __name__ == '__main__':
|
|
193
|
+
try:
|
|
194
|
+
main()
|
|
195
|
+
except Exception as error:
|
|
196
|
+
say('MAS_MAA_NATIVE_ERROR ' + str(error).replace('\n', ' ')[:400])
|
|
197
|
+
sys.exit(1)
|
|
198
198
|
`;
|
|
@@ -427,6 +427,15 @@ export function planRun(project, input) {
|
|
|
427
427
|
if (!project.options.has(key))
|
|
428
428
|
throw new Error(`ProjectInterface has unknown option "${key}".`);
|
|
429
429
|
}
|
|
430
|
+
const unapplied = new Set(input.requiredOptions);
|
|
431
|
+
for (const key of unapplied) {
|
|
432
|
+
const option = project.options.get(key);
|
|
433
|
+
const value = object(overrides.get(key));
|
|
434
|
+
if (option?.type === 'input' && value && namedObjects(option.inputs, `option ${key}.inputs`)
|
|
435
|
+
.some(field => field.password === true && Object.hasOwn(value, field.name))) {
|
|
436
|
+
throw new Error('当前版本无法安全保存 MaaFramework 密码选项');
|
|
437
|
+
}
|
|
438
|
+
}
|
|
430
439
|
const controller = input.controller === undefined
|
|
431
440
|
? project.controllers.find((item) => supportsController(item.type))
|
|
432
441
|
: project.controllers.find((item) => item.name === input.controller);
|
|
@@ -465,30 +474,39 @@ export function planRun(project, input) {
|
|
|
465
474
|
presetOptions.set(task.name, entries);
|
|
466
475
|
}
|
|
467
476
|
const withPreset = (options) => options ? new Map(Object.entries(merge(options, specified))) : overrides;
|
|
477
|
+
function resolveApplied(keys, values) {
|
|
478
|
+
const resolved = resolveOptions(project, selection, keys, values);
|
|
479
|
+
for (const name of Object.keys(resolved.selected))
|
|
480
|
+
unapplied.delete(name);
|
|
481
|
+
return resolved;
|
|
482
|
+
}
|
|
468
483
|
const sharedKeys = [...project.globalOptions, ...resource.option ?? [], ...controller.option ?? []];
|
|
469
|
-
const sharedOptions =
|
|
484
|
+
const sharedOptions = resolveApplied(sharedKeys, overrides).override;
|
|
470
485
|
const tasks = names.map((name) => {
|
|
471
486
|
const task = tasksByName.get(name);
|
|
472
487
|
if (!task)
|
|
473
488
|
throw new Error(`Unknown ProjectInterface task "${name}".`);
|
|
474
489
|
if (!matches(task, selection))
|
|
475
490
|
throw new Error(`Task "${name}" cannot run with controller "${controller.name}" and resource "${resource.name}".`);
|
|
476
|
-
const taskOptions =
|
|
491
|
+
const taskOptions = resolveApplied(task.option ?? [], withPreset(presetOptions.get(name)?.shift())).override;
|
|
477
492
|
return { name: task.name, entry: task.entry, override: merge(merge(pipeline(task.pipeline_override, `task ${name}`), sharedOptions), taskOptions) };
|
|
478
493
|
});
|
|
479
494
|
const presetPretasks = preset?.pretask && new Map(preset.pretask.map(item => [item.name, item]));
|
|
495
|
+
const pretasks = project.pretasks.filter(item => matches(item, selection)
|
|
496
|
+
&& (!presetPretasks || item.name && presetPretasks.get(item.name)?.enabled)).map((item) => ({
|
|
497
|
+
...item,
|
|
498
|
+
optionArgument: item.option?.length
|
|
499
|
+
? JSON.stringify(resolveApplied(item.option, withPreset(item.name ? presetPretasks?.get(item.name)?.option : undefined)).selected)
|
|
500
|
+
: undefined,
|
|
501
|
+
}));
|
|
502
|
+
if (unapplied.size)
|
|
503
|
+
throw new Error(`账号选项不适用于当前任务、控制器或资源:${[...unapplied].join('、')}`);
|
|
480
504
|
return {
|
|
481
505
|
controller, resource, tasks,
|
|
482
506
|
resourcePaths: resource.path.map((path) => projectPath(project.directory, path)),
|
|
483
507
|
attachedPaths: (controller.attach_resource_path ?? []).map((path) => projectPath(project.directory, path)),
|
|
484
508
|
agents: project.agents,
|
|
485
|
-
pretasks
|
|
486
|
-
&& (!presetPretasks || item.name && presetPretasks.get(item.name)?.enabled)).map((item) => ({
|
|
487
|
-
...item,
|
|
488
|
-
optionArgument: item.option?.length
|
|
489
|
-
? JSON.stringify(resolveOptions(project, selection, item.option, withPreset(item.name ? presetPretasks?.get(item.name)?.option : undefined)).selected)
|
|
490
|
-
: undefined,
|
|
491
|
-
})),
|
|
509
|
+
pretasks,
|
|
492
510
|
agentEnvironment: {
|
|
493
511
|
PI_INTERFACE_VERSION: 'v2.8.1',
|
|
494
512
|
PI_CLIENT_NAME: 'Cordis MAS',
|
package/package.json
CHANGED
package/dist/server/storage.js
DELETED
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
import { mkdirSync } from 'node:fs';
|
|
2
|
-
import { join } from 'node:path';
|
|
3
|
-
import { DatabaseSync } from 'node:sqlite';
|
|
4
|
-
export class Store {
|
|
5
|
-
db;
|
|
6
|
-
lease;
|
|
7
|
-
constructor(directory) {
|
|
8
|
-
mkdirSync(directory, { recursive: true });
|
|
9
|
-
this.lease = new DatabaseSync(join(directory, 'session.db'));
|
|
10
|
-
try {
|
|
11
|
-
this.lease.exec('PRAGMA busy_timeout = 0; BEGIN EXCLUSIVE');
|
|
12
|
-
}
|
|
13
|
-
catch (error) {
|
|
14
|
-
this.lease.close();
|
|
15
|
-
if (error.errcode === 5)
|
|
16
|
-
throw new Error('该数据目录已有 MAS 后端在运行');
|
|
17
|
-
throw error;
|
|
18
|
-
}
|
|
19
|
-
try {
|
|
20
|
-
this.db = new DatabaseSync(join(directory, 'mas.db'));
|
|
21
|
-
this.db.exec(`PRAGMA journal_mode = WAL;
|
|
22
|
-
CREATE TABLE IF NOT EXISTS entries (
|
|
23
|
-
collection TEXT NOT NULL, id TEXT NOT NULL, value TEXT NOT NULL,
|
|
24
|
-
PRIMARY KEY (collection, id)
|
|
25
|
-
);
|
|
26
|
-
CREATE INDEX IF NOT EXISTS run_start ON entries (
|
|
27
|
-
unixepoch(json_extract(value, '$.started'), 'subsec') DESC
|
|
28
|
-
) WHERE collection = 'runs'`);
|
|
29
|
-
}
|
|
30
|
-
catch (error) {
|
|
31
|
-
this.lease.close();
|
|
32
|
-
throw error;
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
recentRuns() {
|
|
36
|
-
return this.db.prepare(`SELECT value FROM entries WHERE collection = 'runs'
|
|
37
|
-
ORDER BY unixepoch(json_extract(value, '$.started'), 'subsec') DESC, rowid DESC LIMIT 200`)
|
|
38
|
-
.all().map(row => JSON.parse(String(row.value)));
|
|
39
|
-
}
|
|
40
|
-
list(collection) {
|
|
41
|
-
const rows = this.db.prepare('SELECT value FROM entries WHERE collection = ? ORDER BY rowid').all(collection);
|
|
42
|
-
return rows.map(row => JSON.parse(String(row.value)));
|
|
43
|
-
}
|
|
44
|
-
get(collection, id) {
|
|
45
|
-
const row = this.db.prepare('SELECT value FROM entries WHERE collection = ? AND id = ?').get(collection, id);
|
|
46
|
-
return row && JSON.parse(String(row.value));
|
|
47
|
-
}
|
|
48
|
-
put(collection, entry) {
|
|
49
|
-
this.db.prepare('INSERT INTO entries VALUES (?, ?, ?) ON CONFLICT(collection, id) DO UPDATE SET value = excluded.value')
|
|
50
|
-
.run(collection, entry.id, JSON.stringify(entry));
|
|
51
|
-
return entry;
|
|
52
|
-
}
|
|
53
|
-
remove(collection, id) {
|
|
54
|
-
this.db.prepare('DELETE FROM entries WHERE collection = ? AND id = ?').run(collection, id);
|
|
55
|
-
}
|
|
56
|
-
transaction(callback) {
|
|
57
|
-
this.db.exec('BEGIN IMMEDIATE');
|
|
58
|
-
try {
|
|
59
|
-
const result = callback();
|
|
60
|
-
this.db.exec('COMMIT');
|
|
61
|
-
return result;
|
|
62
|
-
}
|
|
63
|
-
catch (error) {
|
|
64
|
-
this.db.exec('ROLLBACK');
|
|
65
|
-
throw error;
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
close() {
|
|
69
|
-
try {
|
|
70
|
-
this.db.close();
|
|
71
|
-
}
|
|
72
|
-
finally {
|
|
73
|
-
this.lease.close();
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
}
|