@reservoirai/rsvr-provider 0.0.0-stage → 0.1.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 CHANGED
@@ -1,3 +1,19 @@
1
- # Temporary Holding Version
1
+ # @reservoirai/rsvr-provider
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
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, or your platform has no build, install without npm:
12
+
13
+ curl -fsSL https://reservoirai.ai/install.sh | sh
14
+
15
+ On Windows, in PowerShell:
16
+
17
+ irm https://reservoirai.ai/install.ps1 | iex
18
+
19
+ Run `rsvr-provider --help` for the commands.
@@ -0,0 +1,152 @@
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
+ const INSTALL_SH = 'curl -fsSL https://reservoirai.ai/install.sh | sh';
29
+ const INSTALL_PS1 = 'irm https://reservoirai.ai/install.ps1 | iex';
30
+
31
+ /** The platform package for a machine, or null where no build exists. */
32
+ function packageFor(platform, arch) {
33
+ const key = platform + '-' + arch;
34
+ return SUPPORTED.includes(key) ? SCOPE + '/' + NAME + '-' + key : null;
35
+ }
36
+
37
+ /** The program's path inside the platform package whose package.json is at `packageJson`. */
38
+ function binaryPath(packageJson, platform) {
39
+ return path.join(path.dirname(packageJson), 'bin', platform === 'win32' ? NAME + '.exe' : NAME);
40
+ }
41
+
42
+ /** What the launcher prints to stderr when there is no program to run. */
43
+ function missingMessage(platform, arch) {
44
+ const pkg = packageFor(platform, arch);
45
+ const lines = [];
46
+ if (pkg === null) {
47
+ lines.push(NAME + ': there is no build for ' + platform + ' on ' + arch + '.');
48
+ } else {
49
+ lines.push(NAME + ': the package ' + pkg + ' is not installed, and it holds the program for this machine.');
50
+ lines.push('npm installs it as an optional dependency, so it is missing when optional dependencies are turned off.');
51
+ }
52
+ // The hub says which ways it serves the program (FORWARDX_PROVIDER_CLI_INSTALL:
53
+ // npm, s3 or both), and this launcher reads nothing at run time, so both
54
+ // are named and the seller uses the one their hub offers.
55
+ if (pkg !== null) {
56
+ lines.push('Reinstall with npm, with optional dependencies on:');
57
+ lines.push(' npm install -g ' + SCOPE + '/' + NAME + ' --include=optional');
58
+ }
59
+ lines.push('Or, where the hub serves the install script, without npm:');
60
+ lines.push(' ' + INSTALL_SH);
61
+ if (platform === 'win32') {
62
+ lines.push('or, in PowerShell:');
63
+ lines.push(' ' + INSTALL_PS1);
64
+ }
65
+ return lines.join('\n') + '\n';
66
+ }
67
+
68
+ /**
69
+ * Where the program is, or null. `resolve` is require.resolve in production:
70
+ * it looks beside this package in node_modules, which is where npm, pnpm and
71
+ * yarn each put an optional dependency.
72
+ */
73
+ function findBinary(platform, arch, resolve) {
74
+ const pkg = packageFor(platform, arch);
75
+ if (pkg === null) return null;
76
+ let packageJson;
77
+ try {
78
+ packageJson = resolve(pkg + '/package.json');
79
+ } catch (_) {
80
+ return null;
81
+ }
82
+ return binaryPath(packageJson, platform);
83
+ }
84
+
85
+ function launch() {
86
+ const platform = process.platform;
87
+ const bin = findBinary(platform, process.arch, require.resolve);
88
+ if (bin === null || !fs.existsSync(bin)) {
89
+ process.stderr.write(missingMessage(platform, process.arch));
90
+ process.exitCode = 1;
91
+ return;
92
+ }
93
+
94
+ // A tarball can lose the executable bit; put it back rather than fail.
95
+ if (platform !== 'win32') {
96
+ try {
97
+ fs.accessSync(bin, fs.constants.X_OK);
98
+ } catch (_) {
99
+ try {
100
+ fs.chmodSync(bin, 0o755);
101
+ } catch (_2) {
102
+ // spawn says what is wrong, below.
103
+ }
104
+ }
105
+ }
106
+
107
+ const child = childProcess.spawn(bin, process.argv.slice(2), { stdio: 'inherit' });
108
+
109
+ // Signals go on to the program. On a terminal, Ctrl-C already reached the
110
+ // program with the launcher (one process group), and a second SIGINT would
111
+ // read to `run` as "Ctrl-C again: stop now" (GUIDE.md §8.5), so on a
112
+ // terminal the launcher stays alive for SIGINT and sends nothing.
113
+ const interactive = tty.isatty(0);
114
+ const handlers = {};
115
+ for (const signal of ['SIGINT', 'SIGTERM', 'SIGHUP']) {
116
+ handlers[signal] = () => {
117
+ if (signal === 'SIGINT' && interactive) return;
118
+ try {
119
+ child.kill(signal);
120
+ } catch (_) {
121
+ // The program has already gone; its exit event is on its way.
122
+ }
123
+ };
124
+ process.on(signal, handlers[signal]);
125
+ }
126
+
127
+ child.on('error', (err) => {
128
+ process.stderr.write(NAME + ': could not start ' + bin + ': ' + err.message + '\n');
129
+ process.exitCode = 1;
130
+ });
131
+
132
+ child.on('exit', (code, signal) => {
133
+ for (const name of Object.keys(handlers)) process.removeListener(name, handlers[name]);
134
+ if (signal) {
135
+ // Die by the same signal, as the program did, so a shell and a service
136
+ // manager see what happened. Where that does not end us (Windows),
137
+ // exit as a shell reports it: 128 plus the signal's number.
138
+ try {
139
+ process.kill(process.pid, signal);
140
+ } catch (_) {
141
+ // fall through to the exit below.
142
+ }
143
+ setTimeout(() => process.exit(128 + (os.constants.signals[signal] || 1)), 200);
144
+ return;
145
+ }
146
+ process.exit(code === null ? 1 : code);
147
+ });
148
+ }
149
+
150
+ module.exports = { SUPPORTED, INSTALL_SH, INSTALL_PS1, packageFor, binaryPath, missingMessage, findBinary };
151
+
152
+ if (require.main === module) launch();
package/package.json CHANGED
@@ -1,6 +1,27 @@
1
1
  {
2
2
  "name": "@reservoirai/rsvr-provider",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.0",
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.0",
22
+ "@reservoirai/rsvr-provider-linux-arm64": "0.1.0",
23
+ "@reservoirai/rsvr-provider-darwin-arm64": "0.1.0",
24
+ "@reservoirai/rsvr-provider-darwin-x64": "0.1.0",
25
+ "@reservoirai/rsvr-provider-win32-x64": "0.1.0"
26
+ }
27
+ }