@openartifactsai/harness-kit 0.0.0-stage → 0.23.0-rc.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 +202 -0
- package/NOTICE +5 -0
- package/README.md +210 -2
- package/package.json +52 -4
- package/src/client.d.ts +160 -0
- package/src/client.js +409 -0
- package/src/context.d.ts +31 -0
- package/src/context.js +61 -0
- package/src/daemon.d.ts +177 -0
- package/src/daemon.js +293 -0
- package/src/embed/index.d.ts +230 -0
- package/src/embed/index.js +376 -0
- package/src/embed/remote.d.ts +39 -0
- package/src/embed/remote.js +51 -0
- package/src/harness.d.ts +383 -0
- package/src/harness.js +678 -0
- package/src/index.d.ts +28 -0
- package/src/index.js +20 -0
- package/src/legacy.d.ts +106 -0
- package/src/legacy.js +278 -0
- package/src/mcp.d.ts +39 -0
- package/src/mcp.js +85 -0
- package/src/runtimes.d.ts +174 -0
- package/src/runtimes.js +398 -0
- package/src/skill.d.ts +58 -0
- package/src/skill.js +88 -0
- package/src/testing-ws.d.ts +44 -0
- package/src/testing-ws.js +204 -0
- package/src/testing.d.ts +227 -0
- package/src/testing.js +564 -0
package/LICENSE
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/NOTICE
ADDED
package/README.md
CHANGED
|
@@ -1,3 +1,211 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @openartifactsai/harness-kit
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
The SDK an agent app uses to integrate [Open Artifacts](https://github.com/openartifactsai/open-artifacts). It finds or starts the
|
|
4
|
+
local daemon, holds a Harness API connection that reconnects by itself, gives the app's agent the tools, hands comment
|
|
5
|
+
wakes to the app's sessions and page opens to its UI, and reports the artifacts its sessions make.
|
|
6
|
+
|
|
7
|
+
It depends only on `@openartifactsai/protocol` and Node built-ins (Node 22.18+, or Electron's Node), and bundles into a
|
|
8
|
+
single file. The guide is [docs/integrating.md](../../docs/integrating.md); this page is the summary of the package.
|
|
9
|
+
|
|
10
|
+
## Use
|
|
11
|
+
|
|
12
|
+
```ts
|
|
13
|
+
import { createHarness } from '@openartifactsai/harness-kit';
|
|
14
|
+
|
|
15
|
+
const harness = await createHarness({
|
|
16
|
+
harness: 'my-app', // ^[a-z0-9][a-z0-9._-]{0,40}$
|
|
17
|
+
agentName: 'Assistant',
|
|
18
|
+
commands: ['artifact'],
|
|
19
|
+
runtime: { dir: '/path/to/@openartifactsai/cli', version: '0.16.1' }, // starts the daemon when none runs
|
|
20
|
+
// Give a message to a session: 'delivered' | 'resumed' | 'drafted' | 'queued' | 'held' (the daemon keeps it, you start
|
|
21
|
+
// the turn) | 'failed' (the daemon keeps it),
|
|
22
|
+
// or { status, session }. Only the owner's words (source.from.kind === 'owner') should become a user turn.
|
|
23
|
+
// source.requests[] may carry userText and selectionSnapshot (feature wake.request.parts) for the chat to show.
|
|
24
|
+
wake: async ({ session, text, source }) => ((await myApp.deliver(session, text, source)) ? 'delivered' : 'failed'),
|
|
25
|
+
// Show a page in the app's own UI; return false when it was not shown.
|
|
26
|
+
embed: { origins: [], mode: 'view', remote: 'ask' },
|
|
27
|
+
allowRemote: ({ origin, type }) => myApp.confirm(`Show a ${type} page from ${origin}?`),
|
|
28
|
+
open: ({ embedUrl, title }) => myApp.openTab(embedUrl, title),
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
await harness.attach({ session: 's1', workspace: '/path/to/project', title: 'Chat 1' });
|
|
32
|
+
const tools = await harness.tools(); // the daemon's, or the bundled definitions offline
|
|
33
|
+
const result = await harness.call('Artifact', args, { session: 's1', workspace: '/path/to/project' });
|
|
34
|
+
harness.on('artifact', ({ session, artifact, change }) => myApp.card(session, artifact, change));
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
- The connection reconnects with backoff (1 s doubling to 30 s), says hello again and attaches every session again;
|
|
38
|
+
not after the person's `daemon.stop()`, until they ask for the daemon again.
|
|
39
|
+
- What waited in a session's inbox goes to `wake` on attach; `attach()` returns what `wake` did not take. On the
|
|
40
|
+
kit's own attach after a reconnect, what `wake` did not take goes back to the daemon's inbox (`inbox.return`), so
|
|
41
|
+
the session's next `call()` or wait has it; a daemon without that feature leaves it with the kit, which adds it to
|
|
42
|
+
the session's next `call()`.
|
|
43
|
+
- A `wake` callback that throws or takes longer than `wakeTimeoutMs` (25 s) answers `failed`. `held` keeps the message
|
|
44
|
+
in the inbox like `failed` but tells the daemon not to run the profile's nudge, because your app starts the turn; to a
|
|
45
|
+
daemon without the feature `wake.held` the kit sends `failed`.
|
|
46
|
+
- `caps` in `hello` follow from the callbacks: `wake` only with a `wake` callback, `open` only with an `open` callback
|
|
47
|
+
(`{ embed, origins, remote }` with `embed`), `sessions.start` only with a `startSession` callback (and
|
|
48
|
+
`sessions.models` only with a `sessionModels` one next to it). `options.caps` adds `tools`, `library`, `wake.resume`,
|
|
49
|
+
`wake.mode`.
|
|
50
|
+
- Under `embed.remote: 'ask'` (the default) a remote type's page reaches `open` only after `allowRemote` said yes.
|
|
51
|
+
- Check `harness.features` by name before using anything newer than the base protocol.
|
|
52
|
+
- Names from before the rename still work: the kit asks for the `open-artifacts-harness` subprotocol and then the older
|
|
53
|
+
`open-artifact-harness`, takes `open-artifact://` links as its own, and `./embed` sends and reads both envelope keys,
|
|
54
|
+
`openArtifacts` and `openArtifact`, so a Shell of that time works too. A 0.22 daemon still running is found
|
|
55
|
+
(`readDaemon`, `daemonHealth`) and called (`api`) at its older paths, and `ensureDaemon` replaces it with a newer
|
|
56
|
+
runtime ([harness API](../../docs/spec/harness-api.md#names-from-before-the-rename)).
|
|
57
|
+
- `daemon: { spawn }` starts the daemon process yourself. The kit passes `{ bin, args, env, logFile }` (no
|
|
58
|
+
`ELECTRON_RUN_AS_NODE` in `env`) and still chooses the runtime, waits for the daemon, checks its version and tries
|
|
59
|
+
the next runtime; return the process (anything with `once('exit')`) so a failed one is left at once. An Electron app
|
|
60
|
+
with its `RunAsNode` fuse off uses `utilityProcess.fork(bin, args, { env, stdio: 'pipe' })`; type servers then run
|
|
61
|
+
in worker threads of the daemon, and the app asks the daemon to stop (`child.kill()`, then a bounded wait for
|
|
62
|
+
`exit`) before it quits, so `daemon.json` and the lock do not stay behind
|
|
63
|
+
([runtime guide](../../docs/integrating/runtime.md#electron-apps-with-the-runasnode-fuse-off)).
|
|
64
|
+
|
|
65
|
+
## The `Harness` object
|
|
66
|
+
|
|
67
|
+
| Member | Does |
|
|
68
|
+
| --- | --- |
|
|
69
|
+
| `ready()` | connects now (starting the daemon unless `autoStart: false`) |
|
|
70
|
+
| `connected`, `features`, `client` | the state, the daemon's features, the raw `HarnessClient` |
|
|
71
|
+
| `attach`, `status`, `detach`, `rename` | sessions |
|
|
72
|
+
| `tools()`, `call(name, args, caller)` | the tools |
|
|
73
|
+
| `wrote(paths, caller)` | files the agent wrote with its own tools |
|
|
74
|
+
| `open(url, caller)` | shows an artifact (through your `open` when you show pages) |
|
|
75
|
+
| `view(url)` | the addresses to show one of this daemon's artifacts that the person opened in your app, with no session; shows nothing by itself (feature `view.open`; a remote page goes through `allowRemote`, `not_granted` when refused) |
|
|
76
|
+
| `owns(args)` | whether a tool call is about an `open-artifacts://` link |
|
|
77
|
+
| `viewUrl(url)`, `publicUrl(url)` | the local Shell page, and the site address when published |
|
|
78
|
+
| `embedOrigins()` | the origins a view may load (feature `embed.origins`) |
|
|
79
|
+
| `shellCommand(view, command)` | a host message to a top-level view's Shell (feature `shell.command`) |
|
|
80
|
+
| `context(url, caller)`, `contextBlock(context)` | what the person selected on the page, as prompt text (feature `view.context`) |
|
|
81
|
+
| `saveThumbnail(url, jpeg)` | a thumbnail for the library |
|
|
82
|
+
| `installSkill({ dir, … })`, `commands()` | the skill file and the command menu (features `skill.get`, `commands.list`; rendered by the kit without them). `opens` (`host` \| `agent-browser` \| `system` \| `link`) sets how the skill tells the agent to show a page; left out, `host` when you pass `open` (the daemon's rendering and, through `harness.installSkill`, the kit's own), else a general step; the standalone helpers take it only as given ([commands and the skill](../../docs/integrating.md#commands-and-the-skill)) |
|
|
83
|
+
| `runtime.status()`, `runtime.update(version?)` | the runtimes on this computer and which starts; the person's yes to an update (feature `runtime.update`; `update` is `not_granted` when updates are off) |
|
|
84
|
+
| `daemon.restart()` | the person's restart of the daemon: stops it, waits for its process, starts another and connects to it; a second call waits for the same restart; answers the new `daemon.json` without its token. Refused (`invalid_argument`) for a daemon in this process |
|
|
85
|
+
| `daemon.stop()`, `daemon.start()`, `daemon.stopped` | the person's stop: stops the daemon and waits for its process, then does not start it again by itself (no reconnecting; calls that would connect fail with `disconnected`) until `daemon.start()`, `daemon.restart()` or `ready()`; `on('state')` gets `stopped`. Answers `{ stopped, others }`: the daemon it stopped (`null`: none ran) and the other apps connected to it (`null`: unknown), which may start it again ([runtime](../../docs/integrating/runtime.md)). `start()` starts one when none runs and connects; restart, stop and start run one after another |
|
|
86
|
+
| `on('artifact' \| 'shell' \| 'event' \| 'state', listener)` | artifact reports, Shell messages, every daemon event, the connection state (`connected`, `disconnected`: dropped, it reconnects; `stopped`: `daemon.stop()`) |
|
|
87
|
+
| `close()` | closes the connection for good |
|
|
88
|
+
|
|
89
|
+
### Answering pages' model calls
|
|
90
|
+
|
|
91
|
+
`sample: { caps, run }` makes the app a model source for pages' `sample` calls: `hello` declares `caps.sample`, and
|
|
92
|
+
each `sample.create` round goes to `run(round, { onText, signal })`, which resolves `{ text, stop, toolCalls?, model?,
|
|
93
|
+
usage? }`. `onText(delta)` becomes `sample.delta` (only with `caps.stream`); `signal` aborts on `sample.cancel` and when
|
|
94
|
+
the connection drops, and nothing is answered for a cancelled round. Throw an error whose `code` is `rate_limited`,
|
|
95
|
+
`unavailable`, `not_granted`, `session_expired` (the app's sign-in or key was rejected) or `prompt_too_large` to refuse
|
|
96
|
+
for that reason (`SAMPLE_REFUSAL_CODES`); anything else answers `error`. The
|
|
97
|
+
round is not a turn of the session: no history, no session tools. Without `sample` the method is `method_not_found`.
|
|
98
|
+
Walk-through: [docs/integrating/sampling.md](../../docs/integrating/sampling.md).
|
|
99
|
+
|
|
100
|
+
### Lending the app's MCP servers to pages
|
|
101
|
+
|
|
102
|
+
`mcp: { listTools, callTool }` lends the app's MCP servers to pages, which name one as `host:<server>`: `hello`
|
|
103
|
+
declares `caps.mcp` (daemon feature `mcp.proxy`). `listTools({ server?, artifactId? })` resolves `{ servers: [{ server,
|
|
104
|
+
tools, authStatus? }] }`, names without `host:`; keep each tool's `annotations.readOnlyHint`, since a tool without it is
|
|
105
|
+
confirmed before each call. `callTool({ id, server, tool, arguments, artifactId }, { signal })` runs a call the person
|
|
106
|
+
already allowed and resolves the tool's result (`content`, `structuredContent?`, `isError?`; a tool that failed is a
|
|
107
|
+
result with `isError: true`). `signal` aborts on `mcp.cancel` and when the connection drops, and nothing is answered
|
|
108
|
+
then. Throw an error whose `code` is `rate_limited` (with `retryAfterMs`), `needs_reauth`, `server_unavailable` or
|
|
109
|
+
`timeout` to refuse for that reason (`MCP_REFUSAL_CODES`); anything else answers `server_unavailable`. Without `mcp`
|
|
110
|
+
the methods are `method_not_found`. Walk-through: [docs/integrating/connectors.md](../../docs/integrating/connectors.md).
|
|
111
|
+
|
|
112
|
+
### Starting a new session for the person
|
|
113
|
+
|
|
114
|
+
`startSession: ({ text, artifact }) => …` lets the person start a new session of your app from an artifact's page:
|
|
115
|
+
`hello` declares `caps.sessions.start` (daemon feature `session.start`), and the Ask pane of an artifact no session
|
|
116
|
+
owns offers "New session" in your app, also while none of your sessions is attached. The callback gets `text` (the new
|
|
117
|
+
session's first message: what the person asked for, then how to take the artifact over; give it to the agent as it is)
|
|
118
|
+
and `artifact` (`{ id, url, title, type, root }`). Start the session and return within 30 s, without waiting for its
|
|
119
|
+
turn:
|
|
120
|
+
|
|
121
|
+
```ts
|
|
122
|
+
startSession: async ({ text, artifact }) => {
|
|
123
|
+
const session = await myApp.newSession({ title: artifact.title, firstMessage: text });
|
|
124
|
+
return { session: session.id, workspace: session.cwd }; // the id you will attach it with
|
|
125
|
+
},
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
Return `{ session }` when you know the new session's id at once: the daemon makes it the artifact's owner and hands it
|
|
129
|
+
what was sent from the artifact meanwhile. Return nothing when you do not: the session takes the artifact over itself
|
|
130
|
+
(`text` tells it to call `Artifact adopt`). Return `false`, or throw, when no session was started: the person is told.
|
|
131
|
+
It is only ever called because the person picked your app in the page, never by an agent. Without `startSession` the
|
|
132
|
+
method is `method_not_found`. Walk-through:
|
|
133
|
+
[docs/integrating/wake.md](../../docs/integrating/wake.md#starting-a-new-session).
|
|
134
|
+
|
|
135
|
+
`sessionModels: () => ({ models, default? })` next to it lets the person pick the model, and its reasoning effort,
|
|
136
|
+
before the session starts: `hello` declares `caps.sessions.models` (daemon feature `session.models`), and the daemon
|
|
137
|
+
asks each time the person is about to pick your app (answer within 10 s):
|
|
138
|
+
|
|
139
|
+
```ts
|
|
140
|
+
sessionModels: async () => ({
|
|
141
|
+
models: [{ id: 'opus', label: 'Opus', group: 'Anthropic', efforts: [{ id: 'high', label: 'High' }], defaultEffort: 'high' }],
|
|
142
|
+
default: { model: 'opus', effort: 'high' },
|
|
143
|
+
}),
|
|
144
|
+
startSession: async ({ text, artifact, model, effort }) => { /* model and effort: the ids picked, or left out */ },
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
`models[]` are `{ id, label, group?, efforts?, defaultEffort? }` (`SessionModelChoice`), `efforts[]` are
|
|
148
|
+
`{ id, label }`, and `default` is what a new session runs on when nothing is picked. The picked ids come back to
|
|
149
|
+
`startSession` as `model` and `effort`, both left out when the person picked nothing. The daemon shows at most 200
|
|
150
|
+
models and 20 efforts a model, drops entries without a string `id` of at most 200 characters or with an id already
|
|
151
|
+
listed, and does not check the picked ids against your list again: `startSession` refuses a model it does not know
|
|
152
|
+
(`false` or a throw). A throw in `sessionModels` is logged and answered as `{ models: [] }`: the person starts on your
|
|
153
|
+
default. Without `startSession`, `sessionModels` is ignored. Walk-through:
|
|
154
|
+
[docs/integrating/wake.md](../../docs/integrating/wake.md#letting-the-person-pick-the-model).
|
|
155
|
+
|
|
156
|
+
On the raw `HarnessClient`, `handlers` answer the daemon's calls (`wake.deliver`, `host.open`, `shell.event`,
|
|
157
|
+
`sample.create`, `mcp.listTools`, `mcp.callTool`, `session.start`, `session.models`): a handler that throws an `OpenArtifactsError` answers a JSON-RPC error carrying its body (`code`,
|
|
158
|
+
`message`, `fix`, …) in `error.data`, any other throw a bare server error, and a handler that returns `NO_REPLY` sends
|
|
159
|
+
no answer at all (a round the daemon cancelled). `onNotification` takes the daemon's other notifications
|
|
160
|
+
(`sample.cancel`, `mcp.cancel`).
|
|
161
|
+
|
|
162
|
+
A call that needs a feature the daemon does not list throws `unsupported`, fix line `Update the Open Artifacts runtime
|
|
163
|
+
this computer runs.`
|
|
164
|
+
|
|
165
|
+
## Testing an adapter
|
|
166
|
+
|
|
167
|
+
`@openartifactsai/harness-kit/testing` runs a fake daemon in the test process: the Harness API over a real WebSocket on
|
|
168
|
+
an ephemeral port, and `daemon.json` in a temporary home.
|
|
169
|
+
|
|
170
|
+
```ts
|
|
171
|
+
import { startFakeDaemon } from '@openartifactsai/harness-kit/testing';
|
|
172
|
+
|
|
173
|
+
const fake = await startFakeDaemon(); // the real daemon's features; [] plays an older one
|
|
174
|
+
const harness = await createHarness({ harness: 'my-app', home: fake.home, autoStart: false, wake });
|
|
175
|
+
fake.queueInbox('s1', { text: 'Make it blue', source }); // handed to wake by the next attach
|
|
176
|
+
await fake.wake({ session: 's1', text: 'hi' }); // { status } as the adapter answered
|
|
177
|
+
fake.setArtifact({ id: 'art_…', title: 'Deck' }); // also what view.open answers for
|
|
178
|
+
fake.emit({ type: 'artifacts/changed', id: 'art_…' }); // on('artifact') reports it
|
|
179
|
+
fake.drop(); // the adapter reconnects and attaches again
|
|
180
|
+
const round = fake.sample({ turns: [{ role: 'user', content: 'Hi' }] }); // sample.create to your `sample.run`
|
|
181
|
+
await round.result; round.deltas; round.cancel(); // its answer, its sample.delta texts, sample.cancel
|
|
182
|
+
const call = fake.mcpCall({ server: 'notes', tool: 'add_note', arguments: { text: 'Hi' } }); // mcp.callTool to your `mcp.callTool`
|
|
183
|
+
await call.result; call.cancel(); // its answer (rejects a refusal), mcp.cancel
|
|
184
|
+
await fake.startSession({ text: 'Make a deck' }); // session.start to your `startSession`: { started, session? }
|
|
185
|
+
await fake.sessionModels(); // session.models to your `sessionModels`: { models, default? }
|
|
186
|
+
fake.calls; // every call it took, in order
|
|
187
|
+
await fake.close();
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
It answers `skill.get` (the protocol's template for your caps) and `commands.list` (one entry per `types`, default
|
|
191
|
+
`slides`); `onSkill` and `onCommands` replace them, and `handle` answers any other method. More in
|
|
192
|
+
[docs/integrating/testing.md](../../docs/integrating/testing.md).
|
|
193
|
+
|
|
194
|
+
## Entry points
|
|
195
|
+
|
|
196
|
+
- `.`: `createHarness`, `HarnessClient`, `NO_REPLY`, `SAMPLE_REFUSAL_CODES`, `MCP_REFUSAL_CODES`, `ensureDaemon`, `readDaemon`, `daemonHealth`, `restartDaemon`, `stopDaemon`, `api`, `isOlderVersion`, `openArtifactsHome`,
|
|
197
|
+
the runtime choice (`selectRuntime`, `rankRuntimes`, `runtimeCandidates`, …), `remoteGate`, `contextBlock`,
|
|
198
|
+
`installSkill`, `renderSkill`, `commands`.
|
|
199
|
+
- `./testing`: `startFakeDaemon` (with `sample()` and `sampleDeltas` for `sample.create`, `mcpCall()` for `mcp.callTool`, `startSession()` for `session.start`, and `sessionModels()` for `session.models`).
|
|
200
|
+
- `./embed`: browser code with no Node imports, for the app's renderer: `embedArtifact` (a Shell page in an iframe or a
|
|
201
|
+
top-level view; `switcher` hides the Shell's artifact switcher, `onSaved` and `saved` give the page's save state,
|
|
202
|
+
`onModelUse` and `onModelNotice` what the hidden Shell bar's AI mark and notice would show) and
|
|
203
|
+
`embedLibrary` (the home page). Reference: [docs/spec/embed.md](../../docs/spec/embed.md).
|
|
204
|
+
- `./legacy` (also exported from `.`): the names from before 0.23, when Open Artifacts was "Open Artifact", that
|
|
205
|
+
installs still use. `adoptLegacyEnv(env)` copies each `OPEN_ARTIFACT_*` variable to its `OPEN_ARTIFACTS_*` name when
|
|
206
|
+
that one is unset (call it first thing in a process's entry; `ensureDaemon` and `createHarness` also read both).
|
|
207
|
+
`resolveHome()` finds the home: a named home as is; else `~/.agents/open-artifacts`, after renaming
|
|
208
|
+
`~/.agents/open-artifact` to it and leaving a link at the old path when only the old one exists; the old one when
|
|
209
|
+
both are folders (nothing is moved, and `open-artifacts doctor` says so). `resolveHomeDetail()` also says which
|
|
210
|
+
case it was. `withLegacyEnv(env)` gives a child process both spellings, and `defaultHomeWorkspace()` is
|
|
211
|
+
`~/OpenArtifacts`, or `~/OpenArtifact` when only that one exists.
|
package/package.json
CHANGED
|
@@ -1,6 +1,54 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openartifactsai/harness-kit",
|
|
3
|
-
"version": "0.0.0
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.23.0-rc.0",
|
|
4
|
+
"description": "The SDK an agent app uses to integrate Open Artifacts: find or start the local daemon, hold a Harness API connection that reconnects, register the tools, take comment wakes and page opens, and follow the artifacts its sessions make.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"exports": {
|
|
7
|
+
".": {
|
|
8
|
+
"types": "./src/index.d.ts",
|
|
9
|
+
"default": "./src/index.js"
|
|
10
|
+
},
|
|
11
|
+
"./testing": {
|
|
12
|
+
"types": "./src/testing.d.ts",
|
|
13
|
+
"default": "./src/testing.js"
|
|
14
|
+
},
|
|
15
|
+
"./embed": {
|
|
16
|
+
"types": "./src/embed/index.d.ts",
|
|
17
|
+
"default": "./src/embed/index.js"
|
|
18
|
+
},
|
|
19
|
+
"./legacy": {
|
|
20
|
+
"types": "./src/legacy.d.ts",
|
|
21
|
+
"default": "./src/legacy.js"
|
|
22
|
+
},
|
|
23
|
+
"./package.json": "./package.json"
|
|
24
|
+
},
|
|
25
|
+
"files": [
|
|
26
|
+
"src",
|
|
27
|
+
"LICENSE",
|
|
28
|
+
"NOTICE"
|
|
29
|
+
],
|
|
30
|
+
"dependencies": {
|
|
31
|
+
"@openartifactsai/protocol": "0.23.0-rc.0"
|
|
32
|
+
},
|
|
33
|
+
"engines": {
|
|
34
|
+
"node": ">=22.18"
|
|
35
|
+
},
|
|
36
|
+
"sideEffects": false,
|
|
37
|
+
"license": "Apache-2.0",
|
|
38
|
+
"author": {
|
|
39
|
+
"name": "Jim Liu 宝玉",
|
|
40
|
+
"url": "https://github.com/JimLiu"
|
|
41
|
+
},
|
|
42
|
+
"homepage": "https://github.com/openartifactsai/open-artifacts#readme",
|
|
43
|
+
"repository": {
|
|
44
|
+
"type": "git",
|
|
45
|
+
"url": "git+https://github.com/openartifactsai/open-artifacts.git",
|
|
46
|
+
"directory": "packages/harness-kit"
|
|
47
|
+
},
|
|
48
|
+
"bugs": {
|
|
49
|
+
"url": "https://github.com/openartifactsai/open-artifacts/issues"
|
|
50
|
+
},
|
|
51
|
+
"publishConfig": {
|
|
52
|
+
"access": "public"
|
|
53
|
+
}
|
|
54
|
+
}
|
package/src/client.d.ts
ADDED
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A Harness API connection (`/__harness`, JSON-RPC 2.0 over a WebSocket): it says hello, answers the daemon's calls,
|
|
3
|
+
* and when the daemon goes away it reconnects with backoff and attaches its sessions again.
|
|
4
|
+
*
|
|
5
|
+
* Uses the global `WebSocket` (Node ≥ 22, Electron's Node).
|
|
6
|
+
*/
|
|
7
|
+
import { type AdapterCaps, type AdapterToDaemon, type AdapterToDaemonNotifications, type AttachParams, type DaemonCallHandlers, type DaemonState, type DaemonToAdapter, type DaemonToAdapterNotifications, type HarnessEvent, type HelloParams, type HelloResult, type SessionParams, type SessionStatus, type ToolCallResult, type ToolDefinition } from '@openartifactsai/protocol';
|
|
8
|
+
import { type EnsureDaemonOptions } from './daemon.js';
|
|
9
|
+
/**
|
|
10
|
+
* Connection state reported to {@link HarnessClientOptions.onState}: `disconnected` when the connection dropped (the
|
|
11
|
+
* client reconnects by itself), `stopped` when the host stopped the daemon on purpose ({@link HarnessClient.halt}: no
|
|
12
|
+
* reconnecting until it asks again).
|
|
13
|
+
*/
|
|
14
|
+
export type HarnessConnectionState = 'connected' | 'disconnected' | 'stopped';
|
|
15
|
+
/**
|
|
16
|
+
* What a handler returns to send no answer at all (a `sample.create` round the daemon cancelled: the daemon has stopped
|
|
17
|
+
* waiting for it, and an answer would only be noise).
|
|
18
|
+
*/
|
|
19
|
+
export declare const NO_REPLY: unique symbol;
|
|
20
|
+
/** Handlers for the daemon's calls, as {@link HarnessClientOptions.handlers} takes them: each may answer {@link NO_REPLY}. */
|
|
21
|
+
export type ClientCallHandlers = {
|
|
22
|
+
[M in keyof DaemonToAdapter]?: (params: DaemonToAdapter[M]['params']) => Promise<DaemonToAdapter[M]['result'] | typeof NO_REPLY> | DaemonToAdapter[M]['result'] | typeof NO_REPLY;
|
|
23
|
+
};
|
|
24
|
+
/** What else `hello` says besides the harness, its caps and the token. `protocols` defaults to what this kit speaks. */
|
|
25
|
+
export type HelloExtras = Omit<HelloParams, 'harness' | 'token' | 'caps'>;
|
|
26
|
+
/** Options of {@link HarnessClient}. */
|
|
27
|
+
export interface HarnessClientOptions {
|
|
28
|
+
/** The harness name said in `hello`. */
|
|
29
|
+
harness: string;
|
|
30
|
+
caps?: AdapterCaps;
|
|
31
|
+
/** More of `hello`: `kit`, `profile`, `runtime`, `protocols`. */
|
|
32
|
+
hello?: HelloExtras;
|
|
33
|
+
/**
|
|
34
|
+
* Answers the daemon's calls (`wake.deliver`, `host.open`, `shell.event`, `sample.create`). A handler that throws an
|
|
35
|
+
* `OpenArtifactsError` answers its `code` in `error.data`; any other throw answers a bare server error.
|
|
36
|
+
*/
|
|
37
|
+
handlers?: DaemonCallHandlers | ClientCallHandlers;
|
|
38
|
+
/** Takes events; when set, the client subscribes after connecting. */
|
|
39
|
+
onEvent?: (event: HarnessEvent) => void;
|
|
40
|
+
/** Takes the daemon's other notifications (`sample.cancel`); `event` goes to {@link onEvent}. */
|
|
41
|
+
onNotification?: <N extends Exclude<keyof DaemonToAdapterNotifications, 'event'>>(method: N, params: DaemonToAdapterNotifications[N]) => void;
|
|
42
|
+
onState?: (state: HarnessConnectionState) => void;
|
|
43
|
+
/**
|
|
44
|
+
* Called with what `session.attach` answered when the client attached a session again after a reconnect (its
|
|
45
|
+
* `inbox` holds what waited for the session meanwhile).
|
|
46
|
+
*/
|
|
47
|
+
onReattach?: (params: AttachParams, result: AdapterToDaemon['session.attach']['result']) => void | Promise<void>;
|
|
48
|
+
/** Start the daemon when none runs (default `true`). */
|
|
49
|
+
autoStart?: boolean;
|
|
50
|
+
/** Passed to {@link ensureDaemon} (and its `home` to {@link readDaemon}). */
|
|
51
|
+
daemon?: EnsureDaemonOptions;
|
|
52
|
+
/**
|
|
53
|
+
* Delay before reconnecting, ms: `minMs` after a drop, doubling after each failed try up to `maxMs`. Default 2 s
|
|
54
|
+
* each, a steady retry.
|
|
55
|
+
*/
|
|
56
|
+
reconnect?: {
|
|
57
|
+
minMs?: number;
|
|
58
|
+
maxMs?: number;
|
|
59
|
+
};
|
|
60
|
+
/** Diagnostic log. */
|
|
61
|
+
log?: (line: string) => void;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* A Harness API connection. It reconnects when dropped, and says hello and attaches the sessions again.
|
|
65
|
+
*/
|
|
66
|
+
export declare class HarnessClient {
|
|
67
|
+
readonly harness: string;
|
|
68
|
+
/** The daemon this client talks to, once connected. */
|
|
69
|
+
state: DaemonState | null;
|
|
70
|
+
/** What the last `hello` answered (`features` is `[]` from a daemon that does not say). */
|
|
71
|
+
hello: HelloResult | null;
|
|
72
|
+
private readonly options;
|
|
73
|
+
private readonly pending;
|
|
74
|
+
private readonly attached;
|
|
75
|
+
private nextId;
|
|
76
|
+
private closed;
|
|
77
|
+
private subscribed;
|
|
78
|
+
private ready;
|
|
79
|
+
private ws;
|
|
80
|
+
private retry;
|
|
81
|
+
private failures;
|
|
82
|
+
/** While above 0 (a daemon restart), the client does not reconnect by itself. */
|
|
83
|
+
private holding;
|
|
84
|
+
/** The host stopped the daemon ({@link halt}): nothing connects, so nothing starts it, until {@link resume}. */
|
|
85
|
+
private halted;
|
|
86
|
+
constructor(options: HarnessClientOptions);
|
|
87
|
+
/** Whether the connection is up and said hello. */
|
|
88
|
+
get connected(): boolean;
|
|
89
|
+
/** The daemon's features (see `HarnessFeature`), as the last `hello` answered them. */
|
|
90
|
+
get features(): readonly string[];
|
|
91
|
+
/** Whether the host stopped the daemon ({@link halt}) and has not asked for it again ({@link resume}). */
|
|
92
|
+
get stopped(): boolean;
|
|
93
|
+
/**
|
|
94
|
+
* Connects (once); later calls share the same attempt. While {@link stopped} it fails (`disconnected`) without
|
|
95
|
+
* starting the daemon: {@link resume} first.
|
|
96
|
+
*/
|
|
97
|
+
connect(): Promise<HelloResult>;
|
|
98
|
+
private open;
|
|
99
|
+
private onClose;
|
|
100
|
+
/**
|
|
101
|
+
* Tries to connect again later, and keeps trying with backoff until it is connected or closed. The client does this
|
|
102
|
+
* by itself after a drop; call it after a first {@link connect} failed to keep trying in the background.
|
|
103
|
+
*/
|
|
104
|
+
reconnect(): void;
|
|
105
|
+
private onMessage;
|
|
106
|
+
private send;
|
|
107
|
+
/**
|
|
108
|
+
* Sends the daemon a notification on the current connection (`sample.delta`). Returns whether it went out: not while
|
|
109
|
+
* disconnected, and nothing is kept for later.
|
|
110
|
+
*/
|
|
111
|
+
notify<N extends keyof AdapterToDaemonNotifications>(method: N, params: AdapterToDaemonNotifications[N]): boolean;
|
|
112
|
+
/** Calls a daemon method on the current connection (without connecting). */
|
|
113
|
+
private call;
|
|
114
|
+
/** Connects if needed, then calls a daemon method. */
|
|
115
|
+
request<M extends keyof AdapterToDaemon>(method: M, params: AdapterToDaemon[M]['params']): Promise<AdapterToDaemon[M]['result']>;
|
|
116
|
+
/** Turns events on or off; a reconnect keeps the choice. */
|
|
117
|
+
subscribe(on: boolean): Promise<void>;
|
|
118
|
+
/** Attaches a session; a reconnect attaches it again. Returns what waited in its inbox. */
|
|
119
|
+
attach(params: AttachParams): Promise<AdapterToDaemon['session.attach']['result']>;
|
|
120
|
+
/** The session's agent is `running` or `idle` now; a reconnect attaches it with this status. */
|
|
121
|
+
status(params: SessionParams & {
|
|
122
|
+
status: SessionStatus;
|
|
123
|
+
}): Promise<{
|
|
124
|
+
ok: true;
|
|
125
|
+
}>;
|
|
126
|
+
/** Renames a session; a reconnect attaches it with this title. */
|
|
127
|
+
rename(params: SessionParams & {
|
|
128
|
+
title: string;
|
|
129
|
+
}): Promise<{
|
|
130
|
+
ok: true;
|
|
131
|
+
}>;
|
|
132
|
+
/** Detaches a session. */
|
|
133
|
+
detach(params: SessionParams): Promise<{
|
|
134
|
+
ok: true;
|
|
135
|
+
}>;
|
|
136
|
+
/** The tool definitions. */
|
|
137
|
+
tools(): Promise<ToolDefinition[]>;
|
|
138
|
+
/** Calls a tool as `caller`. */
|
|
139
|
+
callTool(name: string, args: Record<string, unknown>, caller?: SessionParams): Promise<ToolCallResult>;
|
|
140
|
+
/**
|
|
141
|
+
* Runs `work` (which stops the daemon and starts another) without reconnecting meanwhile, so the client does not race
|
|
142
|
+
* it to start a daemon; then drops the old connection and connects to the daemon running now, attaching the sessions
|
|
143
|
+
* again. When `work` fails the client goes back to reconnecting by itself.
|
|
144
|
+
*/
|
|
145
|
+
across<T>(work: () => Promise<T>): Promise<{
|
|
146
|
+
result: T;
|
|
147
|
+
hello: HelloResult;
|
|
148
|
+
}>;
|
|
149
|
+
/**
|
|
150
|
+
* Runs `work` (which stops the daemon) and stays off afterwards: no reconnecting, and no call connects (so none starts
|
|
151
|
+
* a daemon), until {@link resume}, {@link across} or a closed client. The connection's end is reported as `stopped`
|
|
152
|
+
* (also when it was already down). A connection attempt under way is waited for first, so it cannot start a daemon
|
|
153
|
+
* after `work`. When `work` fails the client goes back to reconnecting by itself.
|
|
154
|
+
*/
|
|
155
|
+
halt<T>(work: () => Promise<T>): Promise<T>;
|
|
156
|
+
/** Ends {@link halt}: calls may connect (and start the daemon) again. Connects nothing by itself. */
|
|
157
|
+
resume(): void;
|
|
158
|
+
/** Closes the connection for good. */
|
|
159
|
+
close(): void;
|
|
160
|
+
}
|