@ftai/ftai-plugin-ft-bot 0.0.0-stage → 0.4.0
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 +99 -2
- package/lib/chat-host.d.ts +60 -0
- package/lib/chat-host.js +2 -0
- package/lib/chat-host.js.map +1 -0
- package/lib/chats.d.ts +36 -0
- package/lib/chats.js +163 -0
- package/lib/chats.js.map +1 -0
- package/lib/client.js +11 -0
- package/lib/client.js.map +1 -0
- package/lib/client.packages.json +6 -0
- package/lib/controller.d.ts +32 -0
- package/lib/controller.js +241 -0
- package/lib/controller.js.map +1 -0
- package/lib/credential-host.d.ts +5 -0
- package/lib/credential-host.js +2 -0
- package/lib/credential-host.js.map +1 -0
- package/lib/download.d.ts +14 -0
- package/lib/download.js +113 -0
- package/lib/download.js.map +1 -0
- package/lib/index.d.ts +23 -0
- package/lib/index.js +97 -0
- package/lib/index.js.map +1 -0
- package/lib/remote.d.ts +19 -0
- package/lib/remote.js +57 -0
- package/lib/runner.d.ts +15 -0
- package/lib/runner.js +143 -0
- package/lib/runner.js.map +1 -0
- package/lib/types.d.ts +27 -0
- package/lib/types.js +2 -0
- package/lib/types.js.map +1 -0
- package/locale/en.json +1 -0
- package/locale/zh-CN.json +1 -0
- package/package.json +58 -3
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
import { homedir, hostname } from 'node:os';
|
|
2
|
+
import { isAbsolute, join } from 'node:path';
|
|
3
|
+
import { chmod, mkdir, readFile, rename, writeFile } from 'node:fs/promises';
|
|
4
|
+
import { randomUUID } from 'node:crypto';
|
|
5
|
+
import { downloadRunner, gateway } from "./download.js";
|
|
6
|
+
import { computerStatus, launchRunner } from "./runner.js";
|
|
7
|
+
import { DEFAULT_GATEWAY } from "./types.js";
|
|
8
|
+
export function stateDirectory() {
|
|
9
|
+
if (process.env.FT_BOT_PLUGIN_HOME)
|
|
10
|
+
return process.env.FT_BOT_PLUGIN_HOME;
|
|
11
|
+
if (process.platform === 'win32') {
|
|
12
|
+
if (!process.env.LOCALAPPDATA)
|
|
13
|
+
throw new Error('LOCALAPPDATA is not set.');
|
|
14
|
+
return join(process.env.LOCALAPPDATA, 'ft-bot-desktop-plugin');
|
|
15
|
+
}
|
|
16
|
+
return join(homedir(), '.local', 'share', 'ft-bot-desktop-plugin');
|
|
17
|
+
}
|
|
18
|
+
export class Controller {
|
|
19
|
+
directory;
|
|
20
|
+
override;
|
|
21
|
+
chats;
|
|
22
|
+
config = { server: '', executable: null, enabled: false };
|
|
23
|
+
snapshot = {
|
|
24
|
+
server: DEFAULT_GATEWAY, installed: false, enabled: false, busy: true, connection: 'stopped', computer: null, error: null,
|
|
25
|
+
};
|
|
26
|
+
abort = new AbortController();
|
|
27
|
+
children = new Set();
|
|
28
|
+
running;
|
|
29
|
+
ready;
|
|
30
|
+
constructor(directory, override = process.env.FT_BOT_RUNNER_BINARY, chats) {
|
|
31
|
+
this.directory = directory;
|
|
32
|
+
this.override = override;
|
|
33
|
+
this.chats = chats;
|
|
34
|
+
this.ready = this.load().catch(error => {
|
|
35
|
+
this.snapshot.error = String(error.message);
|
|
36
|
+
if (this.config.enabled)
|
|
37
|
+
this.snapshot.connection = 'error';
|
|
38
|
+
}).finally(() => { this.snapshot.busy = false; });
|
|
39
|
+
}
|
|
40
|
+
getStatus() { return { ...this.snapshot }; }
|
|
41
|
+
alive() {
|
|
42
|
+
if (this.abort.signal.aborted)
|
|
43
|
+
throw new Error('The plugin has stopped.');
|
|
44
|
+
}
|
|
45
|
+
executable() {
|
|
46
|
+
const executable = this.override || this.config.executable;
|
|
47
|
+
if (!executable || !isAbsolute(executable))
|
|
48
|
+
throw new Error('Download the runner first.');
|
|
49
|
+
return executable;
|
|
50
|
+
}
|
|
51
|
+
async load() {
|
|
52
|
+
if (!isAbsolute(this.directory))
|
|
53
|
+
throw new Error('Plugin state directory must be absolute.');
|
|
54
|
+
await mkdir(this.directory, { recursive: true, mode: 0o700 });
|
|
55
|
+
if (process.platform !== 'win32')
|
|
56
|
+
await chmod(this.directory, 0o700);
|
|
57
|
+
try {
|
|
58
|
+
const config = JSON.parse(await readFile(join(this.directory, 'config.json'), 'utf8'));
|
|
59
|
+
if (typeof config.enabled !== 'boolean' || typeof config.server !== 'string'
|
|
60
|
+
|| !(config.executable === null || (typeof config.executable === 'string' && isAbsolute(config.executable)))) {
|
|
61
|
+
throw new Error('Invalid plugin configuration.');
|
|
62
|
+
}
|
|
63
|
+
this.config = { server: config.server ? gateway(config.server) : '', executable: config.executable, enabled: config.enabled };
|
|
64
|
+
}
|
|
65
|
+
catch (error) {
|
|
66
|
+
if (error.code !== 'ENOENT')
|
|
67
|
+
throw error;
|
|
68
|
+
}
|
|
69
|
+
this.alive();
|
|
70
|
+
this.snapshot.server = this.config.server || DEFAULT_GATEWAY;
|
|
71
|
+
this.snapshot.enabled = this.config.enabled;
|
|
72
|
+
this.snapshot.installed = Boolean(this.override || this.config.executable);
|
|
73
|
+
if (this.snapshot.installed) {
|
|
74
|
+
await this.inspect();
|
|
75
|
+
if (this.config.enabled)
|
|
76
|
+
this.startRunner();
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
async save(config) {
|
|
80
|
+
this.alive();
|
|
81
|
+
const temporary = join(this.directory, `.config-${randomUUID()}`);
|
|
82
|
+
await writeFile(temporary, JSON.stringify(config), { mode: 0o600, flag: 'wx' });
|
|
83
|
+
await rename(temporary, join(this.directory, 'config.json'));
|
|
84
|
+
this.config = config;
|
|
85
|
+
this.snapshot.server = config.server || DEFAULT_GATEWAY;
|
|
86
|
+
this.snapshot.enabled = config.enabled;
|
|
87
|
+
this.snapshot.installed = Boolean(this.override || config.executable);
|
|
88
|
+
}
|
|
89
|
+
async request(request) {
|
|
90
|
+
this.alive();
|
|
91
|
+
const runner = launchRunner(this.executable(), join(this.directory, 'runner'), request);
|
|
92
|
+
this.children.add(runner);
|
|
93
|
+
let timedOut = false;
|
|
94
|
+
const timer = setTimeout(() => { timedOut = true; void runner.stop(); }, 30_000);
|
|
95
|
+
try {
|
|
96
|
+
const result = await runner.done;
|
|
97
|
+
this.alive();
|
|
98
|
+
if (timedOut)
|
|
99
|
+
throw new Error('Runner request timed out.');
|
|
100
|
+
return computerStatus(result);
|
|
101
|
+
}
|
|
102
|
+
finally {
|
|
103
|
+
clearTimeout(timer);
|
|
104
|
+
this.children.delete(runner);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
async inspect() {
|
|
108
|
+
this.snapshot.computer = await this.request({ type: 'status' });
|
|
109
|
+
const server = this.snapshot.computer.server;
|
|
110
|
+
if (this.snapshot.computer.device_id && server && this.config.server && gateway(server) !== this.config.server) {
|
|
111
|
+
throw new Error('This computer is registered with another gateway.');
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
startRunner() {
|
|
115
|
+
this.alive();
|
|
116
|
+
if (this.running)
|
|
117
|
+
return;
|
|
118
|
+
if (!this.snapshot.computer?.device_id)
|
|
119
|
+
throw new Error('Choose Connect with FtAi first.');
|
|
120
|
+
this.snapshot.connection = 'connecting';
|
|
121
|
+
const runner = launchRunner(this.executable(), join(this.directory, 'runner'), { type: 'run' }, status => {
|
|
122
|
+
if (this.running === runner)
|
|
123
|
+
this.snapshot.connection = status;
|
|
124
|
+
}, this.chats);
|
|
125
|
+
this.running = runner;
|
|
126
|
+
this.children.add(runner);
|
|
127
|
+
void runner.done.then(() => {
|
|
128
|
+
if (this.running === runner)
|
|
129
|
+
this.snapshot.connection = 'stopped';
|
|
130
|
+
}, error => {
|
|
131
|
+
if (this.running === runner) {
|
|
132
|
+
this.snapshot.connection = 'error';
|
|
133
|
+
this.snapshot.error = error.message;
|
|
134
|
+
}
|
|
135
|
+
}).finally(() => {
|
|
136
|
+
this.children.delete(runner);
|
|
137
|
+
if (this.running === runner)
|
|
138
|
+
this.running = undefined;
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
async stopRunner() {
|
|
142
|
+
const runner = this.running;
|
|
143
|
+
this.running = undefined;
|
|
144
|
+
if (runner)
|
|
145
|
+
await runner.stop();
|
|
146
|
+
this.snapshot.connection = 'stopped';
|
|
147
|
+
}
|
|
148
|
+
async operate(work) {
|
|
149
|
+
await this.ready;
|
|
150
|
+
this.alive();
|
|
151
|
+
if (this.snapshot.busy)
|
|
152
|
+
throw new Error('Another operation is still running.');
|
|
153
|
+
this.snapshot.busy = true;
|
|
154
|
+
this.snapshot.error = null;
|
|
155
|
+
try {
|
|
156
|
+
await work();
|
|
157
|
+
}
|
|
158
|
+
catch (error) {
|
|
159
|
+
this.snapshot.error = error.message;
|
|
160
|
+
throw error;
|
|
161
|
+
}
|
|
162
|
+
finally {
|
|
163
|
+
this.snapshot.busy = false;
|
|
164
|
+
}
|
|
165
|
+
return this.getStatus();
|
|
166
|
+
}
|
|
167
|
+
async connectAccount(server, resolveToken) {
|
|
168
|
+
return this.operate(async () => {
|
|
169
|
+
server = gateway(server.trim() || DEFAULT_GATEWAY);
|
|
170
|
+
if (this.snapshot.computer?.device_id)
|
|
171
|
+
throw new Error('This computer is already registered.');
|
|
172
|
+
const token = await resolveToken();
|
|
173
|
+
this.alive();
|
|
174
|
+
if (!token)
|
|
175
|
+
throw new Error('Sign in to FtAi, allow Ft Bot to read FTAI_USER_TOKEN in credential permissions, then retry.');
|
|
176
|
+
if (!this.snapshot.installed)
|
|
177
|
+
await this.download(server);
|
|
178
|
+
const name = Array.from(hostname().replace(/\p{Cc}/gu, '').trim()).slice(0, 64).join('') || 'Computer';
|
|
179
|
+
this.snapshot.computer = await this.request({ type: 'enroll', server, token, name });
|
|
180
|
+
await this.save({ ...this.config, server, enabled: true });
|
|
181
|
+
this.startRunner();
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
async download(server) {
|
|
185
|
+
const executable = this.override || await downloadRunner(server, join(this.directory, 'bin'), AbortSignal.any([this.abort.signal, AbortSignal.timeout(180_000)]));
|
|
186
|
+
this.alive();
|
|
187
|
+
// Probe the stdio contract before selecting a release. Failed upgrades keep the old path.
|
|
188
|
+
const previous = this.config;
|
|
189
|
+
this.config = { ...previous, executable };
|
|
190
|
+
try {
|
|
191
|
+
await this.inspect();
|
|
192
|
+
}
|
|
193
|
+
catch (error) {
|
|
194
|
+
this.config = previous;
|
|
195
|
+
throw error;
|
|
196
|
+
}
|
|
197
|
+
await this.save({ ...this.config, server });
|
|
198
|
+
}
|
|
199
|
+
async updateRunner() {
|
|
200
|
+
return this.operate(async () => {
|
|
201
|
+
if (!this.config.server)
|
|
202
|
+
throw new Error('Choose Connect with FtAi first.');
|
|
203
|
+
await this.stopRunner();
|
|
204
|
+
try {
|
|
205
|
+
await this.download(this.config.server);
|
|
206
|
+
}
|
|
207
|
+
finally {
|
|
208
|
+
if (this.config.enabled)
|
|
209
|
+
this.startRunner();
|
|
210
|
+
}
|
|
211
|
+
});
|
|
212
|
+
}
|
|
213
|
+
async setEnabled(enabled) {
|
|
214
|
+
return this.operate(async () => {
|
|
215
|
+
if (typeof enabled !== 'boolean')
|
|
216
|
+
throw new Error('Invalid connection setting.');
|
|
217
|
+
if (enabled) {
|
|
218
|
+
await this.inspect();
|
|
219
|
+
if (!this.snapshot.computer?.device_id)
|
|
220
|
+
throw new Error('Choose Connect with FtAi first.');
|
|
221
|
+
}
|
|
222
|
+
await this.save({ ...this.config, enabled });
|
|
223
|
+
if (enabled)
|
|
224
|
+
this.startRunner();
|
|
225
|
+
else
|
|
226
|
+
await this.stopRunner();
|
|
227
|
+
});
|
|
228
|
+
}
|
|
229
|
+
async refresh() { return this.operate(() => this.inspect()); }
|
|
230
|
+
async requestPermissions() {
|
|
231
|
+
return this.operate(async () => {
|
|
232
|
+
this.snapshot.computer = await this.request({ type: 'permissions' });
|
|
233
|
+
});
|
|
234
|
+
}
|
|
235
|
+
async dispose() {
|
|
236
|
+
this.abort.abort();
|
|
237
|
+
this.running = undefined;
|
|
238
|
+
await Promise.all([...this.children].map(runner => runner.stop()));
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
//# sourceMapping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,CAAC,OAAO,EAAE,CAAA;gBACpB,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,QAAQ,EAAE,SAAS;oBAAE,MAAM,IAAI,KAAK,CAAC,iCAAiC,CAAC,CAAA;YAC5F,CAAC;YACD,MAAM,IAAI,CAAC,IAAI,CAAC,EAAE,GAAG,IAAI,CAAC,MAAM,EAAE,OAAO,EAAE,CAAC,CAAA;YAC5C,IAAI,OAAO;gBAAE,IAAI,CAAC,WAAW,EAAE,CAAA;;gBAC1B,MAAM,IAAI,CAAC,UAAU,EAAE,CAAA;QAC9B,CAAC,CAAC,CAAA;IACJ,CAAC;IAED,KAAK,CAAC,OAAO,KAAK,OAAO,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC,CAAA,CAAC,CAAC;IAE7D,KAAK,CAAC,kBAAkB;QACtB,OAAO,IAAI,CAAC,OAAO,CAAC,KAAK,IAAI,EAAE;YAC7B,IAAI,CAAC,QAAQ,CAAC,QAAQ,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,EAAE,IAAI,EAAE,aAAa,EAAE,CAAC,CAAA;QACtE,CAAC,CAAC,CAAA;IACJ,CAAC;IAED,KAAK,CAAC,OAAO;QACX,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,CAAA;QAClB,IAAI,CAAC,OAAO,GAAG,SAAS,CAAA;QACxB,MAAM,OAAO,CAAC,GAAG,CAAC,CAAC,GAAG,IAAI,CAAC,QAAQ,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC,CAAC,CAAA;IACpE,CAAC;CACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"credential-host.js","sourceRoot":"","sources":["../src/credential-host.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export declare const PROTOCOL = 7;
|
|
2
|
+
export declare function gateway(value: string): string;
|
|
3
|
+
export declare function artifactFor(manifest: unknown, platform?: NodeJS.Platform, arch?: NodeJS.Architecture): {
|
|
4
|
+
revision: string;
|
|
5
|
+
revisionFile: string;
|
|
6
|
+
target: string;
|
|
7
|
+
filename: string;
|
|
8
|
+
tools: string;
|
|
9
|
+
runner: string;
|
|
10
|
+
browser: string;
|
|
11
|
+
sha256: string;
|
|
12
|
+
bytes: number;
|
|
13
|
+
};
|
|
14
|
+
export declare function downloadRunner(server: string, directory: string, signal: AbortSignal): Promise<string>;
|
package/lib/download.js
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
import { mkdir, mkdtemp, readFile, rename, rm, writeFile } from 'node:fs/promises';
|
|
3
|
+
import { join } from 'node:path';
|
|
4
|
+
import { unzipSync } from 'fflate';
|
|
5
|
+
export const PROTOCOL = 7;
|
|
6
|
+
const maxPackageBytes = 256 * 1024 * 1024;
|
|
7
|
+
const runnerVersionPattern = /^\d+\.\d+\.\d+(-[A-Za-z0-9-]+(\.[A-Za-z0-9-]+)*)?(\+[A-Za-z0-9-]+(\.[A-Za-z0-9-]+)*)?$/;
|
|
8
|
+
export function gateway(value) {
|
|
9
|
+
const url = new URL(value.trim());
|
|
10
|
+
if ((url.protocol !== 'https:' && !(url.protocol === 'http:' && ['localhost', '127.0.0.1', '[::1]'].includes(url.hostname)))
|
|
11
|
+
|| url.username || url.password || url.search || url.hash) {
|
|
12
|
+
throw new Error('Use an HTTPS gateway URL without credentials, query or fragment (HTTP is allowed on loopback).');
|
|
13
|
+
}
|
|
14
|
+
return url.href.replace(/\/+$/, '');
|
|
15
|
+
}
|
|
16
|
+
const targets = {
|
|
17
|
+
'darwin-arm64': 'aarch64-apple-darwin', 'darwin-x64': 'x86_64-apple-darwin',
|
|
18
|
+
'win32-arm64': 'aarch64-pc-windows-msvc', 'win32-x64': 'x86_64-pc-windows-msvc',
|
|
19
|
+
'linux-arm64': 'aarch64-unknown-linux-musl', 'linux-x64': 'x86_64-unknown-linux-musl',
|
|
20
|
+
};
|
|
21
|
+
export function artifactFor(manifest, platform = process.platform, arch = process.arch) {
|
|
22
|
+
const target = targets[`${platform}-${arch}`];
|
|
23
|
+
if (!target)
|
|
24
|
+
throw new Error(`Unsupported computer: ${platform}/${arch}`);
|
|
25
|
+
const data = manifest;
|
|
26
|
+
if (!data || typeof data.revision !== 'string' || !/^[a-f0-9]{40}$/.test(data.revision)
|
|
27
|
+
|| typeof data.runner_version !== 'string' || !runnerVersionPattern.test(data.runner_version)
|
|
28
|
+
|| data.protocol !== PROTOCOL || !Array.isArray(data.artifacts)) {
|
|
29
|
+
throw new Error(`The gateway must publish runner protocol ${PROTOCOL} packages.`);
|
|
30
|
+
}
|
|
31
|
+
const filename = `ft-bot-runner-${target}.zip`;
|
|
32
|
+
const matches = data.artifacts.filter((item) => item?.target === target);
|
|
33
|
+
const artifact = matches[0];
|
|
34
|
+
if (matches.length !== 1 || artifact.filename !== filename || typeof artifact.sha256 !== 'string'
|
|
35
|
+
|| !/^[a-f0-9]{64}$/.test(artifact.sha256) || !Number.isSafeInteger(artifact.bytes)
|
|
36
|
+
|| artifact.bytes <= 0 || artifact.bytes > maxPackageBytes) {
|
|
37
|
+
throw new Error('Invalid runner download metadata.');
|
|
38
|
+
}
|
|
39
|
+
const extension = platform === 'win32' ? '.exe' : '';
|
|
40
|
+
const separator = data.runner_version.includes('+') ? '.' : '+';
|
|
41
|
+
const bundleVersion = `${data.runner_version}${separator}${data.revision.slice(0, 8)}`;
|
|
42
|
+
const tools = `${bundleVersion}/ft-bot-tools`;
|
|
43
|
+
return { revision: data.revision, revisionFile: `${bundleVersion}/REVISION`, target, filename, tools, runner: `${bundleVersion}/ft-bot-runner${extension}`,
|
|
44
|
+
browser: `${tools}/agent-browser${extension}`, sha256: artifact.sha256, bytes: artifact.bytes };
|
|
45
|
+
}
|
|
46
|
+
async function fetchFile(url, signal) {
|
|
47
|
+
// Keep downloads on the selected HTTPS gateway; never follow a downgrade or redirect.
|
|
48
|
+
const response = await fetch(url, { signal, redirect: 'error' });
|
|
49
|
+
if (!response.ok || !response.body)
|
|
50
|
+
throw new Error(`Runner download failed (HTTP ${response.status}).`);
|
|
51
|
+
return response;
|
|
52
|
+
}
|
|
53
|
+
async function readLimited(response, limit) {
|
|
54
|
+
const chunks = [];
|
|
55
|
+
let size = 0;
|
|
56
|
+
for await (const chunk of response.body) {
|
|
57
|
+
size += chunk.length;
|
|
58
|
+
if (size > limit)
|
|
59
|
+
throw new Error('Runner download exceeds its declared size limit.');
|
|
60
|
+
chunks.push(chunk);
|
|
61
|
+
}
|
|
62
|
+
return Buffer.concat(chunks, size);
|
|
63
|
+
}
|
|
64
|
+
export async function downloadRunner(server, directory, signal) {
|
|
65
|
+
const base = `${gateway(server)}/runner/downloads`;
|
|
66
|
+
const manifest = await readLimited(await fetchFile(`${base}/latest.json`, signal), 64 * 1024);
|
|
67
|
+
const artifact = artifactFor(JSON.parse(manifest.toString('utf8')));
|
|
68
|
+
const url = `${base}/${artifact.revision}/${artifact.filename}`;
|
|
69
|
+
const zip = await readLimited(await fetchFile(url, signal), artifact.bytes);
|
|
70
|
+
if (zip.length !== artifact.bytes || createHash('sha256').update(zip).digest('hex') !== artifact.sha256) {
|
|
71
|
+
throw new Error('Runner checksum mismatch.');
|
|
72
|
+
}
|
|
73
|
+
const files = [artifact.revisionFile, `${artifact.tools}/LICENSE.txt`, artifact.browser, artifact.runner];
|
|
74
|
+
const missing = new Set(files);
|
|
75
|
+
let expanded = 0;
|
|
76
|
+
const contents = unzipSync(zip, { filter(entry) {
|
|
77
|
+
expanded += entry.originalSize;
|
|
78
|
+
if (!missing.delete(entry.name) || !entry.originalSize || expanded > maxPackageBytes) {
|
|
79
|
+
throw new Error('Invalid runner package contents.');
|
|
80
|
+
}
|
|
81
|
+
return true;
|
|
82
|
+
} });
|
|
83
|
+
if (missing.size)
|
|
84
|
+
throw new Error('Incomplete runner package.');
|
|
85
|
+
if (!Buffer.from(contents[artifact.revisionFile]).equals(Buffer.from(artifact.revision + '\n'))) {
|
|
86
|
+
throw new Error('Incorrect release revision in runner package.');
|
|
87
|
+
}
|
|
88
|
+
await mkdir(join(directory, artifact.tools), { recursive: true, mode: 0o700 });
|
|
89
|
+
const stage = await mkdtemp(join(directory, '.download-'));
|
|
90
|
+
try {
|
|
91
|
+
await mkdir(join(stage, artifact.tools), { recursive: true, mode: 0o700 });
|
|
92
|
+
for (const name of files) {
|
|
93
|
+
await writeFile(join(stage, name), contents[name], { mode: name === artifact.runner || name === artifact.browser ? 0o700 : 0o600 });
|
|
94
|
+
}
|
|
95
|
+
signal.throwIfAborted();
|
|
96
|
+
// Activate the runner last. Windows may lock an identical, running executable.
|
|
97
|
+
for (const name of files) {
|
|
98
|
+
const destination = join(directory, name);
|
|
99
|
+
try {
|
|
100
|
+
await rename(join(stage, name), destination);
|
|
101
|
+
}
|
|
102
|
+
catch (error) {
|
|
103
|
+
if (process.platform !== 'win32' || !(await readFile(destination)).equals(contents[name]))
|
|
104
|
+
throw error;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
return join(directory, artifact.runner);
|
|
108
|
+
}
|
|
109
|
+
finally {
|
|
110
|
+
await rm(stage, { recursive: true, force: true });
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
//# sourceMappingURL=download.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"download.js","sourceRoot":"","sources":["../src/download.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AACxC,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAA;AAClF,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAChC,OAAO,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAA;AAElC,MAAM,CAAC,MAAM,QAAQ,GAAG,CAAC,CAAA;AACzB,M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CAAC,IAAI,CAAE,EAAE,EAAE,IAAI,EAAE,IAAI,KAAK,QAAQ,CAAC,MAAM,IAAI,IAAI,KAAK,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,EAAE,CAAC,CAAA;QACtI,CAAC;QACD,MAAM,CAAC,cAAc,EAAE,CAAA;QACvB,+EAA+E;QAC/E,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;YACzB,MAAM,WAAW,GAAG,IAAI,CAAC,SAAS,EAAE,IAAI,CAAC,CAAA;YACzC,IAAI,CAAC;gBACH,MAAM,MAAM,CAAC,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,EAAE,WAAW,CAAC,CAAA;YAC9C,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,IAAI,OAAO,CAAC,QAAQ,KAAK,OAAO,IAAI,CAAC,CAAC,MAAM,QAAQ,CAAC,WAAW,CAAC,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAE,CAAC;oBAAE,MAAM,KAAK,CAAA;YACzG,CAAC;QACH,CAAC;QACD,OAAO,IAAI,CAAC,SAAS,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAA;IACzC,CAAC;YAAS,CAAC;QACT,MAAM,EAAE,CAAC,KAAK,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAA;IACnD,CAAC;AACH,CAAC"}
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { Context } from 'cordis';
|
|
2
|
+
import { TypertRemoteService } from '@ftai/plugin-sdk/host';
|
|
3
|
+
import type { PluginStatus } from './types.ts';
|
|
4
|
+
export type * from './types.ts';
|
|
5
|
+
declare module 'cordis' {
|
|
6
|
+
interface Context {
|
|
7
|
+
ftBot: FtBot;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
export declare class FtBot extends TypertRemoteService {
|
|
11
|
+
static inject: string[];
|
|
12
|
+
private controller;
|
|
13
|
+
private readonly credentials;
|
|
14
|
+
constructor(ctx: Context);
|
|
15
|
+
private perform;
|
|
16
|
+
status(): PluginStatus;
|
|
17
|
+
connectAccount(server: string): Promise<PluginStatus>;
|
|
18
|
+
setEnabled(enabled: boolean): Promise<PluginStatus>;
|
|
19
|
+
updateRunner(): Promise<PluginStatus>;
|
|
20
|
+
refresh(): Promise<PluginStatus>;
|
|
21
|
+
requestPermissions(): Promise<PluginStatus>;
|
|
22
|
+
}
|
|
23
|
+
export default FtBot;
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) {
|
|
2
|
+
var useValue = arguments.length > 2;
|
|
3
|
+
for (var i = 0; i < initializers.length; i++) {
|
|
4
|
+
value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
|
|
5
|
+
}
|
|
6
|
+
return useValue ? value : void 0;
|
|
7
|
+
};
|
|
8
|
+
var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
|
|
9
|
+
function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
|
|
10
|
+
var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
|
|
11
|
+
var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
|
|
12
|
+
var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
|
|
13
|
+
var _, done = false;
|
|
14
|
+
for (var i = decorators.length - 1; i >= 0; i--) {
|
|
15
|
+
var context = {};
|
|
16
|
+
for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
|
|
17
|
+
for (var p in contextIn.access) context.access[p] = contextIn.access[p];
|
|
18
|
+
context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); };
|
|
19
|
+
var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
|
|
20
|
+
if (kind === "accessor") {
|
|
21
|
+
if (result === void 0) continue;
|
|
22
|
+
if (result === null || typeof result !== "object") throw new TypeError("Object expected");
|
|
23
|
+
if (_ = accept(result.get)) descriptor.get = _;
|
|
24
|
+
if (_ = accept(result.set)) descriptor.set = _;
|
|
25
|
+
if (_ = accept(result.init)) initializers.unshift(_);
|
|
26
|
+
}
|
|
27
|
+
else if (_ = accept(result)) {
|
|
28
|
+
if (kind === "field") initializers.unshift(_);
|
|
29
|
+
else descriptor[key] = _;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
if (target) Object.defineProperty(target, contextIn.name, descriptor);
|
|
33
|
+
done = true;
|
|
34
|
+
};
|
|
35
|
+
import { Remote, RemoteError, TypertRemoteService } from '@ftai/plugin-sdk/host';
|
|
36
|
+
import { Controller, stateDirectory } from "./controller.js";
|
|
37
|
+
import { Chats } from "./chats.js";
|
|
38
|
+
let FtBot = (() => {
|
|
39
|
+
let _classSuper = TypertRemoteService;
|
|
40
|
+
let _instanceExtraInitializers = [];
|
|
41
|
+
let _status_decorators;
|
|
42
|
+
let _connectAccount_decorators;
|
|
43
|
+
let _setEnabled_decorators;
|
|
44
|
+
let _updateRunner_decorators;
|
|
45
|
+
let _refresh_decorators;
|
|
46
|
+
let _requestPermissions_decorators;
|
|
47
|
+
return class FtBot extends _classSuper {
|
|
48
|
+
static {
|
|
49
|
+
const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
|
|
50
|
+
_status_decorators = [Remote];
|
|
51
|
+
_connectAccount_decorators = [Remote];
|
|
52
|
+
_setEnabled_decorators = [Remote];
|
|
53
|
+
_updateRunner_decorators = [Remote];
|
|
54
|
+
_refresh_decorators = [Remote];
|
|
55
|
+
_requestPermissions_decorators = [Remote];
|
|
56
|
+
__esDecorate(this, null, _status_decorators, { kind: "method", name: "status", static: false, private: false, access: { has: obj => "status" in obj, get: obj => obj.status }, metadata: _metadata }, null, _instanceExtraInitializers);
|
|
57
|
+
__esDecorate(this, null, _connectAccount_decorators, { kind: "method", name: "connectAccount", static: false, private: false, access: { has: obj => "connectAccount" in obj, get: obj => obj.connectAccount }, metadata: _metadata }, null, _instanceExtraInitializers);
|
|
58
|
+
__esDecorate(this, null, _setEnabled_decorators, { kind: "method", name: "setEnabled", static: false, private: false, access: { has: obj => "setEnabled" in obj, get: obj => obj.setEnabled }, metadata: _metadata }, null, _instanceExtraInitializers);
|
|
59
|
+
__esDecorate(this, null, _updateRunner_decorators, { kind: "method", name: "updateRunner", static: false, private: false, access: { has: obj => "updateRunner" in obj, get: obj => obj.updateRunner }, metadata: _metadata }, null, _instanceExtraInitializers);
|
|
60
|
+
__esDecorate(this, null, _refresh_decorators, { kind: "method", name: "refresh", static: false, private: false, access: { has: obj => "refresh" in obj, get: obj => obj.refresh }, metadata: _metadata }, null, _instanceExtraInitializers);
|
|
61
|
+
__esDecorate(this, null, _requestPermissions_decorators, { kind: "method", name: "requestPermissions", static: false, private: false, access: { has: obj => "requestPermissions" in obj, get: obj => obj.requestPermissions }, metadata: _metadata }, null, _instanceExtraInitializers);
|
|
62
|
+
if (_metadata) Object.defineProperty(this, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
|
|
63
|
+
}
|
|
64
|
+
static inject = ['agents', 'credentials'];
|
|
65
|
+
controller = __runInitializers(this, _instanceExtraInitializers);
|
|
66
|
+
credentials;
|
|
67
|
+
constructor(ctx) {
|
|
68
|
+
super(ctx, 'ftBot');
|
|
69
|
+
this.credentials = ctx.credentials;
|
|
70
|
+
ctx.effect(() => {
|
|
71
|
+
const chats = new Chats(ctx.agents);
|
|
72
|
+
this.controller = new Controller(stateDirectory(), undefined, chats);
|
|
73
|
+
return () => this.controller.dispose();
|
|
74
|
+
}, 'ft-bot: runner lifetime');
|
|
75
|
+
}
|
|
76
|
+
async perform(work) {
|
|
77
|
+
try {
|
|
78
|
+
return await work();
|
|
79
|
+
}
|
|
80
|
+
catch (error) {
|
|
81
|
+
const reason = error.message;
|
|
82
|
+
throw new RemoteError('ft-bot/operation-failed', reason, { reason });
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
status() { return this.controller.getStatus(); }
|
|
86
|
+
connectAccount(server) {
|
|
87
|
+
return this.perform(() => this.controller.connectAccount(server, async () => (await this.credentials.resolve('FTAI_USER_TOKEN'))?.value));
|
|
88
|
+
}
|
|
89
|
+
setEnabled(enabled) { return this.perform(() => this.controller.setEnabled(enabled)); }
|
|
90
|
+
updateRunner() { return this.perform(() => this.controller.updateRunner()); }
|
|
91
|
+
refresh() { return this.perform(() => this.controller.refresh()); }
|
|
92
|
+
requestPermissions() { return this.perform(() => this.controller.requestPermissions()); }
|
|
93
|
+
};
|
|
94
|
+
})();
|
|
95
|
+
export { FtBot };
|
|
96
|
+
export default FtBot;
|
|
97
|
+
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAA;AAChF,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAA;AAC5D,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAA;IAWrB,KAAK;sBAAS,mBAAmB;;;;;;;;iBAAjC,KAAM,SAAQ,WAAmB;;;kCAuB3C,MAAM;0CAGN,MAAM;sCAMN,MAAM;wCAGN,MAAM;mCAGN,MAAM;8CAGN,MAAM;YAjBP,qKAAA,MAAM,6DAAuD;YAG7D,6LAAA,cAAc,6DAGb;YAGD,iLAAA,UAAU,6DAA4G;YAGtH,uLAAA,YAAY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AAiB,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,CAAA;QAC5E,CAAC;QAGD,UAAU,CAAC,OAAgB,IAA2B,OAAO,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,UAAU,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,CAAA,CAAC,CAAC;QAGtH,YAAY,KAA4B,OAAO,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,UAAU,CAAC,YAAY,EAAE,CAAC,CAAA,CAAC,CAAC;QAGnG,OAAO,KAA4B,OAAO,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,UAAU,CAAC,OAAO,EAAE,CAAC,CAAA,CAAC,CAAC;QAGzF,kBAAkB,KAA4B,OAAO,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,UAAU,CAAC,kBAAkB,EAAE,CAAC,CAAA,CAAC,CAAC;;;SA1CpG,KAAK;AA6ClB,eAAe,KAAK,CAAA"}
|
package/lib/remote.d.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/* 由 @ftai/plugin-sdk 的 ftai-plugin-remote 生成,不要手改。 */
|
|
2
|
+
import type { RemoteResult, RemoteStream } from '@ftai/plugin-sdk/remote'
|
|
3
|
+
import type { FtBot } from './index.js'
|
|
4
|
+
|
|
5
|
+
/** 去掉最后一个 `signal: AbortSignal` 参数:宿主替插件传它,插件前端可另给自己的取消信号。 */
|
|
6
|
+
type Args<F> = F extends (...args: infer A) => unknown ? (A extends [...infer Head, AbortSignal] ? Head : A) : never
|
|
7
|
+
type Value<F> = F extends (...args: never[]) => infer R ? Awaited<R> : never
|
|
8
|
+
type Item<F> = F extends (...args: never[]) => infer R ? (R extends AsyncIterable<infer I> | Iterable<infer I> ? I : never) : never
|
|
9
|
+
type Call<F> = ((...args: Args<F>) => Promise<RemoteResult<Value<F>>>) & ((...args: [...Args<F>, AbortSignal | undefined]) => Promise<RemoteResult<Value<F>>>)
|
|
10
|
+
type Stream<F> = ((...args: Args<F>) => RemoteStream<Item<F>>) & ((...args: [...Args<F>, AbortSignal | undefined]) => RemoteStream<Item<F>>)
|
|
11
|
+
|
|
12
|
+
declare module '@ftai/plugin-sdk/remote' {
|
|
13
|
+
interface RemoteNamespaceMap {
|
|
14
|
+
'ftBot': { status: Call<FtBot['status']>; connectAccount: Call<FtBot['connectAccount']>; setEnabled: Call<FtBot['setEnabled']>; updateRunner: Call<FtBot['updateRunner']>; refresh: Call<FtBot['refresh']>; requestPermissions: Call<FtBot['requestPermissions']> }
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
declare const REMOTE: { readonly package: string; readonly namespaces: readonly { readonly namespace: string; readonly methods: readonly { readonly name: string; readonly stream: boolean; readonly params?: readonly { readonly name: string; readonly optional: boolean; readonly schema: unknown }[] }[] }[] }
|
|
19
|
+
export default REMOTE
|
package/lib/remote.js
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/* 由 @ftai/plugin-sdk 的 ftai-plugin-remote 生成,不要手改。 */
|
|
2
|
+
export default Object.freeze({
|
|
3
|
+
"package": "@ftai/ftai-plugin-ft-bot",
|
|
4
|
+
"namespaces": [
|
|
5
|
+
{
|
|
6
|
+
"namespace": "ftBot",
|
|
7
|
+
"methods": [
|
|
8
|
+
{
|
|
9
|
+
"name": "status",
|
|
10
|
+
"stream": false,
|
|
11
|
+
"params": []
|
|
12
|
+
},
|
|
13
|
+
{
|
|
14
|
+
"name": "connectAccount",
|
|
15
|
+
"stream": false,
|
|
16
|
+
"params": [
|
|
17
|
+
{
|
|
18
|
+
"name": "server",
|
|
19
|
+
"optional": false,
|
|
20
|
+
"schema": {
|
|
21
|
+
"type": "string"
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
]
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
"name": "setEnabled",
|
|
28
|
+
"stream": false,
|
|
29
|
+
"params": [
|
|
30
|
+
{
|
|
31
|
+
"name": "enabled",
|
|
32
|
+
"optional": false,
|
|
33
|
+
"schema": {
|
|
34
|
+
"type": "boolean"
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
]
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
"name": "updateRunner",
|
|
41
|
+
"stream": false,
|
|
42
|
+
"params": []
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
"name": "refresh",
|
|
46
|
+
"stream": false,
|
|
47
|
+
"params": []
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
"name": "requestPermissions",
|
|
51
|
+
"stream": false,
|
|
52
|
+
"params": []
|
|
53
|
+
}
|
|
54
|
+
]
|
|
55
|
+
}
|
|
56
|
+
]
|
|
57
|
+
})
|
package/lib/runner.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { ComputerStatus, Connection } from './types.ts';
|
|
2
|
+
import type { ChatPort } from './chats.ts';
|
|
3
|
+
export type RunnerRequest = {
|
|
4
|
+
type: 'status' | 'permissions' | 'run';
|
|
5
|
+
} | {
|
|
6
|
+
type: 'enroll';
|
|
7
|
+
server: string;
|
|
8
|
+
token: string;
|
|
9
|
+
name: string;
|
|
10
|
+
};
|
|
11
|
+
export declare function launchRunner(executable: string, state: string, request: RunnerRequest, onConnection?: (status: Connection) => void, chats?: ChatPort): {
|
|
12
|
+
done: Promise<unknown>;
|
|
13
|
+
stop(): Promise<void>;
|
|
14
|
+
};
|
|
15
|
+
export declare function computerStatus(value: unknown): ComputerStatus;
|