@openartifactsai/cli 0.23.0-rc.0 → 0.23.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openartifactsai/cli",
3
- "version": "0.23.0-rc.0",
3
+ "version": "0.23.0",
4
4
  "description": "The open-artifacts command: the local Open Artifacts daemon with its Shell and the built-in types (slides, design, design system, whiteboard, sheets, data, docs, motion, page), an MCP server for agent apps, and the hooks that bring page comments back to the agent.",
5
5
  "type": "module",
6
6
  "bin": {
@@ -1621,7 +1621,7 @@ function lineDecoder() {
1621
1621
  }
1622
1622
  async function* decode(body, decoder, onChunk) {
1623
1623
  const reader = body.getReader();
1624
- let ended = false;
1624
+ let ended2 = false;
1625
1625
  try {
1626
1626
  for (; ; ) {
1627
1627
  const { value, done } = await reader.read();
@@ -1629,10 +1629,10 @@ async function* decode(body, decoder, onChunk) {
1629
1629
  onChunk?.();
1630
1630
  yield* decoder.push(value);
1631
1631
  }
1632
- ended = true;
1632
+ ended2 = true;
1633
1633
  yield* decoder.end();
1634
1634
  } finally {
1635
- if (!ended) await reader.cancel().catch(() => void 0);
1635
+ if (!ended2) await reader.cancel().catch(() => void 0);
1636
1636
  reader.releaseLock();
1637
1637
  }
1638
1638
  }
@@ -5185,13 +5185,13 @@ var FrameSite = class extends FrameCore {
5185
5185
 
5186
5186
  // packages/server-sdk/src/frame/snapshot-action.ts
5187
5187
  import { mkdirSync as mkdirSync2, readdirSync as readdirSync4, rmSync as rmSync5, writeFileSync as writeFileSync3 } from "node:fs";
5188
- import { join as join8 } from "node:path";
5188
+ import { join as join9 } from "node:path";
5189
5189
 
5190
5190
  // packages/server-sdk/src/snapshot.ts
5191
5191
  import { spawn } from "node:child_process";
5192
- import { closeSync as closeSync2, existsSync as existsSync5, mkdtempSync, openSync as openSync2, readFileSync as readFileSync7, rmSync as rmSync4 } from "node:fs";
5192
+ import { closeSync as closeSync2, existsSync as existsSync5, mkdtempSync, openSync as openSync2, readFileSync as readFileSync8 } from "node:fs";
5193
5193
  import { tmpdir } from "node:os";
5194
- import { join as join7, win32 } from "node:path";
5194
+ import { join as join8, win32 } from "node:path";
5195
5195
 
5196
5196
  // packages/server-sdk/src/child.ts
5197
5197
  function hasExited(child) {
@@ -5234,6 +5234,145 @@ function stopChild(child, options) {
5234
5234
  });
5235
5235
  }
5236
5236
 
5237
+ // packages/server-sdk/src/chrome.ts
5238
+ import { readFileSync as readFileSync7, rmSync as rmSync4 } from "node:fs";
5239
+ import { join as join7 } from "node:path";
5240
+ var DEVTOOLS_ACTIVE_PORT = "DevToolsActivePort";
5241
+ function activePortEndpoint(profile) {
5242
+ let text;
5243
+ try {
5244
+ text = readFileSync7(join7(profile, DEVTOOLS_ACTIVE_PORT), "utf8");
5245
+ } catch {
5246
+ return null;
5247
+ }
5248
+ const [port, path] = text.split(/\r?\n/);
5249
+ if (!port || !/^\d+$/.test(port) || !path?.startsWith("/devtools/browser/")) return null;
5250
+ return `ws://127.0.0.1:${port}${path}`;
5251
+ }
5252
+ function waitForDevTools(wait) {
5253
+ const { child, profile, stderr, timeoutMs, relaunchMs = Infinity, name = "Chrome" } = wait;
5254
+ const started = Date.now();
5255
+ return new Promise((resolve8, reject) => {
5256
+ let exitedAt = null;
5257
+ let poll;
5258
+ let settled = false;
5259
+ const settle = (then) => {
5260
+ if (settled) return;
5261
+ settled = true;
5262
+ clearInterval(poll);
5263
+ then();
5264
+ };
5265
+ child.once("error", (error) => settle(() => reject(error)));
5266
+ const check = () => {
5267
+ const said = stderr();
5268
+ const endpoint = /DevTools listening on (ws:\/\/\S+)/.exec(said)?.[1] ?? activePortEndpoint(profile);
5269
+ if (endpoint) return settle(() => resolve8(endpoint));
5270
+ const last = said.trim().slice(-400);
5271
+ const failed = (message) => settle(() => reject(new Error(last ? `${message}: ${last}` : `${message}.`)));
5272
+ if (child.signalCode !== null || child.exitCode !== null && child.exitCode !== 0) {
5273
+ return failed(`${name} exited (${child.exitCode ?? child.signalCode})`);
5274
+ }
5275
+ const relaunched = `${name} exited (0), and no browser it started serves its profile`;
5276
+ if (child.exitCode === 0) {
5277
+ exitedAt ??= Date.now();
5278
+ if (Date.now() - exitedAt > relaunchMs) return failed(relaunched);
5279
+ }
5280
+ if (Date.now() - started > timeoutMs) failed(child.exitCode === 0 ? relaunched : `${name} did not start in ${Math.round(timeoutMs / 1e3)} s`);
5281
+ };
5282
+ poll = setInterval(check, 50);
5283
+ });
5284
+ }
5285
+ function closeBrowserAt(endpoint, waitMs = 3e3, exitMs = 5e3) {
5286
+ return new Promise((resolve8) => {
5287
+ let socket;
5288
+ let pid = null;
5289
+ let closing = false;
5290
+ let hungUp = false;
5291
+ let unanswered;
5292
+ const timer = setTimeout(() => hangUp(), waitMs);
5293
+ const askToClose = () => {
5294
+ if (closing || hungUp) return;
5295
+ closing = true;
5296
+ socket.send(JSON.stringify({ id: 2, method: "Browser.close" }));
5297
+ };
5298
+ const hangUp = () => {
5299
+ if (hungUp) return;
5300
+ hungUp = true;
5301
+ clearTimeout(timer);
5302
+ clearTimeout(unanswered);
5303
+ try {
5304
+ socket?.close();
5305
+ } catch {
5306
+ }
5307
+ if (pid === null) resolve8();
5308
+ else void waitForExit(pid, exitMs).then(resolve8);
5309
+ };
5310
+ try {
5311
+ socket = new WebSocket(endpoint);
5312
+ } catch {
5313
+ return hangUp();
5314
+ }
5315
+ socket.addEventListener(
5316
+ "open",
5317
+ () => {
5318
+ socket.send(JSON.stringify({ id: 1, method: "SystemInfo.getProcessInfo" }));
5319
+ unanswered = setTimeout(askToClose, 1e3);
5320
+ },
5321
+ { once: true }
5322
+ );
5323
+ socket.addEventListener("message", (event) => {
5324
+ let answer;
5325
+ try {
5326
+ answer = JSON.parse(String(event.data));
5327
+ } catch {
5328
+ return;
5329
+ }
5330
+ if (answer.id !== 1) return;
5331
+ const browser = answer.result?.processInfo?.find((info) => info.type === "browser")?.id;
5332
+ if (typeof browser === "number" && Number.isInteger(browser) && browser > 0 && browser !== process.pid) pid = browser;
5333
+ askToClose();
5334
+ });
5335
+ socket.addEventListener("close", () => hangUp(), { once: true });
5336
+ socket.addEventListener("error", () => hangUp(), { once: true });
5337
+ });
5338
+ }
5339
+ function running(pid) {
5340
+ try {
5341
+ process.kill(pid, 0);
5342
+ return true;
5343
+ } catch (error) {
5344
+ return error.code === "EPERM";
5345
+ }
5346
+ }
5347
+ async function ended(pid, ms) {
5348
+ const deadline = Date.now() + ms;
5349
+ while (running(pid)) {
5350
+ if (Date.now() >= deadline) return false;
5351
+ await new Promise((done) => setTimeout(done, 25));
5352
+ }
5353
+ return true;
5354
+ }
5355
+ async function waitForExit(pid, ms) {
5356
+ if (await ended(pid, ms)) return;
5357
+ try {
5358
+ process.kill(pid, "SIGKILL");
5359
+ } catch {
5360
+ return;
5361
+ }
5362
+ await ended(pid, 1e3);
5363
+ }
5364
+ function removeProfile(profile) {
5365
+ const remove = () => {
5366
+ try {
5367
+ rmSync4(profile, { recursive: true, force: true, maxRetries: 5, retryDelay: 100 });
5368
+ return true;
5369
+ } catch {
5370
+ return false;
5371
+ }
5372
+ };
5373
+ if (!remove()) setTimeout(remove, 2e3).unref();
5374
+ }
5375
+
5237
5376
  // packages/server-sdk/src/snapshot.ts
5238
5377
  var WINDOWS_BROWSERS = [
5239
5378
  ["Google\\Chrome\\Application", "chrome.exe"],
@@ -5281,8 +5420,8 @@ var DEFAULT_READY = "document.readyState === 'complete' && !!document.body && (d
5281
5420
  var sleep = (ms) => new Promise((done) => setTimeout(done, ms));
5282
5421
  var CHROME_START_MS = 4e4;
5283
5422
  async function snapshotPage(chrome, request) {
5284
- const profile = mkdtempSync(join7(tmpdir(), "open-artifacts-snapshot-"));
5285
- const stderr = join7(profile, "chrome-stderr.log");
5423
+ const profile = mkdtempSync(join8(tmpdir(), "open-artifacts-snapshot-"));
5424
+ const stderr = join8(profile, "chrome-stderr.log");
5286
5425
  const fd = openSync2(stderr, "a");
5287
5426
  const child = spawn(
5288
5427
  chrome,
@@ -5307,43 +5446,28 @@ async function snapshotPage(chrome, request) {
5307
5446
  );
5308
5447
  closeSync2(fd);
5309
5448
  let ws = null;
5449
+ let endpoint = null;
5310
5450
  let timer;
5311
- const removeProfile = () => {
5312
- try {
5313
- rmSync4(profile, { recursive: true, force: true, maxRetries: 5, retryDelay: 100 });
5314
- return true;
5315
- } catch {
5316
- return false;
5317
- }
5318
- };
5319
5451
  const cleanup = async () => {
5320
5452
  clearTimeout(timer);
5321
5453
  try {
5322
5454
  ws?.close();
5323
5455
  } catch {
5324
5456
  }
5457
+ const browser = endpoint ?? activePortEndpoint(profile);
5458
+ if (browser) await closeBrowserAt(browser);
5325
5459
  await stopChild(child, { graceMs: 0, settleMs: 3e3 });
5326
- if (!removeProfile()) setTimeout(removeProfile, 2e3).unref();
5460
+ removeProfile(profile);
5327
5461
  };
5328
5462
  const work = async () => {
5329
- const endpoint = await new Promise((resolveEndpoint, reject) => {
5330
- const started = Date.now();
5331
- const poll = setInterval(() => {
5332
- let text = "";
5333
- try {
5334
- text = readFileSync7(stderr, "utf8");
5335
- } catch {
5336
- }
5337
- const found = /DevTools listening on (ws:\/\/\S+)/.exec(text);
5338
- if (found) {
5339
- clearInterval(poll);
5340
- resolveEndpoint(found[1]);
5341
- } else if (child.exitCode !== null || Date.now() - started > CHROME_START_MS) {
5342
- clearInterval(poll);
5343
- reject(new Error(`Chrome did not start: ${text.slice(-300)}`));
5344
- }
5345
- }, 50);
5346
- });
5463
+ const readStderr = () => {
5464
+ try {
5465
+ return readFileSync8(stderr, "utf8");
5466
+ } catch {
5467
+ return "";
5468
+ }
5469
+ };
5470
+ endpoint = await waitForDevTools({ child, profile, stderr: readStderr, timeoutMs: CHROME_START_MS });
5347
5471
  const socket = new WebSocket(endpoint);
5348
5472
  ws = socket;
5349
5473
  await new Promise((opened, failed) => {
@@ -5455,13 +5579,13 @@ var snapshotAction = {
5455
5579
  } finally {
5456
5580
  visit.end();
5457
5581
  }
5458
- const dir2 = join8(artifact.root, "_agent", "snapshots");
5459
- if (!staysInside(artifact.root, join8(dir2, "snapshot.png"))) throw new FrameError("failed", "snapshot: _agent/snapshots leaves the artifact folder (a link): remove it and try again.", 500);
5582
+ const dir2 = join9(artifact.root, "_agent", "snapshots");
5583
+ if (!staysInside(artifact.root, join9(dir2, "snapshot.png"))) throw new FrameError("failed", "snapshot: _agent/snapshots leaves the artifact folder (a link): remove it and try again.", 500);
5460
5584
  mkdirSync2(dir2, { recursive: true });
5461
- const image = join8(dir2, `snapshot-${(/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "-")}.png`);
5585
+ const image = join9(dir2, `snapshot-${(/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "-")}.png`);
5462
5586
  writeFileSync3(image, png);
5463
5587
  const old = readdirSync4(dir2).filter((name) => /^snapshot-.*\.png$/.test(name)).sort();
5464
- for (const name of old.slice(0, Math.max(0, old.length - SNAPSHOTS_KEPT))) rmSync5(join8(dir2, name), { force: true });
5588
+ for (const name of old.slice(0, Math.max(0, old.length - SNAPSHOTS_KEPT))) rmSync5(join9(dir2, name), { force: true });
5465
5589
  return { image, width, height, scheme, bytes: png.length, note: SNAPSHOT_NOTE };
5466
5590
  }
5467
5591
  };
@@ -5470,16 +5594,16 @@ var localFrameActions = { ...frameActions, snapshot: snapshotAction };
5470
5594
  // packages/server-sdk/src/serve.ts
5471
5595
  import { randomBytes as randomBytes7 } from "node:crypto";
5472
5596
  import { EventEmitter as EventEmitter2 } from "node:events";
5473
- import { appendFileSync, existsSync as existsSync6, readFileSync as readFileSync9, rmSync as rmSync6, writeFileSync as writeFileSync5 } from "node:fs";
5597
+ import { appendFileSync, existsSync as existsSync6, readFileSync as readFileSync10, rmSync as rmSync6, writeFileSync as writeFileSync5 } from "node:fs";
5474
5598
  import { createServer as createServer2 } from "node:http";
5475
5599
  import { hostname as hostname2 } from "node:os";
5476
- import { basename as basename4, isAbsolute as isAbsolute3, join as join11, resolve as resolve6 } from "node:path";
5600
+ import { basename as basename4, isAbsolute as isAbsolute3, join as join12, resolve as resolve6 } from "node:path";
5477
5601
  import { threadId } from "node:worker_threads";
5478
5602
 
5479
5603
  // packages/protocol/src/workspace-files.ts
5480
5604
  import { randomBytes as randomBytes6 } from "node:crypto";
5481
- import { lstatSync as lstatSync2, readFileSync as readFileSync8, realpathSync as realpathSync2, renameSync as renameSync3, statSync as statSync6, unlinkSync, writeFileSync as writeFileSync4 } from "node:fs";
5482
- import { basename as basename2, dirname as dirname3, isAbsolute as isAbsolute2, join as join9, relative, resolve as resolve4, sep as sep3 } from "node:path";
5605
+ import { lstatSync as lstatSync2, readFileSync as readFileSync9, realpathSync as realpathSync2, renameSync as renameSync3, statSync as statSync6, unlinkSync, writeFileSync as writeFileSync4 } from "node:fs";
5606
+ import { basename as basename2, dirname as dirname3, isAbsolute as isAbsolute2, join as join10, relative, resolve as resolve4, sep as sep3 } from "node:path";
5483
5607
  function includesPath(root, target) {
5484
5608
  const path = relative(root, target);
5485
5609
  return path !== ".." && !path.startsWith(".." + sep3) && !isAbsolute2(path);
@@ -5505,7 +5629,7 @@ var WorkspaceDirectory = class {
5505
5629
  /** Read optional metadata from a checked file. */
5506
5630
  readJson(input, fallback) {
5507
5631
  try {
5508
- return JSON.parse(readFileSync8(this.resolve(input), "utf8"));
5632
+ return JSON.parse(readFileSync9(this.resolve(input), "utf8"));
5509
5633
  } catch {
5510
5634
  return fallback;
5511
5635
  }
@@ -5559,7 +5683,7 @@ var WorkspaceDirectory = class {
5559
5683
  if (outside) throw forbidden();
5560
5684
  throw error;
5561
5685
  }
5562
- const actual = join9(real, ...tail);
5686
+ const actual = join10(real, ...tail);
5563
5687
  if (!includesPath(this.root, actual)) throw forbidden();
5564
5688
  return actual;
5565
5689
  }
@@ -6147,7 +6271,7 @@ var WebSocketConnection = class {
6147
6271
  // packages/server-sdk/src/zip.ts
6148
6272
  import { constants } from "node:fs";
6149
6273
  import { lstat, mkdir, open, readdir, readFile, rename, rm, stat } from "node:fs/promises";
6150
- import { basename as basename3, dirname as dirname4, extname as extname2, join as join10, resolve as resolve5, sep as sep4 } from "node:path";
6274
+ import { basename as basename3, dirname as dirname4, extname as extname2, join as join11, resolve as resolve5, sep as sep4 } from "node:path";
6151
6275
  import { promisify } from "node:util";
6152
6276
  import { deflateRaw as deflateRawCallback, inflateRaw as inflateRawCallback, inflateRawSync } from "node:zlib";
6153
6277
  var inflateRaw = promisify(inflateRawCallback);
@@ -6183,7 +6307,7 @@ async function archiveEntries(root, skip = []) {
6183
6307
  const name = dirent.name;
6184
6308
  const inner = rel ? `${rel}/${name}` : name;
6185
6309
  if (!keepsStep(rel, name, inner)) continue;
6186
- const file = join10(dir2, name);
6310
+ const file = join11(dir2, name);
6187
6311
  if (skipped.has(file)) continue;
6188
6312
  if (dirent.isDirectory()) await walk(file, inner);
6189
6313
  else if (dirent.isFile()) {
@@ -6470,7 +6594,7 @@ var StreamResponse = class extends EventEmitter2 {
6470
6594
  function typeManifest(dir2 = process.env.OPEN_ARTIFACTS_TYPE_DIR) {
6471
6595
  if (!dir2) return {};
6472
6596
  try {
6473
- const value = JSON.parse(readFileSync9(join11(dir2, "artifact-type.json"), "utf8"));
6597
+ const value = JSON.parse(readFileSync10(join12(dir2, "artifact-type.json"), "utf8"));
6474
6598
  return value && typeof value === "object" && !Array.isArray(value) ? value : {};
6475
6599
  } catch {
6476
6600
  return {};
@@ -6626,7 +6750,7 @@ var TypeServer = class {
6626
6750
  }
6627
6751
  async mount(id, root, title, workspace) {
6628
6752
  if (!existsSync6(root)) throw new OpenArtifactsError("not_found", `The folder ${root} is gone.`, { status: 404 });
6629
- const logPath = join11(root, LOG_FILE);
6753
+ const logPath = join12(root, LOG_FILE);
6630
6754
  const log = (line) => {
6631
6755
  try {
6632
6756
  appendFileSync(workspace ? new WorkspaceDirectory(workspace.resolve(root)).resolve(logPath) : logPath, `[${(/* @__PURE__ */ new Date()).toISOString()}] ${line}
@@ -6692,7 +6816,7 @@ var TypeServer = class {
6692
6816
  startedAt: (/* @__PURE__ */ new Date()).toISOString(),
6693
6817
  openArtifacts: id
6694
6818
  };
6695
- writeFileSync5(join11(root, STATE_FILE), `${JSON.stringify(record, null, 2)}
6819
+ writeFileSync5(join12(root, STATE_FILE), `${JSON.stringify(record, null, 2)}
6696
6820
  `);
6697
6821
  } catch {
6698
6822
  }
@@ -6707,8 +6831,8 @@ var TypeServer = class {
6707
6831
  this.byId.delete(id);
6708
6832
  this.byPage.delete(entry.page);
6709
6833
  try {
6710
- const file = join11(entry.root, STATE_FILE);
6711
- const state = JSON.parse(readFileSync9(file, "utf8"));
6834
+ const file = join12(entry.root, STATE_FILE);
6835
+ const state = JSON.parse(readFileSync10(file, "utf8"));
6712
6836
  if (state.pid === process.pid && (state.thread ?? 0) === threadId) rmSync6(file, { force: true });
6713
6837
  } catch {
6714
6838
  }
@@ -4688,7 +4688,7 @@ var init_package = __esm({
4688
4688
  "packages/daemon/package.json"() {
4689
4689
  package_default = {
4690
4690
  name: "@openartifactsai/daemon",
4691
- version: "0.23.0-rc.0",
4691
+ version: "0.23.0",
4692
4692
  private: true,
4693
4693
  type: "module",
4694
4694
  description: "The Open Artifacts daemon (`open-artifacts`): type registry, artifact library, type servers, agent tools, wake routing, the Harness API, MCP and the Shell.",
@@ -4700,10 +4700,10 @@ var init_package = __esm({
4700
4700
  "./client": "./src/client.ts"
4701
4701
  },
4702
4702
  dependencies: {
4703
- "@openartifactsai/harness-kit": "0.23.0-rc.0",
4704
- "@openartifactsai/model-gateway": "0.23.0-rc.0",
4705
- "@openartifactsai/protocol": "0.23.0-rc.0",
4706
- "@openartifactsai/server-sdk": "0.23.0-rc.0"
4703
+ "@openartifactsai/harness-kit": "0.23.0",
4704
+ "@openartifactsai/model-gateway": "0.23.0",
4705
+ "@openartifactsai/protocol": "0.23.0",
4706
+ "@openartifactsai/server-sdk": "0.23.0"
4707
4707
  },
4708
4708
  license: "Apache-2.0"
4709
4709
  };
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.23.0-rc.0",
2
+ "version": "0.23.0",
3
3
  "protocols": {
4
4
  "min": 1,
5
5
  "max": 1