@open-artifact/harness-kit 0.0.0-stage → 0.14.1
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 +102 -2
- package/package.json +48 -4
- package/src/client.d.ts +110 -0
- package/src/client.js +272 -0
- package/src/context.d.ts +31 -0
- package/src/context.js +61 -0
- package/src/daemon.d.ts +139 -0
- package/src/daemon.js +219 -0
- package/src/embed/index.d.ts +183 -0
- package/src/embed/index.js +343 -0
- package/src/embed/remote.d.ts +39 -0
- package/src/embed/remote.js +51 -0
- package/src/harness.d.ts +237 -0
- package/src/harness.js +426 -0
- package/src/index.d.ts +18 -0
- package/src/index.js +17 -0
- package/src/runtimes.d.ts +138 -0
- package/src/runtimes.js +357 -0
- package/src/skill.d.ts +58 -0
- package/src/skill.js +88 -0
- package/src/testing-ws.d.ts +35 -0
- package/src/testing-ws.js +173 -0
- package/src/testing.d.ts +143 -0
- package/src/testing.js +424 -0
package/src/daemon.js
ADDED
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Finding and starting the local daemon, and calling its Library API.
|
|
3
|
+
*
|
|
4
|
+
* One daemon runs per Open Artifact home (`~/.agents/open-artifact`, or `$OPEN_ARTIFACT_HOME`); it writes where it
|
|
5
|
+
* listens and its token to `daemon.json` there. Uses the global `fetch` (Node ≥ 22, Electron's Node).
|
|
6
|
+
*
|
|
7
|
+
* Which runtime starts it is chosen in `runtimes.ts` (design 10.1): the newest compatible one among the caller's own,
|
|
8
|
+
* the ones adapters registered and the shared ones. `$OPEN_ARTIFACT_DAEMON_BIN` and an explicit `bin` skip the choice.
|
|
9
|
+
*/
|
|
10
|
+
import { spawn } from 'node:child_process';
|
|
11
|
+
import { closeSync, mkdirSync, openSync, readFileSync } from 'node:fs';
|
|
12
|
+
import { homedir } from 'node:os';
|
|
13
|
+
import { join, resolve } from 'node:path';
|
|
14
|
+
import { OpenArtifactError, PROTOCOL_MAX, PROTOCOL_MIN } from '@open-artifact/protocol';
|
|
15
|
+
import { compareVersions, rankRuntimes, readRuntimePin, realOrResolved, runtimeCandidates, runtimeEnv, within } from "./runtimes.js";
|
|
16
|
+
/**
|
|
17
|
+
* The Open Artifact home: `home` when given, else `$OPEN_ARTIFACT_HOME`, else `~/.agents/open-artifact`. A leading `~`
|
|
18
|
+
* is the home folder.
|
|
19
|
+
*/
|
|
20
|
+
export function openArtifactHome(home) {
|
|
21
|
+
const path = home || process.env.OPEN_ARTIFACT_HOME || '~/.agents/open-artifact';
|
|
22
|
+
if (path === '~')
|
|
23
|
+
return homedir();
|
|
24
|
+
return resolve(path.startsWith('~/') ? join(homedir(), path.slice(2)) : path);
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Whether version `a` is older than `b`, by major.minor.patch only: a pre-release (a local build) is not replaced by
|
|
28
|
+
* its own release. Choosing among runtimes uses full semver order (`compareVersions`).
|
|
29
|
+
*/
|
|
30
|
+
export function isOlderVersion(a, b) {
|
|
31
|
+
const core = (v) => v.replace(/[-+].*$/, '');
|
|
32
|
+
return compareVersions(core(a), core(b)) < 0;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* The `open-artifact` entry to start when no daemon runs, as far as the kit knows it: `$OPEN_ARTIFACT_DAEMON_BIN`.
|
|
36
|
+
* `undefined` when it is not set; a host then passes `bin` (or `runtime.dir` to `createHarness`).
|
|
37
|
+
*/
|
|
38
|
+
export function defaultDaemonBin() {
|
|
39
|
+
return process.env.OPEN_ARTIFACT_DAEMON_BIN || undefined;
|
|
40
|
+
}
|
|
41
|
+
/** True when a process with this id is alive. */
|
|
42
|
+
function alive(pid) {
|
|
43
|
+
try {
|
|
44
|
+
process.kill(pid, 0);
|
|
45
|
+
return true;
|
|
46
|
+
}
|
|
47
|
+
catch (error) {
|
|
48
|
+
return error.code === 'EPERM';
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* `daemon.json` of the home (see {@link openArtifactHome}) when its process is alive and answers health; `null`
|
|
53
|
+
* otherwise.
|
|
54
|
+
*/
|
|
55
|
+
export async function readDaemon(home) {
|
|
56
|
+
let state = null;
|
|
57
|
+
try {
|
|
58
|
+
state = JSON.parse(readFileSync(join(openArtifactHome(home), 'daemon.json'), 'utf8'));
|
|
59
|
+
}
|
|
60
|
+
catch {
|
|
61
|
+
return null;
|
|
62
|
+
}
|
|
63
|
+
if (!state?.url || !state.pid || !alive(state.pid))
|
|
64
|
+
return null;
|
|
65
|
+
try {
|
|
66
|
+
const response = await fetch(`${state.url}/__open-artifact/health`, { signal: AbortSignal.timeout(1500) });
|
|
67
|
+
const body = (await response.json());
|
|
68
|
+
return body?.openArtifact === 1 ? state : null;
|
|
69
|
+
}
|
|
70
|
+
catch {
|
|
71
|
+
return null;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
/** The entry override in `env`, unless it is the caller's own runtime (a launcher names itself there). */
|
|
75
|
+
function envOverride(env, own) {
|
|
76
|
+
const named = env.OPEN_ARTIFACT_DAEMON_BIN;
|
|
77
|
+
if (!named)
|
|
78
|
+
return undefined;
|
|
79
|
+
if (own?.bin && realOrResolved(own.bin) === realOrResolved(named))
|
|
80
|
+
return undefined;
|
|
81
|
+
if (own?.dir && within(own.dir, named))
|
|
82
|
+
return undefined;
|
|
83
|
+
return named;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* What {@link ensureDaemon} starts for these options: the override when there is one, else the compatible runtimes
|
|
87
|
+
* of the home, newest first (`runtimes.ts`).
|
|
88
|
+
*/
|
|
89
|
+
export function daemonStartPlan(options = {}) {
|
|
90
|
+
const env = options.env ?? process.env;
|
|
91
|
+
const home = openArtifactHome(options.home ?? env.OPEN_ARTIFACT_HOME ?? undefined);
|
|
92
|
+
const override = options.bin ?? envOverride(env, options.own);
|
|
93
|
+
if (override) {
|
|
94
|
+
const version = options.version ?? (options.own?.bin && realOrResolved(options.own.bin) === realOrResolved(override) ? options.own.version : undefined);
|
|
95
|
+
return { tries: [{ bin: override, ...(version ? { version } : {}), env }], ...(version ? { floor: version } : {}), override: true };
|
|
96
|
+
}
|
|
97
|
+
const candidates = runtimeCandidates(home, options.own);
|
|
98
|
+
const ranked = rankRuntimes(candidates, { protocols: options.protocols ?? { min: PROTOCOL_MIN, max: PROTOCOL_MAX }, pin: readRuntimePin(home) });
|
|
99
|
+
const floor = options.own?.version ?? options.version;
|
|
100
|
+
return {
|
|
101
|
+
tries: ranked.slice(0, 3).map((candidate) => ({ bin: candidate.bin, version: candidate.version, env: runtimeEnv(env, candidate, candidates), candidate })),
|
|
102
|
+
...(floor ? { floor } : {}),
|
|
103
|
+
override: false,
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
/** Stops a running daemon and waits until it has gone, so a new one can take its port. */
|
|
107
|
+
async function replaceDaemon(state, timeoutMs) {
|
|
108
|
+
try {
|
|
109
|
+
process.kill(state.pid, 'SIGTERM');
|
|
110
|
+
}
|
|
111
|
+
catch {
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
const deadline = Date.now() + timeoutMs;
|
|
115
|
+
while (alive(state.pid) && Date.now() < deadline)
|
|
116
|
+
await new Promise((done) => setTimeout(done, 100));
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Starts `bin daemon run` in the background for a home, its output appended to `<home>/logs/daemon.out`. Runs with
|
|
120
|
+
* this process's executable (`ELECTRON_RUN_AS_NODE` lets an Electron host's run plain Node).
|
|
121
|
+
*/
|
|
122
|
+
export function startDaemonProcess(bin, options = {}) {
|
|
123
|
+
const env = options.env ?? process.env;
|
|
124
|
+
const logs = join(openArtifactHome(options.home ?? env.OPEN_ARTIFACT_HOME ?? undefined), 'logs');
|
|
125
|
+
mkdirSync(logs, { recursive: true });
|
|
126
|
+
const fd = openSync(join(logs, 'daemon.out'), 'a');
|
|
127
|
+
try {
|
|
128
|
+
const child = spawn(process.execPath, [bin, 'daemon', 'run'], {
|
|
129
|
+
detached: true,
|
|
130
|
+
stdio: ['ignore', fd, fd],
|
|
131
|
+
env: { ...env, ...(options.home ? { OPEN_ARTIFACT_HOME: options.home } : {}), ELECTRON_RUN_AS_NODE: '1' },
|
|
132
|
+
});
|
|
133
|
+
child.on('error', () => undefined);
|
|
134
|
+
child.unref();
|
|
135
|
+
return child;
|
|
136
|
+
}
|
|
137
|
+
finally {
|
|
138
|
+
closeSync(fd);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* The running daemon, started in the background when there is none. The runtime that starts is the newest one
|
|
143
|
+
* compatible with the caller (see {@link daemonStartPlan}); when it exits without starting, the next one is tried. A
|
|
144
|
+
* running daemon older than the caller's own runtime (`own`, or `version` with `bin`) is replaced; the harnesses
|
|
145
|
+
* connected to it reconnect. A newer runtime that is only on disk does not replace a running daemon: the daemon
|
|
146
|
+
* switches to it by itself once idle.
|
|
147
|
+
*/
|
|
148
|
+
export async function ensureDaemon(options = {}) {
|
|
149
|
+
const { timeoutMs = 15_000, env = process.env } = options;
|
|
150
|
+
const home = options.home ?? env.OPEN_ARTIFACT_HOME ?? undefined;
|
|
151
|
+
const running = await readDaemon(home);
|
|
152
|
+
const plan = daemonStartPlan({ ...options, env });
|
|
153
|
+
if (running && (!plan.floor || !isOlderVersion(running.version ?? '0.0.0', plan.floor)))
|
|
154
|
+
return running;
|
|
155
|
+
if (!plan.tries.length) {
|
|
156
|
+
throw new OpenArtifactError('no_daemon', 'No open-artifact daemon is running, and there is no runtime to start one.', {
|
|
157
|
+
fix: 'Set OPEN_ARTIFACT_DAEMON_BIN to the open-artifact entry, or pass bin (createHarness: runtime.dir).',
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
if (running)
|
|
161
|
+
await replaceDaemon(running, 5_000);
|
|
162
|
+
const logFile = join(openArtifactHome(home), 'logs', 'daemon.out');
|
|
163
|
+
const deadline = Date.now() + timeoutMs;
|
|
164
|
+
// What the host's own start threw, per runtime: the error names them when no daemon came up.
|
|
165
|
+
const thrown = [];
|
|
166
|
+
for (const attempt of plan.tries) {
|
|
167
|
+
let exited = false;
|
|
168
|
+
const onExit = () => {
|
|
169
|
+
exited = true;
|
|
170
|
+
};
|
|
171
|
+
if (options.spawn) {
|
|
172
|
+
const start = { bin: attempt.bin, args: ['daemon', 'run'], env: { ...attempt.env, ...(home ? { OPEN_ARTIFACT_HOME: home } : {}) }, logFile };
|
|
173
|
+
delete start.env.ELECTRON_RUN_AS_NODE;
|
|
174
|
+
try {
|
|
175
|
+
mkdirSync(join(openArtifactHome(home), 'logs'), { recursive: true });
|
|
176
|
+
const started = await options.spawn(start);
|
|
177
|
+
if (started && typeof started.once === 'function')
|
|
178
|
+
started.once('exit', onExit);
|
|
179
|
+
}
|
|
180
|
+
catch (error) {
|
|
181
|
+
thrown.push(`${attempt.bin}: ${error?.message ?? String(error)}`);
|
|
182
|
+
continue;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
else {
|
|
186
|
+
startDaemonProcess(attempt.bin, { env: attempt.env, ...(home ? { home } : {}) }).once('exit', onExit);
|
|
187
|
+
}
|
|
188
|
+
while (Date.now() < deadline) {
|
|
189
|
+
await new Promise((done) => setTimeout(done, 150));
|
|
190
|
+
const state = await readDaemon(home);
|
|
191
|
+
if (state)
|
|
192
|
+
return state;
|
|
193
|
+
// It ended without a daemon (a broken runtime): the next one; one that lost a race to another starter is found above.
|
|
194
|
+
if (exited)
|
|
195
|
+
break;
|
|
196
|
+
}
|
|
197
|
+
if (!exited)
|
|
198
|
+
break;
|
|
199
|
+
}
|
|
200
|
+
const state = await readDaemon(home);
|
|
201
|
+
if (state)
|
|
202
|
+
return state;
|
|
203
|
+
const why = thrown.length ? ` The host's start failed: ${thrown.join('; ')}.` : '';
|
|
204
|
+
throw new OpenArtifactError('daemon_failed', `The open-artifact daemon did not start; see ${logFile}.${why}`);
|
|
205
|
+
}
|
|
206
|
+
/** One Library API call (`/api/open-artifact.<name>`) with the daemon token. Returns the parsed JSON body. */
|
|
207
|
+
export async function api(state, name, body, options = {}) {
|
|
208
|
+
const url = new URL(`/api/open-artifact.${name}`, state.url);
|
|
209
|
+
for (const [key, value] of Object.entries(options.query ?? {}))
|
|
210
|
+
if (value !== undefined)
|
|
211
|
+
url.searchParams.set(key, value);
|
|
212
|
+
const response = await fetch(url, {
|
|
213
|
+
method: options.method ?? (body === undefined ? 'GET' : 'POST'),
|
|
214
|
+
headers: { ...options.headers, Authorization: `Bearer ${state.token}`, ...(body !== undefined ? { 'Content-Type': 'application/json' } : {}) },
|
|
215
|
+
...(body !== undefined ? { body: JSON.stringify(body) } : {}),
|
|
216
|
+
...(options.signal ? { signal: options.signal } : {}),
|
|
217
|
+
});
|
|
218
|
+
return (await response.json());
|
|
219
|
+
}
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@open-artifact/harness-kit/embed`: browser code that puts an artifact's Shell page, or the library's home page,
|
|
3
|
+
* into an agent app's own UI. No Node imports: it runs in the app's renderer (a web page, an Electron or Tauri view).
|
|
4
|
+
*
|
|
5
|
+
* Two ways to show an artifact:
|
|
6
|
+
*
|
|
7
|
+
* - **Frame**: the host's page holds an `<iframe>` of the Shell (`viewUrl`). The Shell says `shell_hello` to its parent;
|
|
8
|
+
* this module answers `host_hello` to the Shell's origin only, and takes messages only from that iframe's window and
|
|
9
|
+
* the Shell's origin (the origin of the address it was given: loopback or not, `http` or `https`). The host's origin
|
|
10
|
+
* must be one its adapter declared (`caps.open.origins` in `hello`), or the Shell sends it no prompt or comment text,
|
|
11
|
+
* links, saved files or destinations.
|
|
12
|
+
*
|
|
13
|
+
* const view = embedArtifact(iframe, { url: viewUrl, agentName: 'My Agent', onNewSession: ({ prompt }) => … });
|
|
14
|
+
*
|
|
15
|
+
* - **Top-level view**: the host opens `host.open`'s `embed_url` in a view of its own (a tab, a webview, a window) with
|
|
16
|
+
* no parent frame; the Shell talks to the daemon, the daemon to the adapter (`shell.event` / `shell.command`). The
|
|
17
|
+
* host passes a transport that carries those both ways (in an Electron app, IPC to the process that holds the
|
|
18
|
+
* Harness connection):
|
|
19
|
+
*
|
|
20
|
+
* const view = embedArtifact({ send: (command) => harness.shellCommand(viewId, command), onEvent: (listener) => … }, { url: embedUrl, … });
|
|
21
|
+
*
|
|
22
|
+
* What the Shell sends is data about what the person did: prompts and comments are their words for the agent, never
|
|
23
|
+
* instructions to the host.
|
|
24
|
+
*
|
|
25
|
+
* Thumbnails: give `capture` (returns a JPEG of the view, as the host's own view can take one) and `saveThumbnail`
|
|
26
|
+
* (stores it, e.g. through the adapter's `Harness.saveThumbnail`; a browser page should not hold the daemon token).
|
|
27
|
+
* The kit captures {@link THUMBNAIL_DELAY_MS} after the Shell is ready, then after a place change at most once every
|
|
28
|
+
* {@link THUMBNAIL_INTERVAL_MS}.
|
|
29
|
+
*/
|
|
30
|
+
import { type HostDestination, type HostTheme, type HostToShell, type ShellToHost } from '@open-artifact/protocol';
|
|
31
|
+
export type { HostDestination, HostTheme, HostToShell, ShellToHost };
|
|
32
|
+
/** How long after the Shell is ready the first thumbnail is captured. */
|
|
33
|
+
export declare const THUMBNAIL_DELAY_MS = 2000;
|
|
34
|
+
/** The least time between two thumbnails of one view. */
|
|
35
|
+
export declare const THUMBNAIL_INTERVAL_MS = 60000;
|
|
36
|
+
/** The bits of `window` this module uses (a test passes its own). */
|
|
37
|
+
export interface EmbedWindow {
|
|
38
|
+
addEventListener(type: 'message', listener: (event: MessageEvent) => void): void;
|
|
39
|
+
removeEventListener(type: 'message', listener: (event: MessageEvent) => void): void;
|
|
40
|
+
open?(url: string, target?: string, features?: string): unknown;
|
|
41
|
+
}
|
|
42
|
+
/** The bits of an `<iframe>` this module uses. */
|
|
43
|
+
export interface EmbedFrame {
|
|
44
|
+
src: string;
|
|
45
|
+
readonly contentWindow: {
|
|
46
|
+
postMessage(message: unknown, targetOrigin: string): void;
|
|
47
|
+
} | null;
|
|
48
|
+
}
|
|
49
|
+
/** Carries host messages to a top-level view's Shell and its messages back (through the adapter and the daemon). */
|
|
50
|
+
export interface EmbedTransport {
|
|
51
|
+
/** Sends a host message to the Shell (the adapter calls `Harness.shellCommand(view, command)`). */
|
|
52
|
+
send(command: HostToShell): void | Promise<void>;
|
|
53
|
+
/** Listens to what the Shell says (the adapter's `on('shell')` events of this view); returns a function that stops. */
|
|
54
|
+
onEvent(listener: (event: unknown) => void): () => void;
|
|
55
|
+
}
|
|
56
|
+
/** The artifact a Shell said hello for. */
|
|
57
|
+
export interface EmbedReadyInfo {
|
|
58
|
+
/** `open-artifact://artifact/<id>`. */
|
|
59
|
+
artifact: string;
|
|
60
|
+
id: string;
|
|
61
|
+
title: string;
|
|
62
|
+
type: string;
|
|
63
|
+
/** The Shell's version and host protocol. */
|
|
64
|
+
version: string;
|
|
65
|
+
protocol: number;
|
|
66
|
+
}
|
|
67
|
+
/** Options of {@link embedArtifact}. */
|
|
68
|
+
export interface EmbedArtifactOptions {
|
|
69
|
+
/**
|
|
70
|
+
* The Shell's address: the artifact's `viewUrl` (frame) or `embed_url` (top-level view). In frame mode it is set as
|
|
71
|
+
* the iframe's `src` when that differs; the Shell's origin is taken from it.
|
|
72
|
+
*/
|
|
73
|
+
url?: string;
|
|
74
|
+
/** The app's name, shown by the Shell ("Ask My Agent"). */
|
|
75
|
+
agentName?: string;
|
|
76
|
+
/** The harness the host belongs to. */
|
|
77
|
+
harness?: string;
|
|
78
|
+
/** The host draws its own toolbar: the Shell leaves out its close button. */
|
|
79
|
+
toolbar?: boolean;
|
|
80
|
+
/** The host's colour scheme and accent (`#rrggbb`). */
|
|
81
|
+
theme?: HostTheme;
|
|
82
|
+
/** Places the host sends exports to; the Shell lists at most {@link MAX_HOST_DESTINATIONS} in its Export tab. */
|
|
83
|
+
destinations?: HostDestination[];
|
|
84
|
+
/** The Shell said hello and took the host's answer. */
|
|
85
|
+
onReady?(info: EmbedReadyInfo): void;
|
|
86
|
+
/** Show the session that owns the artifact (`session` is `null` when none does). Sets caps `sessions`. */
|
|
87
|
+
onOpenSession?(request: {
|
|
88
|
+
session: string | null;
|
|
89
|
+
harness: string;
|
|
90
|
+
artifact: string | null;
|
|
91
|
+
}): void;
|
|
92
|
+
/** Start a new session with this prompt about the artifact (the person's words; empty to an undeclared host). Sets caps `sessions`. */
|
|
93
|
+
onNewSession?(request: {
|
|
94
|
+
prompt: string;
|
|
95
|
+
artifact: string;
|
|
96
|
+
}): void;
|
|
97
|
+
/** A comment was sent to the agent (its text; empty to an undeclared host). */
|
|
98
|
+
onCommentSent?(event: {
|
|
99
|
+
text: string;
|
|
100
|
+
}): void;
|
|
101
|
+
/** Where the artifact is now: a fragment to keep and send back with `goto`. */
|
|
102
|
+
onPlace?(event: {
|
|
103
|
+
artifact: string;
|
|
104
|
+
hash: string;
|
|
105
|
+
}): void;
|
|
106
|
+
/** The Shell's close button. */
|
|
107
|
+
onClose?(): void;
|
|
108
|
+
/** The person followed a link out of the Shell. Without this, the kit opens it with `window.open`. */
|
|
109
|
+
onOpenExternal?(url: string): void;
|
|
110
|
+
/** An export was saved to this file (absolute path on the computer that runs the type's server). */
|
|
111
|
+
onSavedFile?(path: string): void;
|
|
112
|
+
/** Takes a JPEG of the view, or `null` when it cannot now. */
|
|
113
|
+
capture?(): Promise<Blob | Uint8Array | ArrayBuffer | null> | Blob | Uint8Array | ArrayBuffer | null;
|
|
114
|
+
/** Stores a captured thumbnail (JPEG bytes) of `artifact`. */
|
|
115
|
+
saveThumbnail?(jpeg: Uint8Array, artifact: string): Promise<void> | void;
|
|
116
|
+
/** A thumbnail or a callback failed (default: ignored). */
|
|
117
|
+
onError?(error: unknown): void;
|
|
118
|
+
/** The window to listen on (default `globalThis.window`). */
|
|
119
|
+
window?: EmbedWindow;
|
|
120
|
+
}
|
|
121
|
+
/** An embedded artifact. */
|
|
122
|
+
export interface EmbeddedArtifact {
|
|
123
|
+
/** The artifact the Shell said hello for, or `null` before. */
|
|
124
|
+
readonly artifact: string | null;
|
|
125
|
+
/** The last place the Shell reported, or `null`. */
|
|
126
|
+
readonly place: string | null;
|
|
127
|
+
/** Resolves once the Shell is ready. */
|
|
128
|
+
readonly ready: Promise<EmbedReadyInfo>;
|
|
129
|
+
/** Shows a place (a fragment from `onPlace`, or a link's own). */
|
|
130
|
+
goto(hash: string): void;
|
|
131
|
+
/** Follows a new colour scheme or accent (sends `host_hello` again). */
|
|
132
|
+
setTheme(theme: HostTheme): void;
|
|
133
|
+
/** The Shell's address with the place last reported (without a view ticket), or `null` when unknown. */
|
|
134
|
+
url(): string | null;
|
|
135
|
+
/** Stops listening (and leaves the iframe as it is). */
|
|
136
|
+
destroy(): void;
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Shows an artifact's Shell in the host's UI: `target` is the `<iframe>` (frame mode) or a transport to a top-level
|
|
140
|
+
* view (see the module's notes). Answers the Shell's hello and turns its messages into the callbacks.
|
|
141
|
+
*/
|
|
142
|
+
export declare function embedArtifact(target: EmbedFrame | EmbedTransport, options?: EmbedArtifactOptions): EmbeddedArtifact;
|
|
143
|
+
/** An artifact the home page asked the host to show. */
|
|
144
|
+
export interface LibraryArtifact {
|
|
145
|
+
url: string;
|
|
146
|
+
id: string;
|
|
147
|
+
title: string;
|
|
148
|
+
type: string;
|
|
149
|
+
}
|
|
150
|
+
/** Options of {@link embedLibrary}. */
|
|
151
|
+
export interface EmbedLibraryOptions {
|
|
152
|
+
/** The home page's address (the daemon's origin); set as the iframe's `src` when it differs. */
|
|
153
|
+
url?: string;
|
|
154
|
+
/** The harness the host belongs to: the page lists only artifacts of its sessions. */
|
|
155
|
+
harness?: string;
|
|
156
|
+
/** Only artifacts of sessions working in this folder (or under it). */
|
|
157
|
+
workspace?: string;
|
|
158
|
+
agentName?: string;
|
|
159
|
+
theme?: HostTheme;
|
|
160
|
+
/** Show this artifact (sets caps `artifacts`: the page sends it instead of navigating). */
|
|
161
|
+
onOpenArtifact?(artifact: LibraryArtifact): void;
|
|
162
|
+
onOpenSession?(request: {
|
|
163
|
+
session: string | null;
|
|
164
|
+
harness: string;
|
|
165
|
+
}): void;
|
|
166
|
+
onNewSession?(request: {
|
|
167
|
+
prompt: string;
|
|
168
|
+
artifact: string;
|
|
169
|
+
}): void;
|
|
170
|
+
/** The home page took the host's answer. */
|
|
171
|
+
onReady?(): void;
|
|
172
|
+
onError?(error: unknown): void;
|
|
173
|
+
window?: EmbedWindow;
|
|
174
|
+
}
|
|
175
|
+
/** The embedded home page. */
|
|
176
|
+
export interface EmbeddedLibrary {
|
|
177
|
+
/** Follows a new colour scheme or accent. */
|
|
178
|
+
setTheme(theme: HostTheme): void;
|
|
179
|
+
destroy(): void;
|
|
180
|
+
}
|
|
181
|
+
/** Shows the library's home page in an `<iframe>`, listing the host's own artifacts, and turns its messages into callbacks. */
|
|
182
|
+
export declare function embedLibrary(iframe: EmbedFrame, options?: EmbedLibraryOptions): EmbeddedLibrary;
|
|
183
|
+
export { remoteGate, remotePolicyOf, type AllowRemote, type RemotePage, type RemotePagePolicy, type RemotePageRequest } from './remote.js';
|