@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/src/harness.d.ts
ADDED
|
@@ -0,0 +1,383 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `createHarness`: everything an agent app's adapter does with the daemon, behind one object.
|
|
3
|
+
*
|
|
4
|
+
* It finds or starts the daemon, connects, and keeps the connection: a dropped one comes back with backoff, attaches
|
|
5
|
+
* every session again and hands what waited in their inboxes to the `wake` callback. The app answers two callbacks,
|
|
6
|
+
* `wake` (give a message to a session) and `open` (show a page in its own UI), and calls the rest: sessions, tools,
|
|
7
|
+
* files its agent wrote, and the artifacts its sessions make.
|
|
8
|
+
*/
|
|
9
|
+
import { type AdapterCaps, type AdapterSampleCaps, type AttachParams, type CommandEntry, type EmbedOriginsResult, type DaemonState, type HarnessEvent, type HostToShell, type ShellEventParams, type HarnessPolicy, type HarnessProfile, type HarnessRuntime, type HarnessSampleCreateParams, type HarnessSampleCreateResult, type HelloResult, type InboxMessage, type RuntimeStatus, type RuntimeUpdateResult, type SessionModelsResult, type SessionParams, type SessionStartParams, type SessionStatus, type ToolCallResult, type ToolDefinition, type WakeDeliverParams, type WakeDeliverResult, type WakeDeliverStatus } from '@openartifactsai/protocol';
|
|
10
|
+
import { HarnessClient, type HarnessConnectionState } from './client.js';
|
|
11
|
+
import { type EnsureDaemonOptions } from './daemon.js';
|
|
12
|
+
import { type InstallSkillOptions, type InstallSkillResult } from './skill.js';
|
|
13
|
+
import { type ArtifactContext } from './context.js';
|
|
14
|
+
import { type AllowRemote, type RemotePage, type RemotePagePolicy } from './embed/remote.js';
|
|
15
|
+
import { type McpOptions } from './mcp.js';
|
|
16
|
+
/** This kit's name and version, said in `hello` (`kit`). */
|
|
17
|
+
export declare const KIT: {
|
|
18
|
+
readonly name: "@openartifactsai/harness-kit";
|
|
19
|
+
readonly version: string;
|
|
20
|
+
};
|
|
21
|
+
/** What the `wake` callback answers: a status, or a status with the session that took the message instead. */
|
|
22
|
+
export type WakeAnswer = WakeDeliverStatus | WakeDeliverResult;
|
|
23
|
+
/** What the `open` callback gets: show this artifact for this session. */
|
|
24
|
+
export interface OpenRequest {
|
|
25
|
+
/** The session that asked, or `null` when no session did. */
|
|
26
|
+
session: string | null;
|
|
27
|
+
/** `open-artifacts://artifact/<id>`. */
|
|
28
|
+
url: string;
|
|
29
|
+
/** The Shell page. */
|
|
30
|
+
viewUrl: string;
|
|
31
|
+
/** What a top-level view loads: `viewUrl` with a view ticket when the daemon gave one, else `viewUrl`. */
|
|
32
|
+
embedUrl: string;
|
|
33
|
+
/** The view ticket, when the daemon gave one. */
|
|
34
|
+
view?: string;
|
|
35
|
+
title?: string;
|
|
36
|
+
/**
|
|
37
|
+
* The artifact's type is on another computer: its page comes from these origins. Present only once the host's
|
|
38
|
+
* `embed.remote` policy let it through (`allow`, or `ask` answered yes); the host lets these origins in to show it.
|
|
39
|
+
*/
|
|
40
|
+
remote?: RemotePage;
|
|
41
|
+
}
|
|
42
|
+
/** An artifact as `on('artifact')` reports it. */
|
|
43
|
+
export interface HarnessArtifact {
|
|
44
|
+
/** `open-artifacts://artifact/<id>`: what to store in messages and cards (it does not change with the daemon's port). */
|
|
45
|
+
url: string;
|
|
46
|
+
id: string;
|
|
47
|
+
title: string;
|
|
48
|
+
/** The type id. */
|
|
49
|
+
type: string;
|
|
50
|
+
/** The local Shell page (also when it is published: the person's own copy); `null` once removed. */
|
|
51
|
+
viewUrl: string | null;
|
|
52
|
+
/** Its address on the site it is published to, or `null` when it is not published. */
|
|
53
|
+
publicUrl?: string | null;
|
|
54
|
+
/** The Library API address of its thumbnail, when one was captured. */
|
|
55
|
+
thumbnail: string | null;
|
|
56
|
+
updatedAt: string;
|
|
57
|
+
}
|
|
58
|
+
/** What changed about an artifact. */
|
|
59
|
+
export type ArtifactChange = 'created' | 'updated' | 'removed';
|
|
60
|
+
/** An `on('artifact')` report. */
|
|
61
|
+
export interface ArtifactReport {
|
|
62
|
+
/** The session of this harness that owns the artifact, or `null` when it is not one of this harness's sessions. */
|
|
63
|
+
session: string | null;
|
|
64
|
+
/** That session's workspace, when known. */
|
|
65
|
+
workspace: string | null;
|
|
66
|
+
artifact: HarnessArtifact;
|
|
67
|
+
change: ArtifactChange;
|
|
68
|
+
/** Who changed it, as the daemon said (`agent`, or the person's page). */
|
|
69
|
+
author?: string;
|
|
70
|
+
/** The files that changed, when the daemon said. */
|
|
71
|
+
paths?: string[];
|
|
72
|
+
}
|
|
73
|
+
/** One model round, as {@link SampleOptions.run} gets it: `sample.create`'s params. */
|
|
74
|
+
export type SampleRound = HarnessSampleCreateParams;
|
|
75
|
+
/** What {@link SampleOptions.run} resolves with: `sample.create`'s answer. */
|
|
76
|
+
export type SampleRoundResult = HarnessSampleCreateResult;
|
|
77
|
+
/** The second argument of {@link SampleOptions.run}. */
|
|
78
|
+
export interface SampleRunContext {
|
|
79
|
+
/**
|
|
80
|
+
* Hands over more of the answer as it is written (the delta, not the whole). Sent as `sample.delta` when
|
|
81
|
+
* `caps.stream` is true, else dropped; dropped too once the round ended or was cancelled. Empty strings are dropped.
|
|
82
|
+
*/
|
|
83
|
+
onText(delta: string): void;
|
|
84
|
+
/** Aborts when the daemon cancels the round (`sample.cancel`) or the connection drops: stop, and spend no more. */
|
|
85
|
+
signal: AbortSignal;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* The `sample` option of {@link createHarness}: the app answers a page's model calls with its own model, one round at
|
|
89
|
+
* a time. The daemon keeps consent, limits, the cache and the tool loop; `run` only answers the round it is given.
|
|
90
|
+
*/
|
|
91
|
+
export interface SampleOptions {
|
|
92
|
+
/** What `hello` declares as `caps.sample`. */
|
|
93
|
+
caps: AdapterSampleCaps;
|
|
94
|
+
/**
|
|
95
|
+
* Answers one round. Throw an error whose `code` is one of {@link SAMPLE_REFUSAL_CODES} to refuse for that reason
|
|
96
|
+
* (`session_expired`: the app's own sign-in or key was rejected; `prompt_too_large`: the round does not fit the
|
|
97
|
+
* model's context); any other throw is a failed round. Several rounds may run at once.
|
|
98
|
+
*/
|
|
99
|
+
run(round: SampleRound, context: SampleRunContext): Promise<SampleRoundResult>;
|
|
100
|
+
}
|
|
101
|
+
/** The codes a `sample.create` refusal may carry; anything else a `run` throws answers `error`. */
|
|
102
|
+
export declare const SAMPLE_REFUSAL_CODES: readonly ["rate_limited", "unavailable", "not_granted", "session_expired", "prompt_too_large"];
|
|
103
|
+
/** Options of {@link createHarness}. */
|
|
104
|
+
export interface HarnessOptions {
|
|
105
|
+
/** The harness name (`^[a-z0-9][a-z0-9._-]{0,40}$`). */
|
|
106
|
+
harness: string;
|
|
107
|
+
/** What the harness calls its agent. */
|
|
108
|
+
agentName?: string;
|
|
109
|
+
/** The harness's command names, e.g. `['artifact']`. */
|
|
110
|
+
commands?: string[];
|
|
111
|
+
/** Capabilities beyond what the callbacks and options imply (see {@link createHarness}). */
|
|
112
|
+
caps?: AdapterCaps;
|
|
113
|
+
/** The harness's rules that are data (the daemon writes its instructions by them, or refuses calls). */
|
|
114
|
+
policy?: HarnessPolicy;
|
|
115
|
+
/** The harness's rules that are only text. */
|
|
116
|
+
rules?: string;
|
|
117
|
+
/** More of the harness's profile, reported in `hello` (`nudge` is never sent). */
|
|
118
|
+
profile?: Omit<Partial<HarnessProfile>, 'nudge' | 'name' | 'source'>;
|
|
119
|
+
/** The runtime the harness carries (`@openartifactsai/cli`): it starts the daemon when none runs. */
|
|
120
|
+
runtime?: HarnessRuntime;
|
|
121
|
+
/**
|
|
122
|
+
* How the harness embeds pages, when it shows them itself (`open`). `remote` is what it does with a remote type's
|
|
123
|
+
* page (one on another computer): `allow` shows it, `deny` answers not-opened without calling `open`, `ask` (the
|
|
124
|
+
* default) asks `allowRemote`, keeping a yes per origin for the life of the process and asking again after a no.
|
|
125
|
+
*/
|
|
126
|
+
embed?: {
|
|
127
|
+
origins: string[];
|
|
128
|
+
mode?: 'frame' | 'view';
|
|
129
|
+
remote?: RemotePagePolicy;
|
|
130
|
+
};
|
|
131
|
+
/** Asked under `embed.remote: 'ask'` before a remote type's page is shown; without it the answer is no. */
|
|
132
|
+
allowRemote?: AllowRemote;
|
|
133
|
+
/** An Open Artifacts home of the harness's own: its own daemon and library, apart from the other apps'. */
|
|
134
|
+
home?: string;
|
|
135
|
+
/** Start the daemon when none runs (default `true`). */
|
|
136
|
+
autoStart?: boolean;
|
|
137
|
+
/** More options for starting the daemon (`env`, `bin`, `timeoutMs`, and `spawn` for a host that starts the process itself). */
|
|
138
|
+
daemon?: EnsureDaemonOptions;
|
|
139
|
+
/** Gives a message to a session (`wake.deliver`); see {@link createHarness}. */
|
|
140
|
+
wake?: (params: WakeDeliverParams) => WakeAnswer | Promise<WakeAnswer>;
|
|
141
|
+
/** Shows a page in the harness's own UI (`host.open`). `false`: it was not shown. */
|
|
142
|
+
open?: (request: OpenRequest) => boolean | void | Promise<boolean | void>;
|
|
143
|
+
/**
|
|
144
|
+
* Answers a page's model calls with the app's own model (`sample.create`, feature `sample.create`); `hello` declares
|
|
145
|
+
* `caps.sample` from it. Without it the adapter declares no `sample` and refuses the call as an unknown method.
|
|
146
|
+
*/
|
|
147
|
+
sample?: SampleOptions;
|
|
148
|
+
/**
|
|
149
|
+
* Lends the app's own MCP servers to pages as `host:<server>` (feature `mcp.proxy`); `hello` declares `caps.mcp`.
|
|
150
|
+
* The daemon asks the person before any call reaches `callTool`.
|
|
151
|
+
*/
|
|
152
|
+
mcp?: McpOptions;
|
|
153
|
+
/**
|
|
154
|
+
* Starts a new session of the app whose first turn is `text` (`session.start`, feature `session.start`); `hello`
|
|
155
|
+
* declares `caps.sessions.start` from it, and the person is then offered the app ("New session") for an artifact no
|
|
156
|
+
* session owns, also while none of its sessions is attached. Only ever called because the person picked the app in
|
|
157
|
+
* the artifact's page. Return the new session's id (and its `workspace`) when the app knows it at once: the daemon
|
|
158
|
+
* makes that session the artifact's owner; without an id, the session takes the artifact over itself, as `text`
|
|
159
|
+
* tells it to. `false`, or a throw: no session was started. Answer within 30 s. `model` and `effort` are what the
|
|
160
|
+
* person picked from {@link HarnessOptions.sessionModels} (an id of a model it listed, and one of that model's
|
|
161
|
+
* efforts); both are left out when they picked nothing, and the session then runs on the app's default. Check them
|
|
162
|
+
* against what the app offers now, and return `false` or throw for a model it does not know: the daemon does not.
|
|
163
|
+
*/
|
|
164
|
+
startSession?: (request: {
|
|
165
|
+
text: string;
|
|
166
|
+
artifact: SessionStartParams['artifact'];
|
|
167
|
+
model?: string;
|
|
168
|
+
effort?: string;
|
|
169
|
+
}) => Promise<{
|
|
170
|
+
session?: string;
|
|
171
|
+
workspace?: string;
|
|
172
|
+
} | false | void> | {
|
|
173
|
+
session?: string;
|
|
174
|
+
workspace?: string;
|
|
175
|
+
} | false | void;
|
|
176
|
+
/**
|
|
177
|
+
* The models a session started by {@link HarnessOptions.startSession} can run on, and the reasoning efforts each
|
|
178
|
+
* offers (`session.models`, feature `session.models`); `hello` declares `caps.sessions.models` from it, and the
|
|
179
|
+
* person picks one before the session starts. Asked each time the person is about to pick the app; answer within
|
|
180
|
+
* 10 s. A throw is answered as no models: the person starts the session on the app's default. Without
|
|
181
|
+
* `startSession` it is ignored: nothing is declared and nothing is asked.
|
|
182
|
+
*/
|
|
183
|
+
sessionModels?: () => SessionModelsResult | Promise<SessionModelsResult>;
|
|
184
|
+
/** How long `wake` may take before the daemon is told it failed (and keeps the message), ms. Default 25 s. */
|
|
185
|
+
wakeTimeoutMs?: number;
|
|
186
|
+
/** Reconnect delays, ms: from `minMs` (default 1 s) doubling to `maxMs` (default 30 s). */
|
|
187
|
+
reconnect?: {
|
|
188
|
+
minMs?: number;
|
|
189
|
+
maxMs?: number;
|
|
190
|
+
};
|
|
191
|
+
/** Diagnostic log. */
|
|
192
|
+
log?: (line: string) => void;
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* The runtime calls (feature `runtime.update`): what runtimes this computer has and which starts, and the host's yes
|
|
196
|
+
* to an update. Both connect first, and throw `unsupported` when the daemon does not list the feature.
|
|
197
|
+
*/
|
|
198
|
+
export interface HarnessRuntimeCalls {
|
|
199
|
+
/** `runtime.status`: the runtimes here, the update policy, the last check and a waiting switch. */
|
|
200
|
+
status(): Promise<RuntimeStatus>;
|
|
201
|
+
/**
|
|
202
|
+
* `runtime.update`: downloads the newest compatible runtime (or `version`) into the shared folder; the daemon
|
|
203
|
+
* switches once idle. Refused (`not_granted`) when updates are off for the whole computer.
|
|
204
|
+
*/
|
|
205
|
+
update(version?: string): Promise<RuntimeUpdateResult>;
|
|
206
|
+
}
|
|
207
|
+
/** Another app's connection to the daemon, as {@link HarnessDaemonCalls.stop} found it (the daemon's `harnesses`). */
|
|
208
|
+
export interface HarnessDaemonPeer {
|
|
209
|
+
/** The daemon's id of the connection. */
|
|
210
|
+
connection: string;
|
|
211
|
+
/** The harness name it said in `hello`. */
|
|
212
|
+
harness: string;
|
|
213
|
+
/** Its display name (the harness profile's title, else the name). */
|
|
214
|
+
title: string;
|
|
215
|
+
/** An HTTP polling adapter rather than a WebSocket. */
|
|
216
|
+
polling: boolean;
|
|
217
|
+
/** How many sessions were attached through it. */
|
|
218
|
+
sessions: number;
|
|
219
|
+
}
|
|
220
|
+
/** What {@link HarnessDaemonCalls.stop} did. */
|
|
221
|
+
export interface HarnessDaemonStopResult {
|
|
222
|
+
/** The daemon it stopped (`pid`, `url`, `version`; not its token), or `null` when none ran. */
|
|
223
|
+
stopped: Omit<DaemonState, 'token'> | null;
|
|
224
|
+
/**
|
|
225
|
+
* The other connections the daemon had when it was stopped (this harness's own left out), or `null` when that could
|
|
226
|
+
* not be read (no daemon ran, or an older daemon). They reconnect, and one with `autoStart` (the default) starts the
|
|
227
|
+
* daemon again: the person's "stop" holds only while no other app wants it. Not listed: command lines, MCP bridges
|
|
228
|
+
* and hooks, which start a daemon whenever they run.
|
|
229
|
+
*/
|
|
230
|
+
others: HarnessDaemonPeer[] | null;
|
|
231
|
+
}
|
|
232
|
+
/** The daemon itself, as the harness reaches it (`Harness.daemon`). */
|
|
233
|
+
export interface HarnessDaemonCalls {
|
|
234
|
+
/**
|
|
235
|
+
* Restarts the daemon of the harness's home: stops it, waits for its process to exit, starts one (the newest
|
|
236
|
+
* compatible runtime, as a first start does) and reconnects, attaching the sessions again. With no daemon running it
|
|
237
|
+
* only starts one, also under `autoStart: false`. Resolves with the new daemon (its `pid`, `url`, `version`; not its
|
|
238
|
+
* token) once the harness has said hello to it. Not inside an agent's own command: it is the person's to ask for.
|
|
239
|
+
*/
|
|
240
|
+
restart(): Promise<Omit<DaemonState, 'token'>>;
|
|
241
|
+
/**
|
|
242
|
+
* The person's stop: stops the daemon of the harness's home and waits for its process to exit; from then on this
|
|
243
|
+
* harness does not start it again by itself (no reconnecting, and calls that would connect fail with `disconnected`),
|
|
244
|
+
* until {@link start}, {@link restart} or `Harness.ready()`. `on('state')` gets `stopped` (not `disconnected`), and
|
|
245
|
+
* {@link stopped} is true. Resolves with the daemon it stopped (`null`: none ran) and the other apps connected to it.
|
|
246
|
+
* Refused (`invalid_argument`) for a daemon in this process; one that does not exit in time fails (`daemon_failed`) and
|
|
247
|
+
* the harness goes back to reconnecting. Not inside an agent's own command: it is the person's to ask for.
|
|
248
|
+
*/
|
|
249
|
+
stop(): Promise<HarnessDaemonStopResult>;
|
|
250
|
+
/**
|
|
251
|
+
* Starts the daemon of the harness's home (the newest compatible runtime, also under `autoStart: false`) when none
|
|
252
|
+
* runs, and connects to it, attaching the sessions again: the second half of {@link restart}. Ends a {@link stop}.
|
|
253
|
+
* Resolves with the daemon (`pid`, `url`, `version`; not its token) once the harness has said hello to it.
|
|
254
|
+
*/
|
|
255
|
+
start(): Promise<Omit<DaemonState, 'token'>>;
|
|
256
|
+
/** Whether this harness stopped the daemon ({@link stop}) and has not started it again (another app may have). */
|
|
257
|
+
readonly stopped: boolean;
|
|
258
|
+
}
|
|
259
|
+
/** The connection to the daemon, as {@link createHarness} returns it. */
|
|
260
|
+
export interface Harness {
|
|
261
|
+
/** The underlying connection, for calls the kit does not wrap (`client.request(method, params)`). */
|
|
262
|
+
readonly client: HarnessClient;
|
|
263
|
+
/** Whether the connection is up. */
|
|
264
|
+
readonly connected: boolean;
|
|
265
|
+
/** The daemon's features (see `HarnessFeature`); empty while not connected. */
|
|
266
|
+
readonly features: readonly string[];
|
|
267
|
+
/**
|
|
268
|
+
* Connects now if it is not connected (starting the daemon unless `autoStart` is false). After `daemon.stop()` it is
|
|
269
|
+
* the person's ask for the daemon again: it ends the stop.
|
|
270
|
+
*/
|
|
271
|
+
ready(): Promise<HelloResult>;
|
|
272
|
+
/**
|
|
273
|
+
* Attaches a session; a reconnect attaches it again. What waited in its inbox goes to the `wake` callback; the
|
|
274
|
+
* answer's `inbox` holds what the callback did not take (all of it without a callback). What the callback does not
|
|
275
|
+
* take on a reconnect's attach goes back to the session's inbox (`inbox.return`), so the session's next tool call,
|
|
276
|
+
* wait or attach has it; a daemon without that feature leaves it with the kit, which adds it to the session's next
|
|
277
|
+
* {@link Harness.call} (or this attach's `inbox`).
|
|
278
|
+
*/
|
|
279
|
+
attach(params: AttachParams): Promise<{
|
|
280
|
+
key: string;
|
|
281
|
+
inbox: InboxMessage[];
|
|
282
|
+
}>;
|
|
283
|
+
/** The session's agent is `running` or `idle` now. */
|
|
284
|
+
status(session: string | SessionParams, status: SessionStatus): Promise<void>;
|
|
285
|
+
/** Detaches a session. */
|
|
286
|
+
detach(session: string | SessionParams): Promise<void>;
|
|
287
|
+
/** Renames a session. */
|
|
288
|
+
rename(session: string | SessionParams, title: string): Promise<void>;
|
|
289
|
+
/** The tool definitions: the daemon's when connected, else the ones this kit carries. */
|
|
290
|
+
tools(): Promise<ToolDefinition[]>;
|
|
291
|
+
/** Calls a tool for a session. */
|
|
292
|
+
call(name: string, args: Record<string, unknown>, caller?: SessionParams): Promise<ToolCallResult>;
|
|
293
|
+
/** The agent wrote these files (absolute paths) with its own tools. */
|
|
294
|
+
wrote(paths: string[], caller?: SessionParams): Promise<{
|
|
295
|
+
ok: true;
|
|
296
|
+
artifacts?: string[];
|
|
297
|
+
}>;
|
|
298
|
+
/** Shows an artifact for a session (through `open`, when the harness shows pages). */
|
|
299
|
+
open(url: string, options?: SessionParams): Promise<{
|
|
300
|
+
opened: boolean;
|
|
301
|
+
view_url?: string;
|
|
302
|
+
}>;
|
|
303
|
+
/** Whether a tool call is about an Open Artifacts link (`url` or `type_url` is `open-artifacts://…`). */
|
|
304
|
+
owns(args: Record<string, unknown> | null | undefined): boolean;
|
|
305
|
+
/**
|
|
306
|
+
* The artifact's local Shell page (stable while the daemon keeps its port; also for a published artifact), or `null`
|
|
307
|
+
* when the daemon does not know it. The published address is {@link Harness.publicUrl}.
|
|
308
|
+
*/
|
|
309
|
+
viewUrl(url: string): Promise<string | null>;
|
|
310
|
+
/** The artifact's address on the site it is published to, or `null` (not published, or unknown). */
|
|
311
|
+
publicUrl(url: string): Promise<string | null>;
|
|
312
|
+
/** The origins a host must let in to show pages (feature `embed.origins`); `on('event')` gets `embed/origins` changes. */
|
|
313
|
+
embedOrigins(): Promise<EmbedOriginsResult>;
|
|
314
|
+
/**
|
|
315
|
+
* A view of one of the daemon's artifacts for the host to show on its own, with no tool call and no session (feature
|
|
316
|
+
* `view.open`): the person picked it in the host's own library. `url`: `open-artifacts://artifact/<id>` or the
|
|
317
|
+
* daemon's own `/a/<id>` address; any other address is refused (`invalid_argument`), an artifact it does not keep is
|
|
318
|
+
* `not_found`. The answer is what `open` gets (`session: null`; `view` and the ticket on `embedUrl` for an
|
|
319
|
+
* `embed.mode: 'view'` harness). A remote type's page passes the `embed.remote` policy first: refused, it throws
|
|
320
|
+
* `not_granted`.
|
|
321
|
+
*/
|
|
322
|
+
view(url: string): Promise<OpenRequest>;
|
|
323
|
+
/** Sends a host message to the Shell of a top-level view this harness opened (feature `shell.command`). */
|
|
324
|
+
shellCommand(view: string, command: HostToShell): Promise<void>;
|
|
325
|
+
/**
|
|
326
|
+
* What the person selected on the artifact's page, read as its owner session (feature `view.context`); turn it into
|
|
327
|
+
* prompt text with {@link Harness.contextBlock}. `on('event')` gets `view/context` when it changes (best effort).
|
|
328
|
+
*/
|
|
329
|
+
context(url: string, options?: {
|
|
330
|
+
session?: string | null;
|
|
331
|
+
workspace?: string | null;
|
|
332
|
+
}): Promise<ArtifactContext>;
|
|
333
|
+
/** The prompt block of a context (see `contextBlock`): `''` when there is nothing to say. */
|
|
334
|
+
contextBlock(context: ArtifactContext | null | undefined): string;
|
|
335
|
+
/** Saves a captured thumbnail (JPEG bytes) for the artifact, for libraries and cards. */
|
|
336
|
+
saveThumbnail(url: string, jpeg: Uint8Array): Promise<void>;
|
|
337
|
+
/** What the Shell of a top-level view this harness opened says (`shell.event`). Returns a function that stops. */
|
|
338
|
+
on(event: 'shell', listener: (event: ShellEventParams) => void): () => void;
|
|
339
|
+
/** Reports artifacts created, changed or removed. Returns a function that stops. */
|
|
340
|
+
on(event: 'artifact', listener: (report: ArtifactReport) => void): () => void;
|
|
341
|
+
/** Every event the daemon sends. Returns a function that stops. */
|
|
342
|
+
on(event: 'event', listener: (event: HarnessEvent) => void): () => void;
|
|
343
|
+
/**
|
|
344
|
+
* The connection went up (`connected`), dropped (`disconnected`: it reconnects by itself) or ended with the person's
|
|
345
|
+
* `daemon.stop()` (`stopped`). Returns a function that stops.
|
|
346
|
+
*/
|
|
347
|
+
on(event: 'state', listener: (state: HarnessConnectionState) => void): () => void;
|
|
348
|
+
/**
|
|
349
|
+
* Writes the skill for this harness into `<dir>/<command>/SKILL.md` (rendered by the daemon, `skill.get`, else by
|
|
350
|
+
* this kit), only when it changed; again after a reconnect to another runtime.
|
|
351
|
+
*/
|
|
352
|
+
installSkill(options: InstallSkillOptions): Promise<InstallSkillResult>;
|
|
353
|
+
/** One command per installed type, for the harness's command menu (`commands.list`; `[]` without it). */
|
|
354
|
+
commands(options?: {
|
|
355
|
+
command?: string;
|
|
356
|
+
locale?: string;
|
|
357
|
+
}): Promise<CommandEntry[]>;
|
|
358
|
+
/** The runtime's status and updates (feature `runtime.update`); `on('event')` gets `runtime/update` when one exists. */
|
|
359
|
+
readonly runtime: HarnessRuntimeCalls;
|
|
360
|
+
/** The daemon process: restart, stop or start it. */
|
|
361
|
+
readonly daemon: HarnessDaemonCalls;
|
|
362
|
+
/** Closes the connection for good. */
|
|
363
|
+
close(): void;
|
|
364
|
+
}
|
|
365
|
+
/** Whether a tool call is about an Open Artifacts link (`url` or `type_url`), so a harness with its own tools can route it. */
|
|
366
|
+
export declare function ownsCall(args: Record<string, unknown> | null | undefined): boolean;
|
|
367
|
+
/**
|
|
368
|
+
* Connects an agent app to the daemon. Resolves once the first connection attempt is over: when it failed (no daemon
|
|
369
|
+
* and `autoStart: false`, say), the harness keeps trying in the background and calls connect on demand.
|
|
370
|
+
*
|
|
371
|
+
* What `hello` says follows from the options: `caps.wake` when there is a `wake` callback, `caps.open` when there is
|
|
372
|
+
* an `open` callback (`{ embed, origins }` with `embed`), `caps.commands` from `commands`, `caps.agentName` from
|
|
373
|
+
* `agentName`, `caps.sample` from `sample`, `caps.mcp` from `mcp`, `caps.sessions.start` when there is a `startSession`
|
|
374
|
+
* callback (and `caps.sessions.models` when there is a `sessionModels` one too); `options.caps` adds the rest (`tools`, `library`, `wake.resume`, `wake.mode`). The profile carries
|
|
375
|
+
* `agentName`, `commands`, `policy`, `rules`, the caps and `options.profile`.
|
|
376
|
+
*
|
|
377
|
+
* `wake` answers how it handed the message over: `resumed` (started a turn), `delivered` (put it into the running
|
|
378
|
+
* turn), `drafted` (put it in the session's draft, for a harness whose `caps.wake.mode` is `draft`), `held` (left in
|
|
379
|
+
* the inbox: the app starts the session's turn itself, so the daemon does not nudge it; sent as `failed` to a daemon
|
|
380
|
+
* without the `wake.held` feature) or `failed` (the daemon keeps it for later). It may name the session that took it instead: `{ status, session }`. A callback that
|
|
381
|
+
* throws, or takes longer than `wakeTimeoutMs`, answers `failed`.
|
|
382
|
+
*/
|
|
383
|
+
export declare function createHarness(options: HarnessOptions): Promise<Harness>;
|