@unionschool/easy-agents 1.0.23 → 1.0.27
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/README.md +7 -7
- package/bin/easy-agents.js +4 -1
- package/bin/mac-service.js +73 -11
- package/bin/run.js +1 -1
- package/bin/tasks.js +49 -11
- package/package.json +2 -2
- package/runtime/task_run.py +18 -2
package/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# EasyAgents
|
|
1
|
+
# EasyAgents
|
|
2
2
|
|
|
3
3
|
在要接任务的设备上单独安装客户端,首次用工作台生成的配对码绑定设备。Mac、Windows 和 Ubuntu 安装包自带 Node、Python 和客户端核心。设备要使用 Codex 或 Claude 时,还需安装并登录对应的工具。
|
|
4
4
|
|
|
@@ -6,8 +6,8 @@
|
|
|
6
6
|
|
|
7
7
|
| 设备 | 安装和打开 | 设备配置位置 |
|
|
8
8
|
| --- | --- | --- |
|
|
9
|
-
| macOS 14+ | Intel 和 Apple 芯片都使用 `EasyAgents-Mac-Universal.zip`。解压后把 `EasyAgents
|
|
10
|
-
| Windows x64 | 双击 `EasyAgents-Setup.exe`,按当前用户安装。从开始菜单打开 **EasyAgents
|
|
9
|
+
| macOS 14+ | Intel 和 Apple 芯片都使用 `EasyAgents-Mac-Universal.zip`。解压后把 `EasyAgents.app` 拖入「应用程序」并打开,点菜单栏图标。 | `~/Library/Application Support/EasyAgents Client/` |
|
|
10
|
+
| Windows x64 | 双击 `EasyAgents-Setup.exe`,按当前用户安装。从开始菜单打开 **EasyAgents**,以后可点托盘图标。在新终端输入 `easy-agents` 也可打开面板。 | `%APPDATA%\EasyAgents\` |
|
|
11
11
|
| Ubuntu x64 | 在压缩包所在目录执行下面两行,以运行客户端的普通用户安装。 | `~/.easyagents/` |
|
|
12
12
|
| Android 8+ | 安装交付的 `EasyAgents-Android-test.apk`,打开应用,用 Linux 设备配对码接入,点「上线接任务」。前台通知显示服务状态。 | 应用私有存储和 Android Keystore |
|
|
13
13
|
|
|
@@ -20,13 +20,13 @@ Ubuntu 的程序入口是 `~/.local/share/easyagents-client/current/easy-agents`
|
|
|
20
20
|
|
|
21
21
|
### 在 Mac 终端直接使用 easy-agents
|
|
22
22
|
|
|
23
|
-
应用内的命令是 `"/Applications/EasyAgents
|
|
23
|
+
应用内的命令是 `"/Applications/EasyAgents.app/Contents/Resources/easy-agents"`(2026-11-23 前应用叫 `EasyAgents Client.app`,装新版后面板会自动把后台、开机启动和下面这个入口改到新应用,旧应用移到废纸篓)。用 `command -v easy-agents` 核对现有入口。以下命令为当前用户创建启动脚本,已有入口时会跳过创建。
|
|
24
24
|
|
|
25
25
|
```sh
|
|
26
26
|
mkdir -p "$HOME/.local/bin"
|
|
27
27
|
launcher="$HOME/.local/bin/easy-agents"
|
|
28
28
|
if [ ! -e "$launcher" ] && [ ! -L "$launcher" ]; then
|
|
29
|
-
printf '%s\n' '#!/bin/sh' 'exec "/Applications/EasyAgents
|
|
29
|
+
printf '%s\n' '#!/bin/sh' 'exec "/Applications/EasyAgents.app/Contents/Resources/easy-agents" "$@"' > "$launcher" && chmod 755 "$launcher"
|
|
30
30
|
fi
|
|
31
31
|
export PATH="$HOME/.local/bin:$PATH"
|
|
32
32
|
command -v easy-agents
|
|
@@ -94,6 +94,6 @@ npm exec --offline -- easy-agents run
|
|
|
94
94
|
- Node 核心支持 `/sha256 <文本>`、本地 Markdown 文档里的同类计算和成员同步。文档与同步的目录需与本机选定工作目录相符,可用 `EASYAGENTS_WORKSPACE` 指定。成员同步使用包内实现、系统 Git 和 Python 3.10+,更新已有检出目录。Android 首版可执行 SHA-256 消息和用户选择目录里的计算文档。
|
|
95
95
|
- 客户端保存待回传结果,重连后补传。独立版尚未接入运行中 `/steer`、手动 `/sync`、平台远程读文档和编辑设备上的工具规则。
|
|
96
96
|
|
|
97
|
-
开发者在 `
|
|
97
|
+
开发者在 `client/` 中执行 `npm ci`、`npm pack` 构建通用包。包内包含 `runtime/easyagents_core/` 中的 Git、文件交付和 MCP 模块及其进程支持,并随包附带 WebSocket 依赖。桌面安装器从同一目录取工具、模型、额度和平台 API 模块,按 `scripts/desktop-requirements.txt` 安装固定版本的 Python 依赖。
|
|
98
98
|
|
|
99
|
-
在 Mac 上,从仓库根目录运行 `uv run --no-project --python 3.12 python
|
|
99
|
+
在 Mac 上,从仓库根目录运行 `uv run --no-project --python 3.12 python client/macos/install.py --zip /path/to/EasyAgents-Mac-Universal.zip` 生成通用 ZIP。该模式只写出压缩包。菜单栏程序、Node 和内置 Python 都包含 `x86_64` 与 `arm64`。
|
package/bin/easy-agents.js
CHANGED
|
@@ -87,7 +87,7 @@ function updater(automatic) {
|
|
|
87
87
|
const [command = desktop ? (process.platform === 'linux' ? 'status' : 'show') : '--help', ...args] = process.argv.slice(2);
|
|
88
88
|
try {
|
|
89
89
|
if (['--help', '-h'].includes(command) && !args.length) {
|
|
90
|
-
console.log('EasyAgents
|
|
90
|
+
console.log('EasyAgents\n\n'
|
|
91
91
|
+ 'easy-agents --version\n'
|
|
92
92
|
+ 'easy-agents configure <网关地址> <端口>\n'
|
|
93
93
|
+ 'easy-agents pair\n'
|
|
@@ -143,6 +143,9 @@ try {
|
|
|
143
143
|
} else if (desktop && command === 'auto-update' && args.length === 1 && ['on','off'].includes(args[0])) {
|
|
144
144
|
(await desktopState()).writeSnapshot(configDir, 'auto-update.json', { enabled: args[0] === 'on' });
|
|
145
145
|
console.log(args[0] === 'on' ? '自动更新已开启' : '自动更新已关闭');
|
|
146
|
+
} else if (mac && command === 'relocate' && !args.length) {
|
|
147
|
+
// 应用改名或换位置后,把开机启动、面板自启、后台任务的 launchd 配置改到当前应用(安装脚本和面板会自动调用)。
|
|
148
|
+
console.log(await (await controls()).relocate(configDir));
|
|
146
149
|
} else if (desktop && command === 'autostart' && args.length === 1 && ['on','off'].includes(args[0])) {
|
|
147
150
|
if (args[0] === 'on' && !readSettings(devicePath)) throw new Error('请先配对设备,再设置开机启动');
|
|
148
151
|
if (mac) await (await controls()).autostart(configDir, args[0] === 'on');
|
package/bin/mac-service.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { execFileSync } from 'node:child_process';
|
|
2
2
|
import { createHash } from 'node:crypto';
|
|
3
|
-
import { existsSync, mkdirSync, openSync, closeSync, renameSync, rmSync, writeFileSync } from 'node:fs';
|
|
3
|
+
import { existsSync, mkdirSync, openSync, closeSync, readFileSync, renameSync, rmSync, writeFileSync } from 'node:fs';
|
|
4
4
|
import { homedir, userInfo } from 'node:os';
|
|
5
|
-
import { dirname, join } from 'node:path';
|
|
5
|
+
import { basename, dirname, join } from 'node:path';
|
|
6
6
|
import { setTimeout as sleep } from 'node:timers/promises';
|
|
7
7
|
import { macResources, readSnapshot, terminalEnabled, compactAt } from './mac-reports.js';
|
|
8
8
|
|
|
@@ -57,14 +57,76 @@ export async function autostart(folder, enabled) {
|
|
|
57
57
|
+ '/usr/sbin/chown root:wheel "$t"; /bin/chmod 644 "$t"; /bin/mv -f "$t" ' + target;
|
|
58
58
|
admin(cmd);
|
|
59
59
|
} else if (!enabled && bootEnabled(folder)) admin('/bin/rm -f ' + target);
|
|
60
|
-
if (enabled)
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
60
|
+
if (enabled) writePanel(folder);
|
|
61
|
+
else rmSync(agent,{force:true});
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const panelFile = folder => join(homedir(),'Library/LaunchAgents',bootLabel(folder) + '.panel.plist');
|
|
65
|
+
|
|
66
|
+
function writePanel(folder) {
|
|
67
|
+
const agent = panelFile(folder);
|
|
68
|
+
mkdirSync(dirname(agent), { recursive: true, mode: 0o700 });
|
|
69
|
+
const temporary = agent + '.' + process.pid;
|
|
70
|
+
const exe = join(dirname(macResources),'MacOS/EasyAgentsClient');
|
|
71
|
+
writeFileSync(temporary, plist(entry('Label',str(bootLabel(folder) + '.panel')) + entry('RunAtLoad','<true/>')
|
|
72
|
+
+ entry('ProgramArguments','<array>' + str(exe) + str('--background') + '</array>')), { mode: 0o600, flag:'wx' });
|
|
73
|
+
renameSync(temporary,agent);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// 应用改名或挪了位置(2026-11-23 起 EasyAgents Client.app 改名 EasyAgents.app):launchd 配置里写死了程序路径,
|
|
77
|
+
// 指向旧应用的要换成当前应用,否则下次开机或重启后台就找不到程序。配置目录与设备身份不变。
|
|
78
|
+
const unxml = s => s.replaceAll('<','<').replaceAll('>','>').replaceAll('&','&');
|
|
79
|
+
export function programOf(file) {
|
|
80
|
+
try { const found = readFileSync(file,'utf8').match(/<key>ProgramArguments<\/key><array><string>([^<]*)<\/string>/); return found ? unxml(found[1]) : null; }
|
|
81
|
+
catch { return null; }
|
|
82
|
+
}
|
|
83
|
+
const currentBundle = () => dirname(dirname(macResources));
|
|
84
|
+
const elsewhere = file => { const program = programOf(file); return program !== null && !program.startsWith(currentBundle() + '/'); };
|
|
85
|
+
const launchdFiles = folder => [bootFile(folder), panelFile(folder), join(folder,'mac-worker.plist')];
|
|
86
|
+
export const moved = folder => launchdFiles(folder).some(elsewhere);
|
|
87
|
+
|
|
88
|
+
// 安装指南教用户建的命令行入口(一行 exec 应用内的 easy-agents),旧路径换成当前应用。
|
|
89
|
+
function relaunchers(old) {
|
|
90
|
+
for (const file of [join(homedir(),'.local/bin/easy-agents'), '/usr/local/bin/easy-agents', '/opt/homebrew/bin/easy-agents']) {
|
|
91
|
+
try {
|
|
92
|
+
const text = readFileSync(file, 'utf8');
|
|
93
|
+
if (text.length < 400 && text.includes('exec "' + old + '/Contents/Resources/easy-agents"'))
|
|
94
|
+
writeFileSync(file, text.replaceAll(old + '/Contents/Resources/', currentBundle() + '/Contents/Resources/'));
|
|
95
|
+
} catch {}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export async function relocate(folder) {
|
|
100
|
+
const stale = launchdFiles(folder).filter(elsewhere);
|
|
101
|
+
if (!stale.length) return '应用位置无需更新';
|
|
102
|
+
const old = stale.map(file => dirname(dirname(dirname(programOf(file))))).find(path => path.endsWith('.app'));
|
|
103
|
+
const running = job(folder).pid > 0;
|
|
104
|
+
await serviceCommand('stop', folder); // 先等当前任务回传
|
|
105
|
+
if (elsewhere(panelFile(folder))) writePanel(folder);
|
|
106
|
+
let bootKept = false;
|
|
107
|
+
if (elsewhere(bootFile(folder))) try {
|
|
108
|
+
const name = bootLabel(folder), target = bootFile(folder);
|
|
109
|
+
const data = Buffer.from(bootPlist(folder, macResources, userInfo().username, homedir())).toString('base64');
|
|
110
|
+
admin('set -eu; t=$(/usr/bin/mktemp /Library/LaunchDaemons/.' + name + '.XXXXXX); '
|
|
111
|
+
+ 'trap \'/bin/rm -f "$t"\' EXIT; /bin/echo ' + data + ' | /usr/bin/base64 -D > "$t"; /usr/bin/plutil -lint "$t" >/dev/null; '
|
|
112
|
+
+ '/usr/sbin/chown root:wheel "$t"; /bin/chmod 644 "$t"; /bin/mv -f "$t" ' + target + '; '
|
|
113
|
+
// 与“开机启动”开关一致:只改文件,下次开机生效;当前已载入的才重新载入(2026-11-23 本机实测时它没载入)。
|
|
114
|
+
+ 'if /bin/launchctl print system/' + name + ' >/dev/null 2>&1; then /bin/launchctl bootout system/' + name + '; /bin/launchctl bootstrap system ' + target + '; fi');
|
|
115
|
+
} catch { bootKept = true; } // 没给管理员授权:其余照常迁移,旧应用留着(开机配置还指着它)
|
|
116
|
+
const worker = join(folder,'mac-worker.plist');
|
|
117
|
+
if (elsewhere(worker)) {
|
|
118
|
+
if (lookup(service(folder)).loaded) launch('bootout', service(folder));
|
|
119
|
+
rmSync(worker, { force: true });
|
|
120
|
+
}
|
|
121
|
+
if (running && !job(folder).pid) await serviceCommand('start', folder); // 原来在跑的照原样拉起
|
|
122
|
+
if (old) relaunchers(old);
|
|
123
|
+
let note = '已改用当前应用:' + basename(currentBundle());
|
|
124
|
+
if (bootKept) note += ';开机启动未更新(没有管理员授权),旧应用先保留,请在面板关掉再打开开机启动后再删旧应用';
|
|
125
|
+
else if (old && old !== currentBundle() && existsSync(old)) {
|
|
126
|
+
try { renameSync(old, join(homedir(), '.Trash', basename(old) + '.' + Date.now())); note += ';旧应用已移到废纸篓'; }
|
|
127
|
+
catch { note += ';旧应用 ' + basename(old) + ' 请手动删除'; }
|
|
128
|
+
}
|
|
129
|
+
return note;
|
|
68
130
|
}
|
|
69
131
|
|
|
70
132
|
function admin(command) {
|
|
@@ -77,7 +139,7 @@ export function desktopStatus(folder) {
|
|
|
77
139
|
const { pid } = job(folder);
|
|
78
140
|
const saved = readSnapshot(folder, 'mac-worker.json');
|
|
79
141
|
const fresh = pid > 0 && saved?.pid === pid && Date.now() - saved.updated < 95000;
|
|
80
|
-
return { running: Boolean(pid), connected: Boolean(fresh && saved.connected), pid, terminalEnabled: terminalEnabled(folder), compactAt: compactAt(folder),
|
|
142
|
+
return { running: Boolean(pid), connected: Boolean(fresh && saved.connected), pid, terminalEnabled: terminalEnabled(folder), compactAt: compactAt(folder), moved: moved(folder),
|
|
81
143
|
report: saved || {}, task: fresh ? saved.task : null };
|
|
82
144
|
}
|
|
83
145
|
|
package/bin/run.js
CHANGED
|
@@ -238,7 +238,7 @@ export async function runDevice(device, configDir, version, signal, { reporter,
|
|
|
238
238
|
}
|
|
239
239
|
}
|
|
240
240
|
if (signal.aborted) break;
|
|
241
|
-
// steer(协议第 16 节):桌面版的 Claude、Codex、Agy
|
|
241
|
+
// steer(协议第 16 节):桌面版的 Claude、Codex、Agy 对话,以及 Claude、Codex 的任务运行(2026-11-23)支持运行中补充;纯 npm 不支持。
|
|
242
242
|
// Cursor 实测只能取消当前一轮再发新的,不算补充(2026-11-23)。
|
|
243
243
|
const steer = { claude_code: taskDelivery(), codex: taskDelivery(), cursor: false, antigravity: taskDelivery() };
|
|
244
244
|
const hello = { type: 'hello', client_version: version, tools: [], terminal, task_delivery: taskDelivery(), doc_read: taskDelivery(), steer, ...metadata };
|
package/bin/tasks.js
CHANGED
|
@@ -86,26 +86,64 @@ function desktopConversation(resources, content, prompt, signal, credential, too
|
|
|
86
86
|
const TASK_KINDS = ['execute', 'review', 'deploy', 'clarify'];
|
|
87
87
|
|
|
88
88
|
// Mac and Ubuntu desktop installs: Git task-branch runs go to the packaged Python runner.
|
|
89
|
+
// 任务运行(执行、审核、部署、答疑):首行 JSON 是运行内容;之后 stdin 保持打开,任务对话里发给正在干活的人员的话
|
|
90
|
+
// 按行写入(运行中补充,2026-11-23),子进程从 fd 3 逐行回执,stdout 只放最终结果。
|
|
89
91
|
function desktopTask(resources, content, signal, options) {
|
|
90
92
|
const runner = fileURLToPath(new URL('../runtime/task_run.py', import.meta.url));
|
|
91
93
|
const seconds = content.timeout_seconds;
|
|
92
94
|
const timeout = Number.isSafeInteger(seconds) && seconds > 0 ? Math.min(seconds, 3600) : 3600;
|
|
93
95
|
const input = { content, timeout, credential: options.credential, worktrees: join(options.configDir, 'worktrees') };
|
|
96
|
+
const onSteer = options.onSteer;
|
|
94
97
|
return new Promise(resolveResult => {
|
|
98
|
+
const child = spawn(join(resources, 'python/bin/python3'), ['-I', '-B', '-X', 'utf8', runner],
|
|
99
|
+
{ stdio: ['pipe', 'pipe', 'ignore', 'pipe'], windowsHide: true });
|
|
100
|
+
const waiting = new Map();
|
|
101
|
+
let stdout = '', size = 0, settled = false, acks = '';
|
|
102
|
+
const finish = result => {
|
|
103
|
+
if (settled) return;
|
|
104
|
+
settled = true;
|
|
105
|
+
clearTimeout(timer);
|
|
106
|
+
signal.removeEventListener('abort', cancel);
|
|
107
|
+
onSteer?.(null);
|
|
108
|
+
for (const done of waiting.values()) done('too_late');
|
|
109
|
+
waiting.clear();
|
|
110
|
+
resolveResult(result);
|
|
111
|
+
};
|
|
95
112
|
// Fetch, checkout and push get their own Git timeouts on top of the tool's.
|
|
96
|
-
const
|
|
97
|
-
{ timeout: (timeout + 600) * 1000, maxBuffer: 8 * 1024 * 1024 }, (error, stdout) => {
|
|
98
|
-
signal.removeEventListener('abort', cancel);
|
|
99
|
-
if (signal.aborted) return resolveResult({ status: 'cancelled', failure_code: 'cancelled' });
|
|
100
|
-
if (!error) {
|
|
101
|
-
try { return resolveResult(JSON.parse(stdout)); } catch {}
|
|
102
|
-
}
|
|
103
|
-
resolveResult({ status: 'failed', failure_code: 'tool_start_failed', failure_detail: '设备任务执行器异常,请检查客户端安装' });
|
|
104
|
-
});
|
|
113
|
+
const timer = setTimeout(() => child.kill('SIGTERM'), (timeout + 600) * 1000);
|
|
105
114
|
const cancel = () => child.kill('SIGTERM');
|
|
115
|
+
child.stdout.on('data', chunk => {
|
|
116
|
+
size += chunk.length;
|
|
117
|
+
if (size > 8 * 1024 * 1024) { child.kill('SIGTERM'); return; }
|
|
118
|
+
stdout += chunk;
|
|
119
|
+
});
|
|
120
|
+
child.stdio[3].on('data', chunk => {
|
|
121
|
+
acks += chunk;
|
|
122
|
+
let line;
|
|
123
|
+
while ((line = acks.indexOf('\n')) >= 0) {
|
|
124
|
+
const raw = acks.slice(0, line); acks = acks.slice(line + 1);
|
|
125
|
+
try {
|
|
126
|
+
const ack = JSON.parse(raw);
|
|
127
|
+
waiting.get(ack.message_id)?.(ack.status);
|
|
128
|
+
waiting.delete(ack.message_id);
|
|
129
|
+
} catch {}
|
|
130
|
+
}
|
|
131
|
+
});
|
|
132
|
+
child.on('error', () => finish({ status: 'failed', failure_code: 'tool_start_failed', failure_detail: '设备任务执行器异常,请检查客户端安装' }));
|
|
133
|
+
child.on('close', () => {
|
|
134
|
+
if (signal.aborted) return finish({ status: 'cancelled', failure_code: 'cancelled' });
|
|
135
|
+
try { return finish(JSON.parse(stdout)); } catch {}
|
|
136
|
+
finish({ status: 'failed', failure_code: 'tool_start_failed', failure_detail: '设备任务执行器异常,请检查客户端安装' });
|
|
137
|
+
});
|
|
106
138
|
signal.addEventListener('abort', cancel, { once: true });
|
|
107
139
|
child.stdin.on('error', () => {});
|
|
108
|
-
child.stdin.
|
|
140
|
+
child.stdin.write(JSON.stringify(input) + '\n');
|
|
141
|
+
onSteer?.((messageId, text) => new Promise(done => {
|
|
142
|
+
if (settled || !child.stdin.writable) return done('too_late');
|
|
143
|
+
const timeoutAck = setTimeout(() => { waiting.delete(messageId); done('failed'); }, 9000);
|
|
144
|
+
waiting.set(messageId, status => { clearTimeout(timeoutAck); done(status); });
|
|
145
|
+
child.stdin.write(JSON.stringify({ type: 'steer', message_id: messageId, content: text }) + '\n');
|
|
146
|
+
}));
|
|
109
147
|
if (signal.aborted) cancel();
|
|
110
148
|
});
|
|
111
149
|
}
|
|
@@ -164,7 +202,7 @@ export async function execute(content, signal, workCredential, { agentCredential
|
|
|
164
202
|
if (signal.aborted) return { status: 'cancelled', failure_code: 'cancelled' };
|
|
165
203
|
return { status: 'failed', failure_code: 'mcp_credential', failure_detail: '无法取得操作入口凭据,请检查设备认证及平台状态' };
|
|
166
204
|
}
|
|
167
|
-
return desktopTask(resources, content, signal, { credential, configDir });
|
|
205
|
+
return desktopTask(resources, content, signal, { credential, configDir, onSteer });
|
|
168
206
|
}
|
|
169
207
|
let prompt = content.prompt;
|
|
170
208
|
const task = content.run_kind === 'execute' && content.task;
|
package/package.json
CHANGED
package/runtime/task_run.py
CHANGED
|
@@ -66,6 +66,8 @@ def run(request, cancelled):
|
|
|
66
66
|
return failed("unsupported_task", "此工具尚未接入独立客户端的任务运行")
|
|
67
67
|
if not shutil.which(adapter.executable):
|
|
68
68
|
return failed("tool_missing", "本机未找到 " + adapter.executable_name)
|
|
69
|
+
if request.get("_on_adapter"):
|
|
70
|
+
request["_on_adapter"](adapter) # 运行中补充:任务对话里给正在干活的人员发的话送进这一轮(2026-11-23)
|
|
69
71
|
resume = content.get("resume_session_ref")
|
|
70
72
|
if resume is not None:
|
|
71
73
|
try:
|
|
@@ -115,7 +117,21 @@ def run(request, cancelled):
|
|
|
115
117
|
return body
|
|
116
118
|
|
|
117
119
|
|
|
118
|
-
|
|
120
|
+
def main():
|
|
119
121
|
cancelled = threading.Event()
|
|
120
122
|
signal.signal(signal.SIGTERM, lambda *_: cancelled.set())
|
|
121
|
-
|
|
123
|
+
# 首行是运行内容;之后 stdin 保持打开,每行一条补充,回执写 fd 3(与对话运行同一协议,客户端协议第 16 节)。
|
|
124
|
+
request = json.loads(sys.stdin.readline())
|
|
125
|
+
try:
|
|
126
|
+
acks = os.fdopen(3, "w")
|
|
127
|
+
except OSError:
|
|
128
|
+
acks = None
|
|
129
|
+
if acks is not None:
|
|
130
|
+
from runtime.desktop_chat import serve_steers
|
|
131
|
+
request["_on_adapter"] = lambda adapter: threading.Thread(
|
|
132
|
+
target=serve_steers, args=(adapter, acks), daemon=True).start()
|
|
133
|
+
print(json.dumps(run(request, cancelled), ensure_ascii=False))
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
if __name__ == "__main__":
|
|
137
|
+
main()
|