@open-artifact/harness-kit 0.14.0 → 0.14.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -16,7 +16,7 @@ const harness = await createHarness({
16
16
  harness: 'my-app', // ^[a-z0-9][a-z0-9._-]{0,40}$
17
17
  agentName: 'Assistant',
18
18
  commands: ['artifact'],
19
- runtime: { dir: '/path/to/@open-artifact/cli', version: '0.14.0' }, // starts the daemon when none runs
19
+ runtime: { dir: '/path/to/@open-artifact/cli', version: '0.14.2' }, // starts the daemon when none runs
20
20
  // Give a message to a session: 'delivered' | 'resumed' | 'drafted' | 'queued' | 'failed' (the daemon keeps it),
21
21
  // or { status, session }. Only the owner's words (source.from.kind === 'owner') should become a user turn.
22
22
  wake: async ({ session, text, source }) => ((await myApp.deliver(session, text, source)) ? 'delivered' : 'failed'),
@@ -39,6 +39,12 @@ harness.on('artifact', ({ session, artifact, change }) => myApp.card(session, ar
39
39
  (`{ embed, origins, remote }` with `embed`). `options.caps` adds `tools`, `library`, `wake.resume`, `wake.mode`.
40
40
  - Under `embed.remote: 'ask'` (the default) a remote type's page reaches `open` only after `allowRemote` said yes.
41
41
  - Check `harness.features` by name before using anything newer than the base protocol.
42
+ - `daemon: { spawn }` starts the daemon process yourself. The kit passes `{ bin, args, env, logFile }` (no
43
+ `ELECTRON_RUN_AS_NODE` in `env`) and still chooses the runtime, waits for the daemon, checks its version and tries
44
+ the next runtime; return the process (anything with `once('exit')`) so a failed one is left at once. An Electron app
45
+ with its `RunAsNode` fuse off uses `utilityProcess.fork(bin, args, { env, stdio: 'pipe' })`; type servers then run
46
+ in worker threads of the daemon
47
+ ([runtime guide](../../docs/integrating/runtime.md#electron-apps-with-the-runasnode-fuse-off)).
42
48
 
43
49
  ## The `Harness` object
44
50
 
@@ -56,7 +62,7 @@ harness.on('artifact', ({ session, artifact, change }) => myApp.card(session, ar
56
62
  | `shellCommand(view, command)` | a host message to a top-level view's Shell (feature `shell.command`) |
57
63
  | `context(url, caller)`, `contextBlock(context)` | what the person selected on the page, as prompt text (feature `view.context`) |
58
64
  | `saveThumbnail(url, jpeg)` | a thumbnail for the library |
59
- | `installSkill({ dir, … })`, `commands()` | the skill file and the command menu (features `skill.get`, `commands.list`; rendered by the kit without them) |
65
+ | `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)) |
60
66
  | `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) |
61
67
  | `on('artifact' \| 'shell' \| 'event' \| 'state', listener)` | artifact reports, Shell messages, every daemon event, the connection state |
62
68
  | `close()` | closes the connection for good |
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@open-artifact/harness-kit",
3
- "version": "0.14.0",
3
+ "version": "0.14.2",
4
4
  "description": "The SDK an agent app uses to integrate Open Artifact: 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
5
  "type": "module",
6
6
  "exports": {
@@ -24,7 +24,7 @@
24
24
  "NOTICE"
25
25
  ],
26
26
  "dependencies": {
27
- "@open-artifact/protocol": "0.14.0"
27
+ "@open-artifact/protocol": "0.14.2"
28
28
  },
29
29
  "engines": {
30
30
  "node": ">=22.18"
package/src/client.d.ts CHANGED
@@ -5,7 +5,7 @@
5
5
  * Uses the global `WebSocket` (Node ≥ 22, Electron's Node).
6
6
  */
7
7
  import { type AdapterCaps, type AdapterToDaemon, type AttachParams, type DaemonCallHandlers, type DaemonState, type HarnessEvent, type HelloParams, type HelloResult, type SessionParams, type SessionStatus, type ToolCallResult, type ToolDefinition } from '@open-artifact/protocol';
8
- import { type EnsureDaemonOptions } from './daemon.ts';
8
+ import { type EnsureDaemonOptions } from './daemon.js';
9
9
  /** Connection state reported to {@link HarnessClientOptions.onState}. */
10
10
  export type HarnessConnectionState = 'connected' | 'disconnected';
11
11
  /** What else `hello` says besides the harness, its caps and the token. `protocols` defaults to what this kit speaks. */
package/src/context.d.ts CHANGED
@@ -7,7 +7,7 @@
7
7
  * it is quoted as JSON, never written as words of the harness's own.
8
8
  */
9
9
  import type { ViewContextResult } from '@open-artifact/protocol';
10
- import type { HarnessClient } from './client.ts';
10
+ import type { HarnessClient } from './client.js';
11
11
  /** A view context with the artifact it is of: what `Harness.context` answers. */
12
12
  export interface ArtifactContext extends ViewContextResult {
13
13
  /** `open-artifact://artifact/<id>`. */
package/src/daemon.d.ts CHANGED
@@ -9,7 +9,7 @@
9
9
  */
10
10
  import { type ChildProcess } from 'node:child_process';
11
11
  import { type DaemonState, type ProtocolRange } from '@open-artifact/protocol';
12
- import { type OwnRuntime, type RuntimeCandidate } from './runtimes.ts';
12
+ import { type OwnRuntime, type RuntimeCandidate } from './runtimes.js';
13
13
  /**
14
14
  * The Open Artifact home: `home` when given, else `$OPEN_ARTIFACT_HOME`, else `~/.agents/open-artifact`. A leading `~`
15
15
  * is the home folder.
@@ -58,6 +58,37 @@ export interface EnsureDaemonOptions {
58
58
  * harness its own daemon and library.
59
59
  */
60
60
  home?: string;
61
+ /**
62
+ * Starts the daemon process instead of the kit, for a host that cannot run a script with its own executable (an
63
+ * Electron app whose `RunAsNode` fuse is off: `utilityProcess.fork(start.bin, start.args, { env: start.env })`).
64
+ * Called once per runtime tried; the kit still waits for the daemon to answer, checks its version, and tries the next
65
+ * runtime when this one throws or ends without a daemon. See {@link DaemonSpawn}.
66
+ */
67
+ spawn?: DaemonSpawn;
68
+ }
69
+ /** What {@link EnsureDaemonOptions.spawn} is given: one daemon to start. */
70
+ export interface DaemonStart {
71
+ /** The `open-artifact` entry script to run (`scripts/open-artifact.mjs` of a runtime). */
72
+ bin: string;
73
+ /** What follows the entry on the command line: `['daemon', 'run']`. */
74
+ args: string[];
75
+ /**
76
+ * The environment to start it with: the kit's choice for this runtime (`OPEN_ARTIFACT_HOME` included when a home was
77
+ * given). `ELECTRON_RUN_AS_NODE` is not in it: a host that runs `bin` with Node by other means does not need it.
78
+ */
79
+ env: NodeJS.ProcessEnv;
80
+ /** `<home>/logs/daemon.out`, where the kit's own start appends the daemon's output (the host may do the same). */
81
+ logFile: string;
82
+ }
83
+ /**
84
+ * Starts one daemon (see {@link EnsureDaemonOptions.spawn}). It may return the started process (anything with
85
+ * `once('exit', …)`, such as Electron's `UtilityProcess` or a `ChildProcess`): then a runtime that ends without
86
+ * starting is given up at once and the next one tried; otherwise the kit waits for it until its timeout.
87
+ */
88
+ export type DaemonSpawn = (start: DaemonStart) => void | DaemonExitSource | Promise<void | DaemonExitSource>;
89
+ /** A started daemon process, as far as the kit watches it: its end. */
90
+ export interface DaemonExitSource {
91
+ once(event: 'exit', listener: (...args: unknown[]) => void): unknown;
61
92
  }
62
93
  /** What {@link ensureDaemon} would start, in order of preference. */
63
94
  export interface DaemonStartPlan {
package/src/daemon.js CHANGED
@@ -161,12 +161,30 @@ export async function ensureDaemon(options = {}) {
161
161
  await replaceDaemon(running, 5_000);
162
162
  const logFile = join(openArtifactHome(home), 'logs', 'daemon.out');
163
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 = [];
164
166
  for (const attempt of plan.tries) {
165
- const child = startDaemonProcess(attempt.bin, { env: attempt.env, ...(home ? { home } : {}) });
166
167
  let exited = false;
167
- child.once('exit', () => {
168
+ const onExit = () => {
168
169
  exited = true;
169
- });
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
+ }
170
188
  while (Date.now() < deadline) {
171
189
  await new Promise((done) => setTimeout(done, 150));
172
190
  const state = await readDaemon(home);
@@ -182,7 +200,8 @@ export async function ensureDaemon(options = {}) {
182
200
  const state = await readDaemon(home);
183
201
  if (state)
184
202
  return state;
185
- throw new OpenArtifactError('daemon_failed', `The open-artifact daemon did not start; see ${logFile}`);
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}`);
186
205
  }
187
206
  /** One Library API call (`/api/open-artifact.<name>`) with the daemon token. Returns the parsed JSON body. */
188
207
  export async function api(state, name, body, options = {}) {
@@ -180,4 +180,4 @@ export interface EmbeddedLibrary {
180
180
  }
181
181
  /** Shows the library's home page in an `<iframe>`, listing the host's own artifacts, and turns its messages into callbacks. */
182
182
  export declare function embedLibrary(iframe: EmbedFrame, options?: EmbedLibraryOptions): EmbeddedLibrary;
183
- export { remoteGate, remotePolicyOf, type AllowRemote, type RemotePage, type RemotePagePolicy, type RemotePageRequest } from './remote.ts';
183
+ export { remoteGate, remotePolicyOf, type AllowRemote, type RemotePage, type RemotePagePolicy, type RemotePageRequest } from './remote.js';
package/src/harness.d.ts CHANGED
@@ -7,11 +7,11 @@
7
7
  * files its agent wrote, and the artifacts its sessions make.
8
8
  */
9
9
  import { type AdapterCaps, type AttachParams, type CommandEntry, type EmbedOriginsResult, type HarnessEvent, type HostToShell, type ShellEventParams, type HarnessPolicy, type HarnessProfile, type HarnessRuntime, type HelloResult, type InboxMessage, type RuntimeStatus, type RuntimeUpdateResult, type SessionParams, type SessionStatus, type ToolCallResult, type ToolDefinition, type WakeDeliverParams, type WakeDeliverResult, type WakeDeliverStatus } from '@open-artifact/protocol';
10
- import { HarnessClient, type HarnessConnectionState } from './client.ts';
11
- import { type EnsureDaemonOptions } from './daemon.ts';
12
- import { type InstallSkillOptions, type InstallSkillResult } from './skill.ts';
13
- import { type ArtifactContext } from './context.ts';
14
- import { type AllowRemote, type RemotePage, type RemotePagePolicy } from './embed/remote.ts';
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
15
  /** This kit's name and version, said in `hello` (`kit`). */
16
16
  export declare const KIT: {
17
17
  readonly name: "@open-artifact/harness-kit";
@@ -103,7 +103,7 @@ export interface HarnessOptions {
103
103
  home?: string;
104
104
  /** Start the daemon when none runs (default `true`). */
105
105
  autoStart?: boolean;
106
- /** More options for starting the daemon (`env`, `bin`, `timeoutMs`). */
106
+ /** More options for starting the daemon (`env`, `bin`, `timeoutMs`, and `spawn` for a host that starts the process itself). */
107
107
  daemon?: EnsureDaemonOptions;
108
108
  /** Gives a message to a session (`wake.deliver`); see {@link createHarness}. */
109
109
  wake?: (params: WakeDeliverParams) => WakeAnswer | Promise<WakeAnswer>;
package/src/harness.js CHANGED
@@ -405,7 +405,9 @@ export async function createHarness(options) {
405
405
  };
406
406
  },
407
407
  async installSkill(opts) {
408
- return (await keepSkillInstalled(client, opts, (listener) => harness.on('state', listener), log)).result;
408
+ // With an `open` handler the app shows pages itself: the kit's own rendering says so, as the daemon's does.
409
+ const withOpens = options.open && opts.opens === undefined ? { ...opts, opens: 'host' } : opts;
410
+ return (await keepSkillInstalled(client, withOpens, (listener) => harness.on('state', listener), log)).result;
409
411
  },
410
412
  commands: (opts) => commands(client, opts),
411
413
  runtime: {
package/src/index.d.ts CHANGED
@@ -8,11 +8,11 @@
8
8
  * Entry points: `.` (this file), `./testing` (a fake daemon for an adapter's tests) and `./embed` (browser code that
9
9
  * puts a Shell page or the home page into the app's own UI: `embedArtifact`, `embedLibrary`).
10
10
  */
11
- export { api, daemonStartPlan, defaultDaemonBin, ensureDaemon, isOlderVersion, openArtifactHome, readDaemon, startDaemonProcess, type ApiOptions, type DaemonStartPlan, type EnsureDaemonOptions } from './daemon.ts';
12
- export { LEGACY_PROTOCOLS, RUNTIME_ENTRY, compareVersions, isPrerelease, missingRuntimes, parseVersion, protocolRangeOf, rangesMeet, rankRuntimes, readRuntimePin, readRuntimesFile, runtimeCandidates, runtimeEnv, runtimeInfo, runtimesFileOf, satisfies, selectRuntime, sharedRuntimes, sharedRuntimesOf, validRange, type OwnRuntime, type RuntimeCandidate, type RuntimeRecord, type RuntimesFile, } from './runtimes.ts';
13
- export { HarnessClient, type HarnessClientOptions, type HarnessConnectionState, type HelloExtras } from './client.ts';
14
- export { KIT, createHarness, ownsCall, type ArtifactChange, type ArtifactReport, type Harness, type HarnessArtifact, type HarnessOptions, type HarnessRuntimeCalls, type OpenRequest, type WakeAnswer, } from './harness.ts';
11
+ export { api, daemonStartPlan, defaultDaemonBin, ensureDaemon, isOlderVersion, openArtifactHome, readDaemon, startDaemonProcess, type ApiOptions, type DaemonExitSource, type DaemonSpawn, type DaemonStart, type DaemonStartPlan, type EnsureDaemonOptions } from './daemon.js';
12
+ export { LEGACY_PROTOCOLS, RUNTIME_ENTRY, compareVersions, isPrerelease, missingRuntimes, parseVersion, protocolRangeOf, rangesMeet, rankRuntimes, readRuntimePin, readRuntimesFile, runtimeCandidates, runtimeEnv, runtimeInfo, runtimesFileOf, satisfies, selectRuntime, sharedRuntimes, sharedRuntimesOf, validRange, type OwnRuntime, type RuntimeCandidate, type RuntimeRecord, type RuntimesFile, } from './runtimes.js';
13
+ export { HarnessClient, type HarnessClientOptions, type HarnessConnectionState, type HelloExtras } from './client.js';
14
+ export { KIT, createHarness, ownsCall, type ArtifactChange, type ArtifactReport, type Harness, type HarnessArtifact, type HarnessOptions, type HarnessRuntimeCalls, type OpenRequest, type WakeAnswer, } from './harness.js';
15
15
  export type { RuntimeStatus, RuntimeUpdateResult } from '@open-artifact/protocol';
16
- export { remoteGate, remotePolicyOf, type AllowRemote, type RemotePage, type RemotePagePolicy, type RemotePageRequest } from './embed/remote.ts';
17
- export { CONTEXT_HEADER, MAX_CONTEXT_CHARS, contextBlock, readContext, type ArtifactContext } from './context.ts';
18
- export { commands, installSkill, keepSkillInstalled, localSkill, renderSkill, type InstallSkillOptions, type InstallSkillResult } from './skill.ts';
16
+ export { remoteGate, remotePolicyOf, type AllowRemote, type RemotePage, type RemotePagePolicy, type RemotePageRequest } from './embed/remote.js';
17
+ export { CONTEXT_HEADER, MAX_CONTEXT_CHARS, contextBlock, readContext, type ArtifactContext } from './context.js';
18
+ export { commands, installSkill, keepSkillInstalled, localSkill, renderSkill, type InstallSkillOptions, type InstallSkillResult } from './skill.js';
package/src/skill.d.ts CHANGED
@@ -9,7 +9,7 @@
9
9
  * the person's input box, never sent by themselves.
10
10
  */
11
11
  import { type CommandEntry, type SkillParams, type SkillResult } from '@open-artifact/protocol';
12
- import type { HarnessClient, HarnessConnectionState } from './client.ts';
12
+ import type { HarnessClient, HarnessConnectionState } from './client.js';
13
13
  /** What {@link installSkill} takes. */
14
14
  export interface InstallSkillOptions extends Omit<SkillParams, 'command'> {
15
15
  /** The folder the harness reads skills from (the skill goes in `<dir>/<command>/`). */