@llmnative/runner 0.0.0-stage → 1.0.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/LICENSE +201 -0
- package/README.md +95 -2
- package/bin/runner.mjs +99 -0
- package/bin/setup-server.mjs +160 -0
- package/bin/ssh-keys.mjs +15 -0
- package/dist/client.js +3 -0
- package/dist/client.js.map +1 -0
- package/dist/client.mjs +183 -0
- package/dist/client.mjs.map +1 -0
- package/dist/setup-app/assets/NetworkCanvasImpl-DIYuzg6x-CVEzQpWc.js +7 -0
- package/dist/setup-app/assets/dist-9W_fpPLL.js +11 -0
- package/dist/setup-app/assets/index-BAksVWhQ.js +32 -0
- package/dist/setup-app/assets/index-CmPc3Q2I.css +2 -0
- package/dist/setup-app/assets/index.es-DFOx5a43.js +1 -0
- package/dist/setup-app/assets/index.esm-7HxyOcz9.js +9 -0
- package/dist/setup-app/assets/index.esm-Bo_uP467.js +1 -0
- package/dist/setup-app/assets/index.esm-D6oehhSQ.js +1 -0
- package/dist/setup-app/assets/index.esm-D983b7TD.js +1 -0
- package/dist/setup-app/assets/index.esm-H_whZvB-.js +4 -0
- package/dist/setup-app/assets/index.esm-NAFJB7JL.js +31 -0
- package/dist/setup-app/assets/lucide-react-DpJIOtaQ.js +1 -0
- package/dist/setup-app/assets/prism-BjaHQ1lq.js +2 -0
- package/dist/setup-app/assets/prism-bash-D6zCJ74D.js +1 -0
- package/dist/setup-app/assets/prism-c-04YixN25.js +1 -0
- package/dist/setup-app/assets/prism-clike-DapgWyxx.js +1 -0
- package/dist/setup-app/assets/prism-cpp-C-lJbC-6.js +1 -0
- package/dist/setup-app/assets/prism-csharp-XPn2bw0d.js +1 -0
- package/dist/setup-app/assets/prism-css-CPgOzxXp.js +1 -0
- package/dist/setup-app/assets/prism-docker-DkT6yOFj.js +1 -0
- package/dist/setup-app/assets/prism-git-BZB8f0uj.js +1 -0
- package/dist/setup-app/assets/prism-go-C_8qAH5n.js +1 -0
- package/dist/setup-app/assets/prism-graphql-XjvHrdQl.js +1 -0
- package/dist/setup-app/assets/prism-ini-BESK3y0r.js +1 -0
- package/dist/setup-app/assets/prism-java-6wtusvIl.js +1 -0
- package/dist/setup-app/assets/prism-javascript-BnO-swvr.js +1 -0
- package/dist/setup-app/assets/prism-json-Dp_-W-Hv.js +1 -0
- package/dist/setup-app/assets/prism-jsx-D-D0NWtC.js +1 -0
- package/dist/setup-app/assets/prism-markup-Cp04rIa1.js +1 -0
- package/dist/setup-app/assets/prism-php-Co4fM40K.js +1 -0
- package/dist/setup-app/assets/prism-powershell-Cvud8pPk.js +1 -0
- package/dist/setup-app/assets/prism-python-CfiSVtM6.js +1 -0
- package/dist/setup-app/assets/prism-ruby-Cb5nlQRI.js +1 -0
- package/dist/setup-app/assets/prism-sql-CYhVDMEE.js +1 -0
- package/dist/setup-app/assets/prism-tsx-p6J2Kc_4.js +1 -0
- package/dist/setup-app/assets/prism-typescript-BMqONzxf.js +1 -0
- package/dist/setup-app/assets/prism-yaml-C0JHu8gr.js +1 -0
- package/dist/setup-app/assets/rolldown-runtime-XKyaHtl9.js +1 -0
- package/dist/setup-app/assets/style-DLioOiRN.css +1 -0
- package/dist/setup-app/index.html +15 -0
- package/dist/setup.js +3 -0
- package/dist/setup.js.map +1 -0
- package/dist/setup.mjs +104 -0
- package/dist/setup.mjs.map +1 -0
- package/dist/steps.js +2 -0
- package/dist/steps.js.map +1 -0
- package/dist/steps.mjs +98 -0
- package/dist/steps.mjs.map +1 -0
- package/dist/types/client/index.d.ts +249 -0
- package/dist/types/setup/index.d.ts +58 -0
- package/dist/types/setup/steps.d.ts +68 -0
- package/dist/types/ui/InstallGuide.d.ts +18 -0
- package/dist/types/ui/RunnerAccounts.d.ts +13 -0
- package/dist/types/ui/RunnerConsole.d.ts +10 -0
- package/dist/types/ui/RunnersSettings.d.ts +66 -0
- package/dist/types/ui/index.d.ts +5 -0
- package/dist/types/ui/texts.d.ts +354 -0
- package/dist/ui.js +4 -0
- package/dist/ui.js.map +1 -0
- package/dist/ui.mjs +1385 -0
- package/dist/ui.mjs.map +1 -0
- package/install/compose.yaml +50 -0
- package/install/coolify.yaml +16 -0
- package/install/install.sh +206 -0
- package/llms.txt +17 -0
- package/openapi/v1.yaml +188 -0
- package/package.json +116 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
CHANGED
|
@@ -1,3 +1,96 @@
|
|
|
1
|
-
#
|
|
1
|
+
# LLMNative Runner
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Claude Code and opencode on **your own VPS**, for many tenants, with **subscriptions per person**.
|
|
4
|
+
|
|
5
|
+
- One runner serves many tenants; a platform (a CMS, a studio) can connect several runners and spread its tenants on them.
|
|
6
|
+
- Each person connects **their own** Claude subscription (or OpenCode Go key): used only for their requests. Without one, a tenant can have accounts shared by everyone, and a host falls back to its own API keys.
|
|
7
|
+
- When an account reaches its limit, the runner goes on with the next one and says when it resets.
|
|
8
|
+
- Chats run in a container each; the harness changes nothing and calls the tools of the client through MCP.
|
|
9
|
+
- No dependency on Google or any cloud: any Linux VPS, a console served by the runner itself.
|
|
10
|
+
|
|
11
|
+
This repository holds everything: the server (`server/`), the image of the harnesses (`agent/`), the installer (`install/`), the API (`openapi/v1.yaml`) and the npm package `@llmnative/runner`.
|
|
12
|
+
|
|
13
|
+
## Install a runner
|
|
14
|
+
|
|
15
|
+
On a VPS (Ubuntu 22.04+ or Debian 12+, 2 cores, 4 GB, ports 80 and 443 open) with a domain pointed at it:
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
curl -fsSL https://github.com/sherpadvisorylab/llmnative-runner/releases/download/v1.0.0/install.sh \
|
|
19
|
+
| sudo sh -s -- --domain runner.example.com
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
It installs Docker if missing, starts the runner and Caddy (TLS by itself), and prints the address and a **pairing code**. Run it again at any time; `--upgrade <version>` moves to another release. To check the script first, download it with its `install.sh.sha256` from the release.
|
|
23
|
+
|
|
24
|
+
From your computer, with the screens (automatic install over SSH, the guide, or a runner already installed):
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
npx @llmnative/runner setup
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
Or from the command line, over SSH:
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
npx @llmnative/runner install --host 203.0.113.10 --domain runner.example.com --key ~/.ssh/id_ed25519 --pair
|
|
34
|
+
npx @llmnative/runner guide --domain runner.example.com # the steps to do it by hand
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
On Coolify: `install/coolify.yaml`, then `node src/cli.ts pair` in the terminal of the service.
|
|
38
|
+
|
|
39
|
+
**Console**: `https://runner.example.com/console`, signed in with the admin token
|
|
40
|
+
(`docker compose -f /opt/llmnative-runner/compose.yaml exec runner node src/cli.ts admin-token`): state, pairing codes, tenants, keys, accounts of a tenant.
|
|
41
|
+
|
|
42
|
+
## Keys
|
|
43
|
+
|
|
44
|
+
| Key | Who has it | What it does |
|
|
45
|
+
|---|---|---|
|
|
46
|
+
| admin token | the machine (`/data/admin-token`) | the console; pairing codes |
|
|
47
|
+
| platform key `rk_platform_…` | the backend of a platform, from a pairing code | tenants and their keys; acts for any tenant with `X-Runner-Tenant` |
|
|
48
|
+
| project key `rk_…` | the backend of a tenant | `complete`, `chat`, `chat:tools`, `accounts`, `accounts:tenant`, `act-as-user`, `keys` |
|
|
49
|
+
|
|
50
|
+
Keys are kept as hashes. A host never puts a key in the browser of its people: its backend verifies the person and forwards with `X-Runner-User` (`forwardToRunner`).
|
|
51
|
+
|
|
52
|
+
## The package `@llmnative/runner`
|
|
53
|
+
|
|
54
|
+
| Entry | For | What |
|
|
55
|
+
|---|---|---|
|
|
56
|
+
| `@llmnative/runner/client` | browser, Node | `RunnerClient` (API v1: platform, accounts, models, complete, chats as async iterables), `RunnerError`, `forwardToRunner(request, path, { url, key, user })` for the backend of a host |
|
|
57
|
+
| `@llmnative/runner/ui` | React on `@llmnative/react` | `RunnerAccounts` (“My subscriptions”, or a tenant’s), `RunnersSettings` + `RunnerFleet` (the runners of a platform: add one automatically over SSH, with the guide, or already installed; default, draining, tenants), `InstallGuide`, `RunnerConsole`; texts in English and Italian (`texts` to override) |
|
|
58
|
+
| `@llmnative/runner/setup` | Node | `installOverSsh`, `installAndPair` (the same install.sh, its log streamed, the SSH access never kept) |
|
|
59
|
+
| `@llmnative/runner/steps` | browser, Node | the requirements, `installCommand`, `GUIDE_STEPS`, `parseInstallOutput`, `lookupDomain`, `checkRunner` |
|
|
60
|
+
| `npx @llmnative/runner` | command line | `setup` (the screens on localhost), `install`, `guide`, `pair` |
|
|
61
|
+
|
|
62
|
+
The UI components need what the fields of `@llmnative/react` need around them: a router, a `DataProvider` and the `I18nProvider`.
|
|
63
|
+
|
|
64
|
+
```tsx
|
|
65
|
+
// In the backend of a host (e.g. a Cloud Function): the person verified by the host.
|
|
66
|
+
import { forwardToRunner } from '@llmnative/runner/client';
|
|
67
|
+
export const runner = (request: Request, uid: string) =>
|
|
68
|
+
forwardToRunner(request, new URL(request.url).pathname.replace(/^\/api\/runner/, ''), { url: RUNNER_URL, key: TENANT_KEY, user: uid });
|
|
69
|
+
|
|
70
|
+
// In the page: the client talks to the backend of the host, not to the runner.
|
|
71
|
+
import { RunnerClient } from '@llmnative/runner/client';
|
|
72
|
+
import { RunnerAccounts } from '@llmnative/runner/ui';
|
|
73
|
+
const client = new RunnerClient({ url: '/api/runner', headers: async () => ({ authorization: `Bearer ${await idToken()}` }) });
|
|
74
|
+
<RunnerAccounts client={client} scope="user" locale="it" />
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
## Develop
|
|
78
|
+
|
|
79
|
+
```bash
|
|
80
|
+
npm install
|
|
81
|
+
npm run typecheck # library and server
|
|
82
|
+
npm test # Vitest
|
|
83
|
+
npm run build # dist/: client, ui, setup, steps
|
|
84
|
+
npm run build:console
|
|
85
|
+
cd server && DATA_DIR=/tmp/runner CONSOLE_DIR=../dist/console node src/main.ts # the server, without Docker for chats
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
The server is plain Node 24 (TypeScript run as is, no dependencies). Releases: a tag `v<version>` builds the images (amd64, arm64), the GitHub release with `install.sh` and publishes the package (`.github/workflows/publish.yml`). Images and package share the version.
|
|
89
|
+
|
|
90
|
+
## Terms of the subscriptions
|
|
91
|
+
|
|
92
|
+
Claude Pro and Max are personal. Connect only your own, used for your own requests. Check the terms of Anthropic before offering subscriptions to the people of a product.
|
|
93
|
+
|
|
94
|
+
## License
|
|
95
|
+
|
|
96
|
+
Apache-2.0
|
package/bin/runner.mjs
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// npx @llmnative/runner <command>
|
|
3
|
+
// setup the screens to add runners (installed for you over SSH, the guide, or already installed), on localhost
|
|
4
|
+
// install --host <ip> --domain <runner.example.com> [--user root] [--key ~/.ssh/id_ed25519 | --password] [--port 22]
|
|
5
|
+
// [--version 1.0.0] [--fingerprint SHA256:…] [--pair]
|
|
6
|
+
// guide --domain <runner.example.com> the commands to run by hand on the VPS
|
|
7
|
+
// pair --url <https://runner…> --code <ABCD-EFGH> a platform key (printed once)
|
|
8
|
+
import { readFileSync } from 'node:fs';
|
|
9
|
+
import { homedir } from 'node:os';
|
|
10
|
+
import { createInterface } from 'node:readline';
|
|
11
|
+
import { installOverSsh, installCommand, verifiedInstallCommands, isDomain, RUNNER_VERSION, RUNNER_REQUIREMENTS } from '../dist/setup.mjs';
|
|
12
|
+
import { RunnerClient } from '../dist/client.mjs';
|
|
13
|
+
import { spawn } from 'node:child_process';
|
|
14
|
+
import { startSetupServer, fleetFile } from './setup-server.mjs';
|
|
15
|
+
import { localSshFor } from './ssh-keys.mjs';
|
|
16
|
+
|
|
17
|
+
const [command, ...rest] = process.argv.slice(2);
|
|
18
|
+
const flags = {};
|
|
19
|
+
for (let index = 0; index < rest.length; index += 1) {
|
|
20
|
+
const name = rest[index].replace(/^--/, '');
|
|
21
|
+
const next = rest[index + 1];
|
|
22
|
+
if (next === undefined || next.startsWith('--')) flags[name] = true;
|
|
23
|
+
else { flags[name] = next; index += 1; }
|
|
24
|
+
}
|
|
25
|
+
const fail = (message) => { console.error(`error: ${message}`); process.exit(1); };
|
|
26
|
+
const ask = (question, hidden = false) => new Promise((resolve) => {
|
|
27
|
+
const rl = createInterface({ input: process.stdin, output: process.stdout });
|
|
28
|
+
if (hidden) rl._writeToOutput = () => {};
|
|
29
|
+
rl.question(question, (answer) => { rl.close(); if (hidden) process.stdout.write('\n'); resolve(answer); });
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
async function main() {
|
|
33
|
+
if (command === 'setup') {
|
|
34
|
+
const { address } = await startSetupServer({ port: flags.port ? Number(flags.port) : 0, log: (line) => console.log(line) });
|
|
35
|
+
console.log(`Runner setup: ${address}`);
|
|
36
|
+
console.log(`Runners and their keys are kept in ${fleetFile()}. Ctrl+C to stop.`);
|
|
37
|
+
if (!flags['no-open']) {
|
|
38
|
+
const [open, args] = process.platform === 'win32' ? ['cmd', ['/c', 'start', '', address]] : process.platform === 'darwin' ? ['open', [address]] : ['xdg-open', [address]];
|
|
39
|
+
spawn(open, args, { stdio: 'ignore', detached: true }).on('error', () => {}).unref();
|
|
40
|
+
}
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
if (command === 'guide') {
|
|
44
|
+
if (!isDomain(String(flags.domain ?? ''))) fail('--domain runner.example.com is required');
|
|
45
|
+
console.log(`Runner ${RUNNER_VERSION}: a VPS with ${RUNNER_REQUIREMENTS.systems.join(' or ')}, ${RUNNER_REQUIREMENTS.cpus} cores, ${RUNNER_REQUIREMENTS.memoryGb} GB, ports ${RUNNER_REQUIREMENTS.ports.join(', ')} open.`);
|
|
46
|
+
console.log(`1. Point ${flags.domain} (record A) to the address of the VPS.`);
|
|
47
|
+
console.log('2. On the VPS, as root or with sudo:\n');
|
|
48
|
+
console.log(` ${installCommand({ domain: String(flags.domain) })}\n`);
|
|
49
|
+
console.log(' or, checking the script first:\n');
|
|
50
|
+
for (const line of verifiedInstallCommands({ domain: String(flags.domain) })) console.log(` ${line}`);
|
|
51
|
+
console.log('\n3. Paste the pairing code it prints where you connect the runner.');
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
if (command === 'pair') {
|
|
55
|
+
if (!flags.url || !flags.code) fail('--url and --code are required');
|
|
56
|
+
const paired = await new RunnerClient({ url: String(flags.url) }).pair(String(flags.code), typeof flags.name === 'string' ? flags.name : 'cli');
|
|
57
|
+
console.log(`Platform key (shown once, keep it safe):\n${paired.key}`);
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
if (command === 'install') {
|
|
61
|
+
const domain = String(flags.domain ?? '');
|
|
62
|
+
if (!flags.host) fail('--host is required');
|
|
63
|
+
if (!isDomain(domain)) fail('--domain runner.example.com is required');
|
|
64
|
+
const keyFile = typeof flags.key === 'string' ? flags.key.replace(/^~/, homedir()) : undefined;
|
|
65
|
+
const password = flags.password ? (typeof flags.password === 'string' ? flags.password : await ask('SSH password: ', true)) : undefined;
|
|
66
|
+
// Without --key: the key ~/.ssh/config gives this host, as ssh does, then the default ones.
|
|
67
|
+
const local = localSshFor(String(flags.host));
|
|
68
|
+
const privateKey = keyFile ? readFileSync(keyFile, 'utf8') : (!password ? local.privateKey : undefined);
|
|
69
|
+
if (!privateKey && !password) fail('no SSH key found: give --key <file> or --password');
|
|
70
|
+
if (!keyFile && local.file && !password) console.log(`SSH key: ${local.file}`);
|
|
71
|
+
const result = await installOverSsh({
|
|
72
|
+
host: String(flags.host),
|
|
73
|
+
port: flags.port ? Number(flags.port) : 22,
|
|
74
|
+
username: typeof flags.user === 'string' ? flags.user : (local.user ?? 'root'),
|
|
75
|
+
...(privateKey ? { privateKey } : {}),
|
|
76
|
+
...(password ? { password } : {}),
|
|
77
|
+
...(typeof flags.fingerprint === 'string' ? { hostFingerprint: flags.fingerprint } : {}),
|
|
78
|
+
}, {
|
|
79
|
+
domain,
|
|
80
|
+
...(typeof flags.version === 'string' ? { version: flags.version } : {}),
|
|
81
|
+
onProgress: ({ line }) => { if (!/^[A-Z_]+=/.test(line)) console.log(line); },
|
|
82
|
+
});
|
|
83
|
+
console.log(`\nHost key of the VPS: ${result.hostFingerprint}`);
|
|
84
|
+
if (flags.pair) {
|
|
85
|
+
const paired = await new RunnerClient({ url: result.url }).pair(result.pairingCode, 'cli');
|
|
86
|
+
console.log(`Platform key (shown once, keep it safe):\n${paired.key}`);
|
|
87
|
+
} else {
|
|
88
|
+
console.log(`Address: ${result.url}\nPairing code: ${result.pairingCode} (valid 15 minutes, once)`);
|
|
89
|
+
}
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
console.log('usage: npx @llmnative/runner setup [--port 0] [--no-open]');
|
|
93
|
+
console.log(' npx @llmnative/runner install --host <ip> --domain <runner.example.com> [--user root] [--key <file> | --password] [--pair]');
|
|
94
|
+
console.log(' npx @llmnative/runner guide --domain <runner.example.com>');
|
|
95
|
+
console.log(' npx @llmnative/runner pair --url <https://runner…> --code <ABCD-EFGH>');
|
|
96
|
+
process.exit(command ? 64 : 0);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
main().catch((error) => fail(`${error.code ? `${error.code}: ` : ''}${error.message}`));
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
// The backend of `npx @llmnative/runner setup`, on 127.0.0.1 only: the runners of this computer (with their platform
|
|
2
|
+
// keys) in ~/.llmnative-runner/fleet.json (0600), the installation over SSH from here, the state of each runner.
|
|
3
|
+
// Every request carries the token of the address it opened, so that no other page of the browser can call it.
|
|
4
|
+
import { randomBytes, timingSafeEqual } from 'node:crypto';
|
|
5
|
+
import { createReadStream, existsSync, mkdirSync, readFileSync, renameSync, statSync, writeFileSync } from 'node:fs';
|
|
6
|
+
import { createServer } from 'node:http';
|
|
7
|
+
import { homedir } from 'node:os';
|
|
8
|
+
import { dirname, extname, join, normalize, sep } from 'node:path';
|
|
9
|
+
import { fileURLToPath } from 'node:url';
|
|
10
|
+
import { installOverSsh } from '../dist/setup.mjs';
|
|
11
|
+
import { RunnerClient } from '../dist/client.mjs';
|
|
12
|
+
import { localSshFor } from './ssh-keys.mjs';
|
|
13
|
+
|
|
14
|
+
const APP_DIR = join(dirname(fileURLToPath(import.meta.url)), '..', 'dist', 'setup-app');
|
|
15
|
+
const TYPES = { '.html': 'text/html; charset=utf-8', '.js': 'text/javascript', '.css': 'text/css', '.svg': 'image/svg+xml', '.png': 'image/png', '.woff2': 'font/woff2', '.json': 'application/json' };
|
|
16
|
+
|
|
17
|
+
export function fleetFile(home = homedir()) {
|
|
18
|
+
return join(home, '.llmnative-runner', 'fleet.json');
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function readFleet(file) {
|
|
22
|
+
try {
|
|
23
|
+
return existsSync(file) ? JSON.parse(readFileSync(file, 'utf8')) : { runners: [] };
|
|
24
|
+
} catch {
|
|
25
|
+
return { runners: [] };
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function writeFleet(file, fleet) {
|
|
30
|
+
mkdirSync(dirname(file), { recursive: true, mode: 0o700 });
|
|
31
|
+
writeFileSync(`${file}.tmp`, JSON.stringify(fleet, null, 2), { mode: 0o600 });
|
|
32
|
+
renameSync(`${file}.tmp`, file);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const view = ({ key: _key, ...entry }) => entry;
|
|
36
|
+
const send = (response, status, body) => {
|
|
37
|
+
response.writeHead(status, { 'content-type': 'application/json', 'cache-control': 'no-store' });
|
|
38
|
+
response.end(JSON.stringify(body));
|
|
39
|
+
};
|
|
40
|
+
const body = (request) => new Promise((resolve, reject) => {
|
|
41
|
+
const chunks = [];
|
|
42
|
+
let size = 0;
|
|
43
|
+
request.on('data', (chunk) => {
|
|
44
|
+
size += chunk.length;
|
|
45
|
+
if (size > 256 * 1024) { reject(new Error('too large')); request.destroy(); } else chunks.push(chunk);
|
|
46
|
+
});
|
|
47
|
+
request.on('end', () => {
|
|
48
|
+
try { resolve(chunks.length ? JSON.parse(Buffer.concat(chunks).toString('utf8')) : {}); } catch { reject(new Error('invalid')); }
|
|
49
|
+
});
|
|
50
|
+
request.on('error', reject);
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
/** Starts the page; resolves with its address (token included). */
|
|
54
|
+
export function startSetupServer({ port = 0, file = fleetFile(), log = () => {} } = {}) {
|
|
55
|
+
const token = randomBytes(24).toString('base64url');
|
|
56
|
+
const allowed = (request) => {
|
|
57
|
+
const given = Buffer.from(String(request.headers['x-setup-token'] ?? ''));
|
|
58
|
+
const expected = Buffer.from(token);
|
|
59
|
+
return given.length === expected.length && timingSafeEqual(given, expected);
|
|
60
|
+
};
|
|
61
|
+
const save = (change) => {
|
|
62
|
+
const fleet = readFleet(file);
|
|
63
|
+
const next = change(fleet) ?? fleet;
|
|
64
|
+
writeFleet(file, next);
|
|
65
|
+
return next;
|
|
66
|
+
};
|
|
67
|
+
/** Connects a runner by its pairing code (or a key made before) and keeps it. */
|
|
68
|
+
async function connect({ name, url, code, key }, extra = {}) {
|
|
69
|
+
const address = String(url ?? '').replace(/\/+$/, '');
|
|
70
|
+
if (!/^https?:\/\//.test(address)) throw Object.assign(new Error('invalid url'), { status: 400 });
|
|
71
|
+
const platformKey = key ? String(key) : (await new RunnerClient({ url: address }).pair(String(code ?? ''), 'setup on this computer')).key;
|
|
72
|
+
// The key works: its state answers.
|
|
73
|
+
await new RunnerClient({ url: address, key: platformKey }).platform.status();
|
|
74
|
+
const entry = { id: randomBytes(4).toString('hex'), name: String(name || new URL(address).hostname).slice(0, 80), url: address, key: platformKey, ...extra };
|
|
75
|
+
save((fleet) => {
|
|
76
|
+
if (!fleet.runners.length) entry.isDefault = true;
|
|
77
|
+
fleet.runners.push(entry);
|
|
78
|
+
});
|
|
79
|
+
log(`runner added: ${entry.name} (${entry.url})`);
|
|
80
|
+
return entry;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
const server = createServer(async (request, response) => {
|
|
84
|
+
const url = new URL(request.url ?? '/', 'http://localhost');
|
|
85
|
+
try {
|
|
86
|
+
if (url.pathname.startsWith('/api/')) {
|
|
87
|
+
if (!allowed(request)) return send(response, 401, { error: 'bad token' });
|
|
88
|
+
const parts = url.pathname.slice('/api/'.length).split('/').filter(Boolean).map(decodeURIComponent);
|
|
89
|
+
const [area, id, what] = parts;
|
|
90
|
+
if (area === 'runners' && !id && request.method === 'GET') return send(response, 200, { runners: readFleet(file).runners.map(view) });
|
|
91
|
+
if (area === 'runners' && !id && request.method === 'POST') return send(response, 201, { runner: view(await connect(await body(request))) });
|
|
92
|
+
const entry = readFleet(file).runners.find((runner) => runner.id === id);
|
|
93
|
+
if (area === 'runners' && id && !entry) return send(response, 404, { error: 'not found' });
|
|
94
|
+
if (area === 'runners' && what === 'status' && request.method === 'GET') {
|
|
95
|
+
return send(response, 200, await new RunnerClient({ url: entry.url, key: entry.key }).platform.status());
|
|
96
|
+
}
|
|
97
|
+
if (area === 'runners' && !what && request.method === 'PATCH') {
|
|
98
|
+
const patch = await body(request);
|
|
99
|
+
save((fleet) => {
|
|
100
|
+
for (const runner of fleet.runners) {
|
|
101
|
+
if (runner.id === id) {
|
|
102
|
+
if (typeof patch.name === 'string') runner.name = patch.name.slice(0, 80);
|
|
103
|
+
if (typeof patch.draining === 'boolean') runner.draining = patch.draining;
|
|
104
|
+
if (patch.isDefault === true) runner.isDefault = true;
|
|
105
|
+
if (patch.isDefault === false) delete runner.isDefault;
|
|
106
|
+
} else if (patch.isDefault === true) delete runner.isDefault;
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
return send(response, 200, { ok: true });
|
|
110
|
+
}
|
|
111
|
+
if (area === 'runners' && !what && request.method === 'DELETE') {
|
|
112
|
+
save((fleet) => ({ runners: fleet.runners.filter((runner) => runner.id !== id) }));
|
|
113
|
+
return send(response, 200, { removed: true });
|
|
114
|
+
}
|
|
115
|
+
if (area === 'install' && !id && request.method === 'POST') {
|
|
116
|
+
const input = await body(request);
|
|
117
|
+
const access = input.access ?? {};
|
|
118
|
+
response.writeHead(200, { 'content-type': 'application/x-ndjson', 'cache-control': 'no-store' });
|
|
119
|
+
const write = (event) => response.write(`${JSON.stringify(event)}\n`);
|
|
120
|
+
try {
|
|
121
|
+
// No key nor password given: the key of this computer for that host (~/.ssh/config).
|
|
122
|
+
const local = !access.privateKey && !access.password ? localSshFor(String(access.host ?? '')) : {};
|
|
123
|
+
if (!access.privateKey && !access.password && !local.privateKey) throw Object.assign(new Error('no SSH key of this computer for this host'), { code: 'ssh-key' });
|
|
124
|
+
const username = String(access.username || local.user || 'root');
|
|
125
|
+
log(`installing on ${username}@${access.host} as ${input.domain}${local.file ? ` (key ${local.file})` : ''}…`);
|
|
126
|
+
const installed = await installOverSsh({
|
|
127
|
+
host: String(access.host ?? ''),
|
|
128
|
+
port: Number(access.port) || 22,
|
|
129
|
+
username,
|
|
130
|
+
...(access.privateKey ? { privateKey: String(access.privateKey) } : local.privateKey ? { privateKey: local.privateKey } : {}),
|
|
131
|
+
...(access.password ? { password: String(access.password) } : {}),
|
|
132
|
+
}, {
|
|
133
|
+
domain: String(input.domain ?? ''),
|
|
134
|
+
onProgress: ({ line, phase }) => write({ type: 'line', line, ...(phase ? { phase } : {}) }),
|
|
135
|
+
});
|
|
136
|
+
const entry = await connect({ name: input.name, url: installed.url, code: installed.pairingCode }, { hostFingerprint: installed.hostFingerprint });
|
|
137
|
+
write({ type: 'done', runner: view(entry) });
|
|
138
|
+
} catch (error) {
|
|
139
|
+
write({ type: 'error', message: error.message, ...(error.code ? { code: error.code } : {}) });
|
|
140
|
+
}
|
|
141
|
+
return response.end();
|
|
142
|
+
}
|
|
143
|
+
return send(response, 404, { error: 'not found' });
|
|
144
|
+
}
|
|
145
|
+
// The page itself.
|
|
146
|
+
const relative = normalize(decodeURIComponent(url.pathname)).replace(/^([/\\])+/, '');
|
|
147
|
+
let path = join(APP_DIR, relative);
|
|
148
|
+
if (!path.startsWith(normalize(APP_DIR + sep)) && path !== normalize(APP_DIR)) return send(response, 404, { error: 'not found' });
|
|
149
|
+
if (!existsSync(path) || statSync(path).isDirectory()) path = join(APP_DIR, 'index.html');
|
|
150
|
+
response.writeHead(200, { 'content-type': TYPES[extname(path)] ?? 'application/octet-stream', 'x-frame-options': 'DENY', 'referrer-policy': 'no-referrer' });
|
|
151
|
+
createReadStream(path).pipe(response);
|
|
152
|
+
} catch (error) {
|
|
153
|
+
send(response, error.status ?? 400, { error: error.code ?? error.message });
|
|
154
|
+
}
|
|
155
|
+
});
|
|
156
|
+
return new Promise((resolve) => server.listen(port, '127.0.0.1', () => {
|
|
157
|
+
const address = `http://127.0.0.1:${server.address().port}/#token=${token}`;
|
|
158
|
+
resolve({ address, token, server });
|
|
159
|
+
}));
|
|
160
|
+
}
|
package/bin/ssh-keys.mjs
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
// The SSH key of this computer for a host: the IdentityFile of ~/.ssh/config for it (as ssh would use), then the
|
|
2
|
+
// usual default keys. Read only here, sent to nobody: the installer connects from this computer.
|
|
3
|
+
import { existsSync, readFileSync } from 'node:fs';
|
|
4
|
+
import { homedir } from 'node:os';
|
|
5
|
+
import { join } from 'node:path';
|
|
6
|
+
import { sshConfigFor } from '../dist/setup.mjs';
|
|
7
|
+
|
|
8
|
+
export function localSshFor(host) {
|
|
9
|
+
const home = homedir();
|
|
10
|
+
const configFile = join(home, '.ssh', 'config');
|
|
11
|
+
const config = existsSync(configFile) ? sshConfigFor(readFileSync(configFile, 'utf8'), host) : { identityFiles: [] };
|
|
12
|
+
const files = [...config.identityFiles.map((file) => file.replace(/^~(?=$|[\\/])/, home)), ...['id_ed25519', 'id_ecdsa', 'id_rsa'].map((name) => join(home, '.ssh', name))];
|
|
13
|
+
const file = files.find((candidate) => existsSync(candidate));
|
|
14
|
+
return { ...(config.user ? { user: config.user } : {}), ...(file ? { file, privateKey: readFileSync(file, 'utf8') } : {}) };
|
|
15
|
+
}
|
package/dist/client.js
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=class extends Error{status;code;until;detail;constructor(e,t,n={}){super(t),this.name=`RunnerError`,this.status=e,this.code=t,n.until&&(this.until=n.until),n.detail&&(this.detail=n.detail)}},t=e=>e.type===`error`&&e.message.startsWith(`no-credit:`)?e.message.slice(10):void 0,n=class t{options;constructor(e){this.options={...e,url:e.url.replace(/\/+$/,``)}}as(e){return new t({...this.options,...e})}async headers(e){let{key:t,tenant:n,user:r,headers:i}=this.options;return{...e?{"content-type":`application/json`}:{},...t?{authorization:`Bearer ${t}`}:{},...n?{"x-runner-tenant":n}:{},...r?{"x-runner-user":r}:{},...await i?.()}}async request(t,n,r){let i=await(this.options.fetch??fetch)(`${this.options.url}${n}`,{method:t,headers:await this.headers(r!==void 0),...r===void 0?{}:{body:JSON.stringify(r)}}),a=await i.text(),o={};try{o=a?JSON.parse(a):{}}catch{}if(!i.ok)throw new e(i.status,typeof o.error==`string`?o.error:`http-${i.status}`,{...typeof o.until==`string`?{until:o.until}:{},...typeof o.detail==`string`?{detail:o.detail}:{}});return o}health(){return this.request(`GET`,`/health`)}pair(e,t){return this.request(`POST`,`/v1/pair`,{code:e,...t?{name:t}:{}})}info(){return this.request(`GET`,`/v1/info`)}createPairing(){return this.request(`POST`,`/v1/admin/pairing`)}platform={status:()=>this.request(`GET`,`/v1/platform/status`),tenants:async()=>(await this.request(`GET`,`/v1/platform/tenants`)).tenants,createTenant:(e,t={})=>this.request(`POST`,`/v1/platform/tenants`,{id:e,...t}),removeTenant:async e=>(await this.request(`DELETE`,`/v1/platform/tenants/${encodeURIComponent(e)}`)).removed,keys:async e=>(await this.request(`GET`,`/v1/platform/tenants/${encodeURIComponent(e)}/keys`)).keys,createKey:(e,t={})=>this.request(`POST`,`/v1/platform/tenants/${encodeURIComponent(e)}/keys`,t),revokeKey:async(e,t)=>(await this.request(`DELETE`,`/v1/platform/tenants/${encodeURIComponent(e)}/keys/${encodeURIComponent(t)}`)).removed,platformKeys:async()=>(await this.request(`GET`,`/v1/platform/keys`)).keys,revokePlatformKey:async e=>(await this.request(`DELETE`,`/v1/platform/keys/${encodeURIComponent(e)}`)).removed};accounts={list:async()=>this.request(`GET`,`/v1/accounts`),startClaudeLogin:()=>this.request(`POST`,`/v1/accounts/claude-code/login`),finishClaudeLogin:async(e,t)=>(await this.request(`POST`,`/v1/accounts/claude-code/login/code`,{code:e,...t?{label:t}:{}})).account,addClaudeToken:async(e,t)=>(await this.request(`POST`,`/v1/accounts/claude-code`,{token:e,...t?{label:t}:{}})).account,addKey:async(e,t,n)=>(await this.request(`POST`,`/v1/accounts/${e}`,{key:t,...n?{label:n}:{}})).account,remove:async(e,t)=>(await this.request(`DELETE`,`/v1/accounts/${e}/${encodeURIComponent(t)}`)).removed,order:async(e,t)=>(await this.request(`PUT`,`/v1/accounts/order`,{provider:e,ids:t})).accounts};models(){return this.request(`GET`,`/v1/models`)}complete(e){return this.request(`POST`,`/v1/complete`,e)}chats={start:(e,t)=>this.request(`POST`,`/v1/chats`,{id:e,...t?{tools:t}:{}}),send:(e,t,n)=>this.stream(`/v1/chats/${encodeURIComponent(e)}/messages`,t,n),answerCall:async(e,t,n)=>(await this.request(`POST`,`/v1/chats/${encodeURIComponent(e)}/calls/${encodeURIComponent(t)}`,n)).answered,stop:async e=>(await this.request(`POST`,`/v1/chats/${encodeURIComponent(e)}/stop`)).stopped,close:async e=>(await this.request(`DELETE`,`/v1/chats/${encodeURIComponent(e)}`)).closed};async*stream(t,n,r){let i=await(this.options.fetch??fetch)(`${this.options.url}${t}`,{method:`POST`,headers:await this.headers(!0),body:JSON.stringify(n),...r?{signal:r}:{}});if(!i.ok||!i.body){let t=`http-${i.status}`;try{let e=await i.json();e.error&&(t=e.error)}catch{}throw new e(i.status,t)}let a=i.body.getReader(),o=new TextDecoder,s=``;for(;;){let{done:e,value:t}=await a.read();s+=o.decode(t??new Uint8Array,{stream:!e});let n=s.split(`
|
|
2
|
+
`);s=e?``:n.pop()??``;for(let e of n){if(!e.trim())continue;let t;try{t=JSON.parse(e)}catch{continue}t.type!==`ping`&&(yield t)}if(e)return}}},r=/^\/v1\/(info|models|complete|accounts(\/[A-Za-z0-9_.:-]+){0,3}|chats(\/[a-f0-9]{8}(\/(messages|stop|calls\/[a-f0-9]{12}))?)?)$/;async function i(e,t,n,i=fetch){if(!r.test(t)||![`GET`,`POST`,`PUT`,`DELETE`].includes(e.method))return new Response(JSON.stringify({error:`not found`}),{status:404,headers:{"content-type":`application/json`}});let a={authorization:`Bearer ${n.key}`,"x-runner-user":n.user,...n.tenant?{"x-runner-tenant":n.tenant}:{}},o=e.headers.get(`content-type`);o&&(a[`content-type`]=o);let s=e.method===`GET`||e.method===`DELETE`?void 0:await e.arrayBuffer(),c=new URL(e.url),l=await i(`${n.url.replace(/\/+$/,``)}${t}${c.search}`,{method:e.method,headers:a,...s?{body:s}:{},signal:e.signal});return new Response(l.body,{status:l.status,headers:{"content-type":l.headers.get(`content-type`)??`application/json`,"cache-control":`no-store`,"x-accel-buffering":`no`}})}exports.RunnerClient=n,exports.RunnerError=e,exports.forwardToRunner=i,exports.noCreditUntil=t;
|
|
3
|
+
//# sourceMappingURL=client.js.map
|