@reservoirai/rsvr-provider 0.0.0-stage → 0.1.1
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 +12 -2
- package/bin/rsvr-provider.js +145 -0
- package/package.json +25 -4
package/README.md
CHANGED
|
@@ -1,3 +1,13 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @reservoirai/rsvr-provider
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
The reservoir provider command line. It signs in, finds your model server,
|
|
4
|
+
and serves work for reservoir.
|
|
5
|
+
|
|
6
|
+
npx @reservoirai/rsvr-provider setup
|
|
7
|
+
|
|
8
|
+
This package holds only a small launcher. The program itself is in the one
|
|
9
|
+
platform package npm installs for your machine
|
|
10
|
+
(`@reservoirai/rsvr-provider-<os>-<cpu>`). If optional dependencies are turned
|
|
11
|
+
off, reinstall with `npm install -g @reservoirai/rsvr-provider --include=optional`.
|
|
12
|
+
|
|
13
|
+
Run `rsvr-provider --help` for the commands.
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
// The launcher of @reservoirai/rsvr-provider: it finds the one platform
|
|
5
|
+
// package npm installed for this machine, runs the program inside it with the
|
|
6
|
+
// terminal passed through, and returns the program's exit code unchanged
|
|
7
|
+
// (src/rsvr-provider/GUIDE.md §9: the launcher's own failure is 1).
|
|
8
|
+
//
|
|
9
|
+
// No dependencies, CommonJS, Node 18 or later. No install script anywhere in
|
|
10
|
+
// the package: where the platform package is missing (optional dependencies
|
|
11
|
+
// turned off, a platform with no build) this says which package it looked for
|
|
12
|
+
// and how to install without npm, and exits 1.
|
|
13
|
+
|
|
14
|
+
const childProcess = require('node:child_process');
|
|
15
|
+
const fs = require('node:fs');
|
|
16
|
+
const os = require('node:os');
|
|
17
|
+
const path = require('node:path');
|
|
18
|
+
const tty = require('node:tty');
|
|
19
|
+
|
|
20
|
+
const SCOPE = '@reservoirai';
|
|
21
|
+
const NAME = 'rsvr-provider';
|
|
22
|
+
|
|
23
|
+
// The platforms that have a build, as npm names them (`process.platform` and
|
|
24
|
+
// `process.arch`). The main package's optionalDependencies list exactly
|
|
25
|
+
// these, and the launcher's test says so.
|
|
26
|
+
const SUPPORTED = ['linux-x64', 'linux-arm64', 'darwin-arm64', 'darwin-x64', 'win32-x64'];
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
/** The platform package for a machine, or null where no build exists. */
|
|
30
|
+
function packageFor(platform, arch) {
|
|
31
|
+
const key = platform + '-' + arch;
|
|
32
|
+
return SUPPORTED.includes(key) ? SCOPE + '/' + NAME + '-' + key : null;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** The program's path inside the platform package whose package.json is at `packageJson`. */
|
|
36
|
+
function binaryPath(packageJson, platform) {
|
|
37
|
+
return path.join(path.dirname(packageJson), 'bin', platform === 'win32' ? NAME + '.exe' : NAME);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** What the launcher prints to stderr when there is no program to run. */
|
|
41
|
+
function missingMessage(platform, arch) {
|
|
42
|
+
const pkg = packageFor(platform, arch);
|
|
43
|
+
const lines = [];
|
|
44
|
+
if (pkg === null) {
|
|
45
|
+
lines.push(NAME + ': there is no build for ' + platform + ' on ' + arch + '.');
|
|
46
|
+
} else {
|
|
47
|
+
lines.push(NAME + ': the package ' + pkg + ' is not installed, and it holds the program for this machine.');
|
|
48
|
+
lines.push('npm installs it as an optional dependency, so it is missing when optional dependencies are turned off.');
|
|
49
|
+
}
|
|
50
|
+
// Only npm serves the program for now (decision C51: no install script).
|
|
51
|
+
if (pkg !== null) {
|
|
52
|
+
lines.push('Reinstall with npm, with optional dependencies on:');
|
|
53
|
+
lines.push(' npm install -g ' + SCOPE + '/' + NAME + ' --include=optional');
|
|
54
|
+
lines.push('or run it again with npx:');
|
|
55
|
+
lines.push(' npx ' + SCOPE + '/' + NAME);
|
|
56
|
+
lines.push('With npx, a brand-new release can take a few minutes to reach the npm download servers: try again shortly.');
|
|
57
|
+
}
|
|
58
|
+
return lines.join('\n') + '\n';
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Where the program is, or null. `resolve` is require.resolve in production:
|
|
63
|
+
* it looks beside this package in node_modules, which is where npm, pnpm and
|
|
64
|
+
* yarn each put an optional dependency.
|
|
65
|
+
*/
|
|
66
|
+
function findBinary(platform, arch, resolve) {
|
|
67
|
+
const pkg = packageFor(platform, arch);
|
|
68
|
+
if (pkg === null) return null;
|
|
69
|
+
let packageJson;
|
|
70
|
+
try {
|
|
71
|
+
packageJson = resolve(pkg + '/package.json');
|
|
72
|
+
} catch (_) {
|
|
73
|
+
return null;
|
|
74
|
+
}
|
|
75
|
+
return binaryPath(packageJson, platform);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function launch() {
|
|
79
|
+
const platform = process.platform;
|
|
80
|
+
const bin = findBinary(platform, process.arch, require.resolve);
|
|
81
|
+
if (bin === null || !fs.existsSync(bin)) {
|
|
82
|
+
process.stderr.write(missingMessage(platform, process.arch));
|
|
83
|
+
process.exitCode = 1;
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// A tarball can lose the executable bit; put it back rather than fail.
|
|
88
|
+
if (platform !== 'win32') {
|
|
89
|
+
try {
|
|
90
|
+
fs.accessSync(bin, fs.constants.X_OK);
|
|
91
|
+
} catch (_) {
|
|
92
|
+
try {
|
|
93
|
+
fs.chmodSync(bin, 0o755);
|
|
94
|
+
} catch (_2) {
|
|
95
|
+
// spawn says what is wrong, below.
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
const child = childProcess.spawn(bin, process.argv.slice(2), { stdio: 'inherit' });
|
|
101
|
+
|
|
102
|
+
// Signals go on to the program. On a terminal, Ctrl-C already reached the
|
|
103
|
+
// program with the launcher (one process group), and a second SIGINT would
|
|
104
|
+
// read to `run` as "Ctrl-C again: stop now" (GUIDE.md §8.5), so on a
|
|
105
|
+
// terminal the launcher stays alive for SIGINT and sends nothing.
|
|
106
|
+
const interactive = tty.isatty(0);
|
|
107
|
+
const handlers = {};
|
|
108
|
+
for (const signal of ['SIGINT', 'SIGTERM', 'SIGHUP']) {
|
|
109
|
+
handlers[signal] = () => {
|
|
110
|
+
if (signal === 'SIGINT' && interactive) return;
|
|
111
|
+
try {
|
|
112
|
+
child.kill(signal);
|
|
113
|
+
} catch (_) {
|
|
114
|
+
// The program has already gone; its exit event is on its way.
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
process.on(signal, handlers[signal]);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
child.on('error', (err) => {
|
|
121
|
+
process.stderr.write(NAME + ': could not start ' + bin + ': ' + err.message + '\n');
|
|
122
|
+
process.exitCode = 1;
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
child.on('exit', (code, signal) => {
|
|
126
|
+
for (const name of Object.keys(handlers)) process.removeListener(name, handlers[name]);
|
|
127
|
+
if (signal) {
|
|
128
|
+
// Die by the same signal, as the program did, so a shell and a service
|
|
129
|
+
// manager see what happened. Where that does not end us (Windows),
|
|
130
|
+
// exit as a shell reports it: 128 plus the signal's number.
|
|
131
|
+
try {
|
|
132
|
+
process.kill(process.pid, signal);
|
|
133
|
+
} catch (_) {
|
|
134
|
+
// fall through to the exit below.
|
|
135
|
+
}
|
|
136
|
+
setTimeout(() => process.exit(128 + (os.constants.signals[signal] || 1)), 200);
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
process.exit(code === null ? 1 : code);
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
module.exports = { SUPPORTED, packageFor, binaryPath, missingMessage, findBinary };
|
|
144
|
+
|
|
145
|
+
if (require.main === module) launch();
|
package/package.json
CHANGED
|
@@ -1,6 +1,27 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@reservoirai/rsvr-provider",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"description": "The reservoir provider command line: sign in, find your model server, and serve work for reservoir.",
|
|
5
|
+
"homepage": "https://reservoirai.ai",
|
|
6
|
+
"license": "UNLICENSED",
|
|
7
|
+
"engines": {
|
|
8
|
+
"node": ">=18"
|
|
9
|
+
},
|
|
10
|
+
"bin": {
|
|
11
|
+
"rsvr-provider": "bin/rsvr-provider.js"
|
|
12
|
+
},
|
|
13
|
+
"files": [
|
|
14
|
+
"bin/rsvr-provider.js",
|
|
15
|
+
"README.md"
|
|
16
|
+
],
|
|
17
|
+
"publishConfig": {
|
|
18
|
+
"access": "public"
|
|
19
|
+
},
|
|
20
|
+
"optionalDependencies": {
|
|
21
|
+
"@reservoirai/rsvr-provider-linux-x64": "0.1.1",
|
|
22
|
+
"@reservoirai/rsvr-provider-linux-arm64": "0.1.1",
|
|
23
|
+
"@reservoirai/rsvr-provider-darwin-arm64": "0.1.1",
|
|
24
|
+
"@reservoirai/rsvr-provider-darwin-x64": "0.1.1",
|
|
25
|
+
"@reservoirai/rsvr-provider-win32-x64": "0.1.1"
|
|
26
|
+
}
|
|
27
|
+
}
|