@nidl/client 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/LICENSE ADDED
@@ -0,0 +1,43 @@
1
+ # Licence
2
+
3
+ nidl is dual-licensed under either of
4
+
5
+ - Apache License, Version 2.0 ([LICENSE-APACHE](./LICENSE-APACHE))
6
+ - MIT License ([LICENSE-MIT](./LICENSE-MIT))
7
+
8
+ at your option. This is the Rust ecosystem's customary dual licence, and it is what the
9
+ great majority of this project's own dependencies already use.
10
+
11
+ Unless you explicitly state otherwise, any contribution intentionally submitted for
12
+ inclusion in this work by you, as defined in the Apache-2.0 licence, shall be dual
13
+ licensed as above, without any additional terms or conditions.
14
+
15
+ ## Third-party notice
16
+
17
+ This notice is scoped to what each build contains, as
18
+ `.hermes/artifacts/plugin-cli-foundation/F-DEPENDENCY-SECURITY-AUDIT.md` s.2 records it. Its
19
+ obligations are recorded here rather than left to be discovered.
20
+
21
+ **The headless binary** (`nidl-core`, built without default features: what a handed build
22
+ contains) has one dependency under a copyleft licence:
23
+
24
+ **`option-ext`** (MPL-2.0), used unmodified, reached through `dirs` → `dirs-sys`. MPL-2.0 is
25
+ file-level copyleft: the obligation attaches to modifications of MPL-licensed *files*, not
26
+ to the work that links them. nidl modifies none, so what is owed is the notice above and
27
+ availability of that component's source, which is published at its own repository. It
28
+ places no constraint on nidl's own terms.
29
+
30
+ Everything else in the headless binary's dependency graph is permissive. No crate in it is under
31
+ GPL, LGPL or AGPL.
32
+
33
+ **The desktop app** (built with default features, and not distributed today) also contains the
34
+ four MPL-2.0 crates of its webview's CSS stack, each used unmodified, with the same obligation as
35
+ `option-ext`: **`cssparser`**, **`cssparser-macros`**, **`dtoa-short`** and **`selectors`**. No
36
+ crate in it is under GPL, LGPL or AGPL either.
37
+
38
+ **The website** (`@nidl/web`, private, and not distributed) depends on
39
+ **`@img/sharp-libvips-darwin-arm64`** (LGPL-3.0-or-later), a prebuilt image library reached through
40
+ `next` → `sharp`. Publishing the website would make its LGPL obligation live.
41
+
42
+ `tests/licence_notice_test.rs` reads both Rust dependency graphs, and fails when a copyleft crate in
43
+ either is not named here or a crate under GPL, LGPL or AGPL appears.
package/LICENSE-APACHE ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
package/LICENSE-MIT ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Criss Moldovan
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,157 @@
1
- # Temporary Holding Version
1
+ # @nidl/client
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
+ Drive a running [nidl](https://github.com/crissmoldovan/nidl) core from a Node program, over its
4
+ local socket, or over HTTPS to its remote port on another machine.
5
+
6
+ ```js
7
+ import { connect } from "@nidl/client";
8
+
9
+ const nidl = await connect(); // the core serving ~/.nidl; or connect({ dataDir })
10
+ if (nidl.has("targets.list")) {
11
+ const { targets } = await nidl.command("targets.list");
12
+ }
13
+ ```
14
+
15
+ - **It never starts a core.** When none is running, `connect()` fails with code `not_running`
16
+ and says how to start one: `nidl serve --data-dir ~/.nidl`, or open the nidl app.
17
+ - **It checks the socket's folder first:** each folder on the way is yours or root's and not
18
+ writable by others, the control folder is `0700`, the core's record is a private file
19
+ describing this folder's core, and the socket is the one that record names. A check that fails
20
+ throws code `unsafe_folder`. Node cannot ask the operating system who is at the other end of a
21
+ socket, so this library cannot check the peer's user; the Python and Rust libraries can.
22
+ - **It is an app, not the owner.** It connects as the `app` client kind: it can read, draft,
23
+ preview and apply, but credential commands, such as connecting an account or unlocking
24
+ credentials, are refused with `requires_owner_action`. Those are yours to run, from the CLI or
25
+ the desktop.
26
+ - **Command names are typed.** `command()` takes a `CommandName`, one of `COMMAND_NAMES`: the
27
+ commands an app may run, generated from the core's registry. A misspelled name, a credential
28
+ command or `pools.lend` is a type error. Call a command a newer core offers with a cast:
29
+ `nidl.command("its.name" as CommandName)`. Results are plain JSON.
30
+ - **Each call is one connection:** the folder is checked, the core says hello, the command runs,
31
+ the connection closes.
32
+
33
+ Errors are `NidlError`s with a `code` for programs, a `message` for people, and an `outcome`:
34
+ `not_started`, or `unknown` when the connection was lost after the command was sent, since it may
35
+ have run.
36
+
37
+ | Code | Meaning |
38
+ | --- | --- |
39
+ | `not_running` | no core serves this folder |
40
+ | `unsafe_folder` | the socket's folder failed a check |
41
+ | `not_offered` | this core does not have that command; update nidl |
42
+ | `version_conflict` | the core speaks another protocol version |
43
+ | `path_too_long` | the socket's path is longer than the platform allows |
44
+ | `timeout` | no answer within `timeoutMs` (10 seconds by default) |
45
+ | `protocol_error` | the core's reply broke the protocol |
46
+ | anything else | the core's own refusal, such as `not_found` or `requires_owner_action` |
47
+
48
+ ## A core on another machine
49
+
50
+ When a machine's owner has turned on nidl's remote port there (`nidl remote enable`) and issued you
51
+ a remote token (`nidl remote-tokens issue`), connect to that core by its URL, `https://HOST:PORT`:
52
+
53
+ ```js
54
+ const nidl = await connect({
55
+ url: "https://nidl.example:8443",
56
+ token: process.env.NIDL_TOKEN,
57
+ fingerprint: "sha256:…", // as `nidl remote status` shows it on that machine
58
+ });
59
+ ```
60
+
61
+ - **The certificate is checked before the token is sent.** With a fingerprint, only nidl's own
62
+ certificate with that fingerprint is accepted, as SSH remembers a host's key; the handshake still
63
+ proves the server holds its key. Without one, the certificate must be one Node trusts for the URL's
64
+ host, as when the owner serves a certificate of their own. Anything else fails with
65
+ `untrusted_certificate`, and nothing is sent.
66
+ - **The token's scope decides what runs.** A `read` token lists and reads. An `operate` token also
67
+ drafts targets, refreshes catalogs and readings, and previews and applies routing. Neither runs
68
+ credential commands or starts paid model checks: those stay with the owner at the machine
69
+ (`requires_owner_action`).
70
+ - **`nidl.identity`** has no `root` or `instanceNonce` for a remote core, which does not say what names
71
+ its files; it says the token's `scope`.
72
+ - **Each call is one HTTPS connection** to the remote port, closed after the answer.
73
+
74
+ The remote codes, beside those above: `unauthorized` (the token is unknown, revoked or expired),
75
+ `untrusted_certificate` (the certificate is not the one expected; nothing was sent), `throttled`
76
+ (too many failed attempts from this address; wait a minute), `invalid_input` (the URL, token or
77
+ fingerprint is malformed, or the command is over 1 MiB), `unavailable` (the machine could not be
78
+ reached, or its core is busy or not serving), and `unsupported` (that nidl's remote port takes no
79
+ commands; update it there).
80
+
81
+ ## Lending your project's key, and reporting readings
82
+
83
+ Another program can use nidl for its own accounts once the owner has made it a project there
84
+ (`nidl projects create`), with a **borrowed** account for each API key it holds
85
+ (`nidl projects add-account`, mode `borrowed`) and an API target with an app token
86
+ (`nidl targets create`, `nidl app-tokens issue`). Your program lends nidl its key for as long as it
87
+ wants requests to the target's endpoint, `/h/<target>/v1/…`, routed with it, and takes it back:
88
+
89
+ ```js
90
+ const lease = await nidl.lend(accountId, apiKey, { appToken: process.env.NIDL_APP_TOKEN, expiresInSeconds: 3600 });
91
+ // ... calls to the target's endpoint route with the key while the lease lives ...
92
+ await nidl.withdraw(accountId);
93
+ ```
94
+
95
+ - **The key travels in the socket's secret frame,** never in a command's arguments, so
96
+ `command("pools.lend")` is refused with `invalid_input`. nidl keeps it in memory only, never on
97
+ disk, for 60 seconds to 12 hours (an hour unless you say) and never past the app token. It is
98
+ dropped when the lease expires, when you withdraw it, when the owner revokes the token or removes
99
+ its target, and when the core stops. Lend again to renew it.
100
+ - **The app token proves the account is your project's.** A token of another project's target, a
101
+ revoked or expired one, or none, is refused with `not_authorized`.
102
+ - **On this machine only.** `lend` and `withdraw` on a remote core fail with `unsupported` before
103
+ anything is sent.
104
+ - The lease is `{accountId, lentAt, expiresAt, lentBy}`, `lentBy` being your app token's id. It
105
+ never holds the key.
106
+
107
+ A JavaScript string cannot be wiped; the frame's own bytes are overwritten once the socket has
108
+ taken them.
109
+
110
+ An **observed** account is one nidl never holds a key for, a subscription for instance, whose quota
111
+ your program reports so the owner sees it beside their own:
112
+
113
+ ```js
114
+ await nidl.observe(accountId, [{ key: "five_hour", percent: 37.5, resetsAt: "2026-10-21T15:00:00Z" }]);
115
+ ```
116
+
117
+ At most 16 windows, each a `key`, a `percent` from 0 to 100, and optionally a `label` and a
118
+ `resetsAt`, captured within the last 24 hours (now, unless you say). On a remote core this needs an
119
+ `operate` token bound to your project (`nidl remote-tokens issue` with its `project`).
120
+
121
+
122
+ ## In a Trigger.dev task
123
+
124
+ A task can run its own nidl core in its container, from a **task vault** you export at your
125
+ machine (`nidl task-vault export`) and give the task as two secrets, `NIDL_TASK_VAULT` and
126
+ `NIDL_TASK_VAULT_KEY`:
127
+
128
+ ```js
129
+ import { startTaskCore } from "@nidl/client";
130
+
131
+ const nidl = await startTaskCore(); // once per process; a warm worker reuses it
132
+ process.env.ANTHROPIC_BASE_URL = nidl.baseUrl; // http://127.0.0.1:<port>/h/<target>
133
+ process.env.ANTHROPIC_API_KEY = nidl.appToken;
134
+ ```
135
+
136
+ - It removes both secrets from `process.env` before anything else runs, writes them to private
137
+ files, opens the task vault, serves it with `--stop-with-parent` and unlocks it with its key
138
+ file. It needs `@nidl/cli` beside it (or `executable`), both kept out of the bundle
139
+ (`build.external`).
140
+ - Its folder is made in the temporary folder, or in the home folder when someone else may write to
141
+ the temporary one, as anyone may to `/tmp`; `directory` names another. A start that fails removes
142
+ what it wrote and can be called again; `stop()` removes the folder once the core has stopped.
143
+ - Linux only, where Trigger.dev deploys run. Otherwise a task reaches the hub with an app token.
144
+ - Codes: `not_configured` (no secrets), `not_installed` (no `@nidl/cli`), `timeout`,
145
+ `unavailable`, or the core's own, such as `invalid_input` for a vault that does not open.
146
+
147
+ The whole path, the hub's included, is in
148
+ [docs/integrations/trigger-dev.md](https://github.com/crissmoldovan/nidl/blob/main/docs/integrations/trigger-dev.md).
149
+
150
+ Long-running commands return an operation id: poll it with `nidl.command("operations.get", { operationId })`.
151
+
152
+ Results are JavaScript values, so a whole number above 2^53 loses precision, as it does in any
153
+ `JSON.parse`. nidl's results do not carry such numbers today.
154
+
155
+ The protocol is described in
156
+ [docs/protocol/nidl-core-protocol.md](https://github.com/crissmoldovan/nidl/blob/main/docs/protocol/nidl-core-protocol.md).
157
+ Node 22 or later, on macOS or Linux. No dependencies: the remote port uses Node's own `tls` and `http`.
@@ -0,0 +1,3 @@
1
+ export declare const COMMAND_NAMES: readonly ["accounts.get", "accounts.list", "accounts.update", "catalog.refresh", "catalog.search", "commands.list", "costs.get", "custom_harnesses.list", "custom_harnesses.remove", "custom_harnesses.save", "generations.list", "generations.preview", "generations.retire", "generations.stop", "launch.apply", "launch.preview", "launch.remove", "launch.status", "mappings.suggest", "mappings.validate", "monitor.probe_now", "monitor.start", "monitor.status", "monitor.stop", "operations.get", "plugins.disable", "plugins.enable", "plugins.lifecycle", "plugins.lifecycle_preview", "plugins.list", "pools.withdraw", "presets.get", "presets.list", "presets.validate", "probes.costs", "probes.history", "projects.list", "providers.list", "readings.observe", "remote.status", "routing.apply", "routing.disable", "routing.disable_preview", "routing.preview", "routing.status", "routing_presets.list", "routing_presets.remove", "routing_presets.save", "runtime.version", "targets.clone", "targets.create", "targets.get", "targets.list", "targets.preset_refresh_apply", "targets.preset_refresh_preview", "targets.remove", "targets.save", "usage.get", "watchers.add_model", "watchers.disable", "watchers.enable", "watchers.get", "watchers.history", "watchers.refresh", "watchers.remove_model"];
2
+ export type CommandName = (typeof COMMAND_NAMES)[number];
3
+ //# sourceMappingURL=commands.generated.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"commands.generated.d.ts","sourceRoot":"","sources":["../src/commands.generated.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,aAAa,mwCAkEhB,CAAC;AAEX,MAAM,MAAM,WAAW,GAAG,CAAC,OAAO,aAAa,CAAC,CAAC,MAAM,CAAC,CAAC"}
@@ -0,0 +1,72 @@
1
+ // Generated from the core's command registry. Do not edit by hand: the core's test
2
+ // `client_command_names_test` fails when this file differs, and prints it as it should be.
3
+ // The commands an app may run: none of the owner's credential commands, and not `pools.lend`, which
4
+ // `lend()` sends with its key in the socket's secret frame.
5
+ export const COMMAND_NAMES = [
6
+ "accounts.get",
7
+ "accounts.list",
8
+ "accounts.update",
9
+ "catalog.refresh",
10
+ "catalog.search",
11
+ "commands.list",
12
+ "costs.get",
13
+ "custom_harnesses.list",
14
+ "custom_harnesses.remove",
15
+ "custom_harnesses.save",
16
+ "generations.list",
17
+ "generations.preview",
18
+ "generations.retire",
19
+ "generations.stop",
20
+ "launch.apply",
21
+ "launch.preview",
22
+ "launch.remove",
23
+ "launch.status",
24
+ "mappings.suggest",
25
+ "mappings.validate",
26
+ "monitor.probe_now",
27
+ "monitor.start",
28
+ "monitor.status",
29
+ "monitor.stop",
30
+ "operations.get",
31
+ "plugins.disable",
32
+ "plugins.enable",
33
+ "plugins.lifecycle",
34
+ "plugins.lifecycle_preview",
35
+ "plugins.list",
36
+ "pools.withdraw",
37
+ "presets.get",
38
+ "presets.list",
39
+ "presets.validate",
40
+ "probes.costs",
41
+ "probes.history",
42
+ "projects.list",
43
+ "providers.list",
44
+ "readings.observe",
45
+ "remote.status",
46
+ "routing.apply",
47
+ "routing.disable",
48
+ "routing.disable_preview",
49
+ "routing.preview",
50
+ "routing.status",
51
+ "routing_presets.list",
52
+ "routing_presets.remove",
53
+ "routing_presets.save",
54
+ "runtime.version",
55
+ "targets.clone",
56
+ "targets.create",
57
+ "targets.get",
58
+ "targets.list",
59
+ "targets.preset_refresh_apply",
60
+ "targets.preset_refresh_preview",
61
+ "targets.remove",
62
+ "targets.save",
63
+ "usage.get",
64
+ "watchers.add_model",
65
+ "watchers.disable",
66
+ "watchers.enable",
67
+ "watchers.get",
68
+ "watchers.history",
69
+ "watchers.refresh",
70
+ "watchers.remove_model",
71
+ ];
72
+ //# sourceMappingURL=commands.generated.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"commands.generated.js","sourceRoot":"","sources":["../src/commands.generated.ts"],"names":[],"mappings":"AAAA,mFAAmF;AACnF,2FAA2F;AAC3F,oGAAoG;AACpG,4DAA4D;AAC5D,MAAM,CAAC,MAAM,aAAa,GAAG;IAC3B,cAAc;IACd,eAAe;IACf,iBAAiB;IACjB,iBAAiB;IACjB,gBAAgB;IAChB,eAAe;IACf,WAAW;IACX,uBAAuB;IACvB,yBAAyB;IACzB,uBAAuB;IACvB,kBAAkB;IAClB,qBAAqB;IACrB,oBAAoB;IACpB,kBAAkB;IAClB,cAAc;IACd,gBAAgB;IAChB,eAAe;IACf,eAAe;IACf,kBAAkB;IAClB,mBAAmB;IACnB,mBAAmB;IACnB,eAAe;IACf,gBAAgB;IAChB,cAAc;IACd,gBAAgB;IAChB,iBAAiB;IACjB,gBAAgB;IAChB,mBAAmB;IACnB,2BAA2B;IAC3B,cAAc;IACd,gBAAgB;IAChB,aAAa;IACb,cAAc;IACd,kBAAkB;IAClB,cAAc;IACd,gBAAgB;IAChB,eAAe;IACf,gBAAgB;IAChB,kBAAkB;IAClB,eAAe;IACf,eAAe;IACf,iBAAiB;IACjB,yBAAyB;IACzB,iBAAiB;IACjB,gBAAgB;IAChB,sBAAsB;IACtB,wBAAwB;IACxB,sBAAsB;IACtB,iBAAiB;IACjB,eAAe;IACf,gBAAgB;IAChB,aAAa;IACb,cAAc;IACd,8BAA8B;IAC9B,gCAAgC;IAChC,gBAAgB;IAChB,cAAc;IACd,WAAW;IACX,oBAAoB;IACpB,kBAAkB;IAClB,iBAAiB;IACjB,cAAc;IACd,kBAAkB;IAClB,kBAAkB;IAClB,uBAAuB;CACf,CAAC"}
@@ -0,0 +1,136 @@
1
+ import type { CommandName } from "./commands.generated.js";
2
+ export declare const VERSION = "0.1.0";
3
+ /** PQ4: how a key is lent. */
4
+ export interface LendOptions {
5
+ /** An app token of one of the account's project's targets: how an app proves its project. */
6
+ appToken?: string;
7
+ /** How long the lease lasts, 60 to 43,200 seconds; an hour unless given. */
8
+ expiresInSeconds?: number;
9
+ }
10
+ /** PQ4: one window of an observed account's reading. */
11
+ export interface ObservedWindow {
12
+ key: string;
13
+ percent: number;
14
+ label?: string;
15
+ resetsAt?: string;
16
+ }
17
+ export interface ConnectOptions {
18
+ /** The core's data folder. Defaults to `~/.nidl`. */
19
+ dataDir?: string;
20
+ /** How long one call may take, in milliseconds. Defaults to 10 seconds. */
21
+ timeoutMs?: number;
22
+ /** A core on another machine: its remote port, `https://HOST:PORT`. Instead of `dataDir`. */
23
+ url?: string;
24
+ /** The remote token `nidl remote-tokens issue` gave, for `url`. */
25
+ token?: string;
26
+ /**
27
+ * `sha256:` and 64 hex digits, as `nidl remote status` shows it: only the certificate with this
28
+ * fingerprint is accepted. Without it, the certificate must be one Node trusts for the URL's host.
29
+ */
30
+ fingerprint?: string;
31
+ }
32
+ /**
33
+ * The core's identity, as its hello returns it. Fields this version does not know are kept. A
34
+ * remote core does not say what names its files (`root`, `instanceNonce`), and says the token's
35
+ * `scope` instead.
36
+ */
37
+ export interface Identity {
38
+ root?: {
39
+ device: string;
40
+ inode: string;
41
+ };
42
+ instanceNonce?: string;
43
+ apiMajor: number;
44
+ apiMinor: number;
45
+ coreVersion: string;
46
+ commands: string[];
47
+ scope?: string;
48
+ [field: string]: unknown;
49
+ }
50
+ /**
51
+ * Why a call failed. `code` is for programs and `message` for people. `outcome` says whether
52
+ * anything happened: `not_started`, or `unknown` when the connection was lost after the request
53
+ * was sent.
54
+ */
55
+ export declare class NidlError extends Error {
56
+ readonly code: string;
57
+ readonly outcome: string;
58
+ readonly name = "NidlError";
59
+ constructor(code: string, message: string, outcome?: string);
60
+ }
61
+ /**
62
+ * Connect to the core serving `dataDir`, or, with `url` and `token`, to the core whose remote port
63
+ * is at `url`; then say hello once to prove it answers.
64
+ */
65
+ export declare function connect(options?: ConnectOptions): Promise<Nidl>;
66
+ export declare class Nidl {
67
+ #private;
68
+ /** The data folder of the core on this machine; undefined for a remote core. */
69
+ readonly dataDir: string | undefined;
70
+ private readonly timeoutMs;
71
+ private readonly remote?;
72
+ /** @internal Use `connect()`. */
73
+ constructor(
74
+ /** The data folder of the core on this machine; undefined for a remote core. */
75
+ dataDir: string | undefined, timeoutMs: number, remote?: Remote | undefined);
76
+ /** The core's identity from the latest hello. */
77
+ get identity(): Identity;
78
+ /** Whether the core offers a command, by the latest hello. */
79
+ has(name: string): boolean;
80
+ /**
81
+ * Run one command and return its result, or throw a `NidlError`. Each call opens its own
82
+ * connection, checks the folder again and says hello again. `name` is one an app may run
83
+ * (CL8); a newer core's command is called with a cast, `"its.name" as CommandName`.
84
+ */
85
+ command(name: CommandName, args?: Record<string, unknown>): Promise<unknown>;
86
+ /**
87
+ * PQ4 (docs/specs/nidl-external-pools.md s.6 item 1): lend `apiKey` to the borrowed account
88
+ * `accountId` of the core on this machine. An app proves the account's project with
89
+ * `appToken`, an app token of one of that project's targets. The key travels in the socket's
90
+ * secret frame, never in the command's arguments, and never through the remote port. A
91
+ * JavaScript string cannot be wiped; the frame's own bytes are overwritten once written.
92
+ */
93
+ lend(accountId: string, apiKey: string, options?: LendOptions): Promise<unknown>;
94
+ /**
95
+ * PQ4: end the lease of the borrowed account `accountId` on the core on this machine.
96
+ * Withdrawing none is not an error: the result says whether there was one.
97
+ */
98
+ withdraw(accountId: string): Promise<unknown>;
99
+ /**
100
+ * PQ4: report an observed account's quota readings, on this machine or through the remote port
101
+ * with a remote token bound to the account's project. `capturedAt` (RFC 3339) defaults to now.
102
+ */
103
+ observe(accountId: string, windows: ObservedWindow[], capturedAt?: string): Promise<unknown>;
104
+ private onThisMachine;
105
+ private offered;
106
+ /** @internal Say hello on a fresh connection and keep the identity. */
107
+ refresh(): Promise<void>;
108
+ /** `secret`, when given, is the secret frame written right after the command's line (PQ4). */
109
+ private exchange;
110
+ }
111
+ /**
112
+ * A core's remote port: one TLS connection per call, closed after the answer. The certificate is
113
+ * checked once the handshake is done and before anything is written, so a token is never sent to a
114
+ * server that is not the core's. With a pin, the handshake's own signature still proves the server
115
+ * holds the pinned certificate's key.
116
+ */
117
+ declare class Remote {
118
+ #private;
119
+ private readonly host;
120
+ private readonly port;
121
+ private readonly authority;
122
+ private readonly pin;
123
+ constructor(url: string, token: string, fingerprint: string | undefined);
124
+ hello(deadline: number): Promise<Identity>;
125
+ command(name: string, args: unknown, deadline: number): Promise<unknown>;
126
+ /** A reply or an identity for 200, a reply for the 403 and 502 that carry one; otherwise the error the status names. */
127
+ private answer;
128
+ private untrusted;
129
+ /** A TLS connection whose certificate has been checked, before anything is written on it. */
130
+ private secured;
131
+ /** One request on one connection, every step within `deadline`. */
132
+ private exchange;
133
+ }
134
+ export { COMMAND_NAMES, type CommandName } from "./commands.generated.js";
135
+ export { openTaskCore, startTaskCore, TASK_VAULT_KEY_VARIABLE, TASK_VAULT_VARIABLE, type TaskCore, type TaskCoreOptions, } from "./task.js";
136
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAaA,OAAO,KAA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