agent-yes 1.195.0 → 1.196.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.
@@ -0,0 +1,8 @@
1
+ import "./ts-CHkgLvsJ.js";
2
+ import "./logger-CDIsZ-Pp.js";
3
+ import "./versionChecker-BGywS-RN.js";
4
+ import "./pidStore-BIvsBQ8X.js";
5
+ import "./globalPidIndex-CoNr7tS8.js";
6
+ import { t as SUPPORTED_CLIS } from "./SUPPORTED_CLIS-DOwI2CmP.js";
7
+
8
+ export { SUPPORTED_CLIS };
@@ -1,8 +1,8 @@
1
- import { t as CLIS_CONFIG } from "./ts-DDsICrj-.js";
1
+ import { t as CLIS_CONFIG } from "./ts-CHkgLvsJ.js";
2
2
 
3
3
  //#region ts/SUPPORTED_CLIS.ts
4
4
  const SUPPORTED_CLIS = Object.keys(CLIS_CONFIG);
5
5
 
6
6
  //#endregion
7
7
  export { SUPPORTED_CLIS as t };
8
- //# sourceMappingURL=SUPPORTED_CLIS-Bdj9qDRm.js.map
8
+ //# sourceMappingURL=SUPPORTED_CLIS-DOwI2CmP.js.map
@@ -1,7 +1,7 @@
1
1
  import "./logger-CDIsZ-Pp.js";
2
2
  import "./globalPidIndex-CoNr7tS8.js";
3
3
  import "./configShared-0MnIQ652.js";
4
- import { M as resolveOne } from "./subcommands-CqB9zo8_.js";
4
+ import { M as resolveOne } from "./subcommands-RnI0AkSK.js";
5
5
  import "./e2e-BeKjLhmO.js";
6
6
  import "./webrtcLink-BG0Xc4-W.js";
7
7
  import "./remotes-oSmwSYaV.js";
@@ -228,4 +228,4 @@ function transformEvent(rawEvent, agentId, forwarded) {
228
228
 
229
229
  //#endregion
230
230
  export { createScopedShare, listShares, revokeAllShares, revokeShare };
231
- //# sourceMappingURL=agentShare-M2jaTMlH.js.map
231
+ //# sourceMappingURL=agentShare-bCHRyHSj.js.map
package/dist/cli.js CHANGED
@@ -1,8 +1,8 @@
1
1
  #!/usr/bin/env bun
2
2
  import { t as invokedCliName } from "./invokedCli-uqM2YYA7.js";
3
3
  import { n as logger } from "./logger-CDIsZ-Pp.js";
4
- import { i as versionString, n as displayVersion, t as checkAndAutoUpdate } from "./versionChecker-B8qEzYDu.js";
5
- import { n as getRustBinary } from "./rustBinary-B4pfibDJ.js";
4
+ import { i as versionString, n as displayVersion, t as checkAndAutoUpdate } from "./versionChecker-BGywS-RN.js";
5
+ import { n as getRustBinary } from "./rustBinary-BYJrF4jm.js";
6
6
  import { argv } from "process";
7
7
  import { spawn } from "child_process";
8
8
  import ms from "ms";
@@ -285,7 +285,7 @@ function buildRustArgs(argv, cliFromScript, supportedClis) {
285
285
  const rawArg = process.argv[2];
286
286
  const managerCommands = !invokedCliName(process.argv);
287
287
  const isHelpFlag = rawArg === "-h" || rawArg === "--help";
288
- const { isSubcommand, runSubcommand, cmdHelp } = await import("./subcommands-CV5gqRKq.js");
288
+ const { isSubcommand, runSubcommand, cmdHelp } = await import("./subcommands-CRW8on1l.js");
289
289
  if (isHelpFlag && process.argv.length === 3) {
290
290
  await cmdHelp(managerCommands);
291
291
  process.exit(0);
@@ -327,7 +327,7 @@ if (config.useRust) {
327
327
  }
328
328
  }
329
329
  if (rustBinary) {
330
- const { SUPPORTED_CLIS } = await import("./SUPPORTED_CLIS-Daig8XHX.js");
330
+ const { SUPPORTED_CLIS } = await import("./SUPPORTED_CLIS-CFTeu8hj.js");
331
331
  const rustArgs = buildRustArgs(process.argv, config.cli, SUPPORTED_CLIS);
332
332
  if (config.verbose) {
333
333
  console.log(`[rust] Using binary: ${rustBinary}`);
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
- import { a as removeControlCharacters, i as AgentContext, n as agentYes, r as config, t as CLIS_CONFIG } from "./ts-DDsICrj-.js";
1
+ import { a as removeControlCharacters, i as AgentContext, n as agentYes, r as config, t as CLIS_CONFIG } from "./ts-CHkgLvsJ.js";
2
2
  import "./logger-CDIsZ-Pp.js";
3
- import "./versionChecker-B8qEzYDu.js";
3
+ import "./versionChecker-BGywS-RN.js";
4
4
  import "./pidStore-BIvsBQ8X.js";
5
5
  import "./globalPidIndex-CoNr7tS8.js";
6
6
 
@@ -1,7 +1,7 @@
1
1
  import { n as logger } from "./logger-CDIsZ-Pp.js";
2
2
  import "./globalPidIndex-CoNr7tS8.js";
3
3
  import "./configShared-0MnIQ652.js";
4
- import { $ as notifyDir, G as gcInboxes, J as liveWatchers, K as hostId, Q as daemonLockOwnerPath, S as listRecords, W as appendEvent, X as shouldStealLock, Y as readInbox, Z as daemonLockDir, _ as isPidAlive, c as deriveLiveState, k as renderLogTailLines, q as listInboxParents } from "./subcommands-CqB9zo8_.js";
4
+ import { $ as notifyDir, G as gcInboxes, J as liveWatchers, K as hostId, Q as daemonLockOwnerPath, S as listRecords, W as appendEvent, X as shouldStealLock, Y as readInbox, Z as daemonLockDir, _ as isPidAlive, c as deriveLiveState, k as renderLogTailLines, q as listInboxParents } from "./subcommands-RnI0AkSK.js";
5
5
  import "./e2e-BeKjLhmO.js";
6
6
  import "./webrtcLink-BG0Xc4-W.js";
7
7
  import "./remotes-oSmwSYaV.js";
@@ -588,4 +588,4 @@ async function ensureDaemon() {
588
588
 
589
589
  //#endregion
590
590
  export { daemonStatus, ensureDaemon, requestDaemonStop, runDaemon };
591
- //# sourceMappingURL=notifyDaemon-D5HwUMxH.js.map
591
+ //# sourceMappingURL=notifyDaemon-lPJrVB96.js.map
@@ -1,4 +1,4 @@
1
- import { r as getInstalledPackage } from "./versionChecker-B8qEzYDu.js";
1
+ import { r as getInstalledPackage } from "./versionChecker-BGywS-RN.js";
2
2
  import { execFileSync } from "child_process";
3
3
  import { existsSync, mkdirSync, unlinkSync } from "fs";
4
4
  import { chmod, copyFile } from "fs/promises";
@@ -225,4 +225,4 @@ async function getRustBinary(options = {}) {
225
225
 
226
226
  //#endregion
227
227
  export { getRustBinary as n, findSpawnHiddenLauncher as t };
228
- //# sourceMappingURL=rustBinary-B4pfibDJ.js.map
228
+ //# sourceMappingURL=rustBinary-BYJrF4jm.js.map
@@ -1,9 +1,9 @@
1
- import "./ts-DDsICrj-.js";
1
+ import "./ts-CHkgLvsJ.js";
2
2
  import "./logger-CDIsZ-Pp.js";
3
- import "./versionChecker-B8qEzYDu.js";
3
+ import "./versionChecker-BGywS-RN.js";
4
4
  import "./pidStore-BIvsBQ8X.js";
5
5
  import "./globalPidIndex-CoNr7tS8.js";
6
- import { t as SUPPORTED_CLIS } from "./SUPPORTED_CLIS-Bdj9qDRm.js";
6
+ import { t as SUPPORTED_CLIS } from "./SUPPORTED_CLIS-DOwI2CmP.js";
7
7
  import { d as resolveSpawnCwd } from "./workspaceConfig-_GtAZtsi.js";
8
8
  import { n as liveEnv, t as ensureNodeRuntime } from "./nodeRuntime-DZRjxpNp.js";
9
9
  import { createHash } from "node:crypto";
@@ -150,4 +150,4 @@ async function cmdSchedule(rest) {
150
150
 
151
151
  //#endregion
152
152
  export { cmdSchedule };
153
- //# sourceMappingURL=schedule-1oS-Yxxa.js.map
153
+ //# sourceMappingURL=schedule-BVTk2aWT.js.map
@@ -1,13 +1,13 @@
1
- import "./ts-DDsICrj-.js";
1
+ import "./ts-CHkgLvsJ.js";
2
2
  import "./logger-CDIsZ-Pp.js";
3
- import { r as getInstalledPackage } from "./versionChecker-B8qEzYDu.js";
4
- import { t as findSpawnHiddenLauncher } from "./rustBinary-B4pfibDJ.js";
3
+ import { r as getInstalledPackage } from "./versionChecker-BGywS-RN.js";
4
+ import { t as findSpawnHiddenLauncher } from "./rustBinary-BYJrF4jm.js";
5
5
  import "./pidStore-BIvsBQ8X.js";
6
6
  import { a as updateGlobalPidStatus } from "./globalPidIndex-CoNr7tS8.js";
7
7
  import { t as pgidForWrapper } from "./reaper-CWF2_ATd.js";
8
8
  import "./configShared-0MnIQ652.js";
9
- import { t as SUPPORTED_CLIS } from "./SUPPORTED_CLIS-Bdj9qDRm.js";
10
- import { A as renderRawLog, D as recentMessageEdges, E as readPtysize, L as snapshotStatus, M as resolveOne, O as recentReadEdges, S as listRecords, T as readNotes, U as writeToIpc, b as isUserTyping, et as TYPING_BADGE, f as extractNeedsInput, k as renderLogTailLines, l as deriveLiveStatus, o as controlCodeFromName, p as extractTaskCounts, tt as recordInbox, u as extractBadges } from "./subcommands-CqB9zo8_.js";
9
+ import { t as SUPPORTED_CLIS } from "./SUPPORTED_CLIS-DOwI2CmP.js";
10
+ import { A as renderRawLog, D as recentMessageEdges, E as readPtysize, L as snapshotStatus, M as resolveOne, O as recentReadEdges, S as listRecords, T as readNotes, U as writeToIpc, b as isUserTyping, et as TYPING_BADGE, f as extractNeedsInput, k as renderLogTailLines, l as deriveLiveStatus, o as controlCodeFromName, p as extractTaskCounts, tt as recordInbox, u as extractBadges } from "./subcommands-RnI0AkSK.js";
11
11
  import "./e2e-BeKjLhmO.js";
12
12
  import "./webrtcLink-BG0Xc4-W.js";
13
13
  import "./remotes-oSmwSYaV.js";
@@ -340,21 +340,26 @@ async function resolveActiveManager() {
340
340
  }
341
341
  return firstRunnable ?? resolveDaemonManager();
342
342
  }
343
- async function installAndVerify(pkg) {
344
- const bun = Bun.which("bun");
345
- const npm = Bun.which("npm");
346
- const installer = bun ? [
343
+ function installerArgv(pkg, bun, npm) {
344
+ if (bun) return [
347
345
  bun,
348
346
  "add",
349
347
  "-g",
348
+ ...pkg === "oxmgr" ? ["--trust"] : [],
350
349
  pkg
351
- ] : npm ? [
350
+ ];
351
+ if (npm) return [
352
352
  npm,
353
353
  "install",
354
354
  "-g",
355
355
  pkg
356
- ] : null;
356
+ ];
357
+ return null;
358
+ }
359
+ async function installAndVerify(pkg) {
360
+ const installer = installerArgv(pkg, Bun.which("bun"), Bun.which("npm"));
357
361
  if (!installer) return null;
362
+ await ensureNodeRuntime();
358
363
  process.stderr.write(`ay serve install: installing ${pkg}…\n`);
359
364
  const code = await Bun.spawn(installer, {
360
365
  stdio: [
@@ -1923,7 +1928,7 @@ Options:
1923
1928
  const perm = body.perm ?? "r";
1924
1929
  if (perm !== "r" && perm !== "rw") return new Response(`invalid perm ${perm} (want r or rw)`, { status: 400 });
1925
1930
  try {
1926
- const { createScopedShare } = await import("./agentShare-M2jaTMlH.js");
1931
+ const { createScopedShare } = await import("./agentShare-bCHRyHSj.js");
1927
1932
  const share = await createScopedShare({
1928
1933
  agent: body.agent,
1929
1934
  perm,
@@ -1938,12 +1943,12 @@ Options:
1938
1943
  }
1939
1944
  }
1940
1945
  if (req.method === "GET" && p === "/api/shares") {
1941
- const { listShares } = await import("./agentShare-M2jaTMlH.js");
1946
+ const { listShares } = await import("./agentShare-bCHRyHSj.js");
1942
1947
  return Response.json(listShares());
1943
1948
  }
1944
1949
  const revokeM = /^\/api\/share\/([^/]+)$/.exec(p);
1945
1950
  if (req.method === "DELETE" && revokeM) {
1946
- const { revokeShare } = await import("./agentShare-M2jaTMlH.js");
1951
+ const { revokeShare } = await import("./agentShare-bCHRyHSj.js");
1947
1952
  const ok = revokeShare(decodeURIComponent(revokeM[1]));
1948
1953
  return new Response(ok ? "revoked" : "no such share", { status: ok ? 200 : 404 });
1949
1954
  }
@@ -2125,7 +2130,7 @@ Options:
2125
2130
  const shutdown = (resolve) => {
2126
2131
  if (heartbeat) clearInterval(heartbeat);
2127
2132
  closeShare?.();
2128
- import("./agentShare-M2jaTMlH.js").then((m) => m.revokeAllShares()).catch(() => {});
2133
+ import("./agentShare-bCHRyHSj.js").then((m) => m.revokeAllShares()).catch(() => {});
2129
2134
  server?.stop();
2130
2135
  resolve();
2131
2136
  };
@@ -2138,4 +2143,4 @@ Options:
2138
2143
 
2139
2144
  //#endregion
2140
2145
  export { cmdServe };
2141
- //# sourceMappingURL=serve-Ce708ALB.js.map
2146
+ //# sourceMappingURL=serve-sTUSkXkr.js.map
@@ -32,7 +32,7 @@ async function cmdSetup(rest) {
32
32
  if (!existsSync(abs)) process.stderr.write(` note: that directory doesn't exist yet — create it, or agents spawned there will fail\n`);
33
33
  if (noShare) return 0;
34
34
  process.stdout.write(`\nsharing this machine to agent-yes.com…\n`);
35
- const { cmdServe } = await import("./serve-Ce708ALB.js");
35
+ const { cmdServe } = await import("./serve-sTUSkXkr.js");
36
36
  return cmdServe([
37
37
  "install",
38
38
  "--share",
@@ -42,4 +42,4 @@ async function cmdSetup(rest) {
42
42
 
43
43
  //#endregion
44
44
  export { cmdSetup };
45
- //# sourceMappingURL=setup-fTLT9Bf2.js.map
45
+ //# sourceMappingURL=setup-B03A9bDx.js.map
@@ -1,7 +1,7 @@
1
1
  import "./logger-CDIsZ-Pp.js";
2
2
  import "./globalPidIndex-CoNr7tS8.js";
3
3
  import "./configShared-0MnIQ652.js";
4
- import { A as renderRawLog, B as submitAndConfirm, C as matchKeyword, D as recentMessageEdges, E as readPtysize, F as restartHintLines, H as writeKeysPaced, I as runSubcommand, L as snapshotStatus, M as resolveOne, N as resolveReadWindow, O as recentReadEdges, P as resolveResumeArgs, R as stdinActivityPath, S as listRecords, T as readNotes, U as writeToIpc, V as waitForLogQuiet, _ as isPidAlive, a as cmdHelp, b as isUserTyping, c as deriveLiveState, d as extractMenu, f as extractNeedsInput, g as isExitRequest, h as isAgentStuck, i as backoffWhileTyping, j as renderRawLogLines, k as renderLogTailLines, l as deriveLiveStatus, m as finalizedLines, n as READ_PAGE_DEFAULT, o as controlCodeFromName, p as extractTaskCounts, r as TYPING_WINDOW_MS, s as cursorAbs, t as GRACEFUL_EXIT_COMMANDS, u as extractBadges, v as isSlashCommand, w as menuSelectKeys, x as lastStdinAt, y as isSubcommand, z as stopTipForCli } from "./subcommands-CqB9zo8_.js";
4
+ import { A as renderRawLog, B as submitAndConfirm, C as matchKeyword, D as recentMessageEdges, E as readPtysize, F as restartHintLines, H as writeKeysPaced, I as runSubcommand, L as snapshotStatus, M as resolveOne, N as resolveReadWindow, O as recentReadEdges, P as resolveResumeArgs, R as stdinActivityPath, S as listRecords, T as readNotes, U as writeToIpc, V as waitForLogQuiet, _ as isPidAlive, a as cmdHelp, b as isUserTyping, c as deriveLiveState, d as extractMenu, f as extractNeedsInput, g as isExitRequest, h as isAgentStuck, i as backoffWhileTyping, j as renderRawLogLines, k as renderLogTailLines, l as deriveLiveStatus, m as finalizedLines, n as READ_PAGE_DEFAULT, o as controlCodeFromName, p as extractTaskCounts, r as TYPING_WINDOW_MS, s as cursorAbs, t as GRACEFUL_EXIT_COMMANDS, u as extractBadges, v as isSlashCommand, w as menuSelectKeys, x as lastStdinAt, y as isSubcommand, z as stopTipForCli } from "./subcommands-RnI0AkSK.js";
5
5
  import "./e2e-BeKjLhmO.js";
6
6
  import "./webrtcLink-BG0Xc4-W.js";
7
7
  import "./remotes-oSmwSYaV.js";
@@ -1271,15 +1271,15 @@ async function runSubcommand(argv) {
1271
1271
  case "restart": return await cmdRestart(rest);
1272
1272
  case "note": return await cmdNote(rest);
1273
1273
  case "serve": {
1274
- const { cmdServe } = await import("./serve-Ce708ALB.js");
1274
+ const { cmdServe } = await import("./serve-sTUSkXkr.js");
1275
1275
  return cmdServe(rest);
1276
1276
  }
1277
1277
  case "setup": {
1278
- const { cmdSetup } = await import("./setup-fTLT9Bf2.js");
1278
+ const { cmdSetup } = await import("./setup-B03A9bDx.js");
1279
1279
  return cmdSetup(rest);
1280
1280
  }
1281
1281
  case "schedule": {
1282
- const { cmdSchedule } = await import("./schedule-1oS-Yxxa.js");
1282
+ const { cmdSchedule } = await import("./schedule-BVTk2aWT.js");
1283
1283
  return cmdSchedule(rest);
1284
1284
  }
1285
1285
  case "remote": {
@@ -4297,7 +4297,7 @@ async function cmdNotify(rest) {
4297
4297
  }
4298
4298
  const ensure = async () => {
4299
4299
  if (!argv["ensure-daemon"]) return;
4300
- const { ensureDaemon } = await import("./notifyDaemon-D5HwUMxH.js");
4300
+ const { ensureDaemon } = await import("./notifyDaemon-lPJrVB96.js");
4301
4301
  await ensureDaemon().catch(() => null);
4302
4302
  };
4303
4303
  await heartbeatWatcher(parent, selfStartedAt);
@@ -4371,7 +4371,7 @@ async function cmdNotifyCursor(args) {
4371
4371
  }
4372
4372
  async function cmdNotifyd(rest) {
4373
4373
  const sub = rest[0] ?? "status";
4374
- const daemon = await import("./notifyDaemon-D5HwUMxH.js");
4374
+ const daemon = await import("./notifyDaemon-lPJrVB96.js");
4375
4375
  switch (sub) {
4376
4376
  case "run": return daemon.runDaemon();
4377
4377
  case "once": return daemon.runDaemon({ once: true });
@@ -4398,4 +4398,4 @@ async function cmdNotifyd(rest) {
4398
4398
 
4399
4399
  //#endregion
4400
4400
  export { notifyDir as $, renderRawLog as A, submitAndConfirm as B, matchKeyword as C, recentMessageEdges as D, readPtysize as E, restartHintLines as F, gcInboxes as G, writeKeysPaced as H, runSubcommand as I, liveWatchers as J, hostId as K, snapshotStatus as L, resolveOne as M, resolveReadWindow as N, recentReadEdges as O, resolveResumeArgs as P, daemonLockOwnerPath as Q, stdinActivityPath as R, listRecords as S, readNotes as T, writeToIpc as U, waitForLogQuiet as V, appendEvent as W, shouldStealLock as X, readInbox as Y, daemonLockDir as Z, isPidAlive as _, cmdHelp as a, isUserTyping as b, deriveLiveState as c, extractMenu as d, TYPING_BADGE as et, extractNeedsInput as f, isExitRequest as g, isAgentStuck as h, backoffWhileTyping as i, renderRawLogLines as j, renderLogTailLines as k, deriveLiveStatus as l, finalizedLines as m, READ_PAGE_DEFAULT as n, controlCodeFromName as o, extractTaskCounts as p, listInboxParents as q, TYPING_WINDOW_MS as r, cursorAbs as s, GRACEFUL_EXIT_COMMANDS as t, recordInbox as tt, extractBadges as u, isSlashCommand as v, menuSelectKeys as w, lastStdinAt as x, isSubcommand as y, stopTipForCli as z };
4401
- //# sourceMappingURL=subcommands-CqB9zo8_.js.map
4401
+ //# sourceMappingURL=subcommands-RnI0AkSK.js.map
@@ -1,5 +1,5 @@
1
1
  import { n as logger, t as addTransport } from "./logger-CDIsZ-Pp.js";
2
- import { r as getInstalledPackage } from "./versionChecker-B8qEzYDu.js";
2
+ import { r as getInstalledPackage } from "./versionChecker-BGywS-RN.js";
3
3
  import { t as agentYesHome } from "./agentYesHome-CtHb5b71.js";
4
4
  import { i as shouldUseLock, r as releaseLock, t as acquireLock } from "./runningLock-CNMl13dC.js";
5
5
  import { t as PidStore } from "./pidStore-BIvsBQ8X.js";
@@ -1824,4 +1824,4 @@ function sleep(ms) {
1824
1824
 
1825
1825
  //#endregion
1826
1826
  export { removeControlCharacters as a, AgentContext as i, agentYes as n, config as r, CLIS_CONFIG as t };
1827
- //# sourceMappingURL=ts-DDsICrj-.js.map
1827
+ //# sourceMappingURL=ts-CHkgLvsJ.js.map
@@ -7,7 +7,7 @@ import { fileURLToPath } from "url";
7
7
 
8
8
  //#region package.json
9
9
  var name = "agent-yes";
10
- var version = "1.195.0";
10
+ var version = "1.196.1";
11
11
 
12
12
  //#endregion
13
13
  //#region ts/versionChecker.ts
@@ -215,4 +215,4 @@ async function displayVersion() {
215
215
 
216
216
  //#endregion
217
217
  export { versionString as i, displayVersion as n, getInstalledPackage as r, checkAndAutoUpdate as t };
218
- //# sourceMappingURL=versionChecker-B8qEzYDu.js.map
218
+ //# sourceMappingURL=versionChecker-BGywS-RN.js.map
package/lab/ui/index.html CHANGED
@@ -2306,6 +2306,10 @@
2306
2306
  previewFetch(port, method, path, init) {
2307
2307
  return chRoom.room.fetch(peerId, method, "/__codehost/port/" + port + path, init || {});
2308
2308
  },
2309
+ // Open a WS to the previewed port over the tunnel (Vite HMR etc.).
2310
+ previewWs(port, path, protocols, handlers) {
2311
+ return chRoom.room.openWs(peerId, "/__codehost/port/" + port + path, protocols, handlers);
2312
+ },
2309
2313
  async fetchJSON(path) {
2310
2314
  let res;
2311
2315
  try {
@@ -2599,6 +2603,98 @@
2599
2603
  .catch((err) => port.postMessage({ type: "error", message: String(err) }));
2600
2604
  });
2601
2605
  }
2606
+
2607
+ // A window.WebSocket replacement, bound to a preview source+port, that
2608
+ // tunnels over the codehost DataChannel (previewWs → the daemon's port WS)
2609
+ // instead of the network. The preview iframe's injected bootstrap installs
2610
+ // it as window.WebSocket so a dev server's HMR socket goes P2P too.
2611
+ // previewWs is async (it dials the peer), so sends before open are queued.
2612
+ window.__ayMakeWS = function (src, port) {
2613
+ return class PreviewWebSocket {
2614
+ static CONNECTING = 0;
2615
+ static OPEN = 1;
2616
+ static CLOSING = 2;
2617
+ static CLOSED = 3;
2618
+ CONNECTING = 0;
2619
+ OPEN = 1;
2620
+ CLOSING = 2;
2621
+ CLOSED = 3;
2622
+ constructor(url, protocols) {
2623
+ this.url = String(url);
2624
+ this.readyState = 0; // CONNECTING
2625
+ this.binaryType = "blob";
2626
+ this.protocol = "";
2627
+ this._listeners = {};
2628
+ this._handle = null;
2629
+ this._queue = [];
2630
+ const tx = sources.get(src)?.tx;
2631
+ const u = new URL(this.url, location.href);
2632
+ const protoList = protocols ? (Array.isArray(protocols) ? protocols : [protocols]) : undefined;
2633
+ if (!tx || !tx.previewWs) return void this._fail();
2634
+ tx.previewWs(port, u.pathname + u.search, protoList, {
2635
+ onOpenAck: (ok, proto) => {
2636
+ if (!ok) return this._fail();
2637
+ this.readyState = 1;
2638
+ this.protocol = proto || "";
2639
+ this._dispatch("open", {});
2640
+ for (const m of this._queue) this._rawSend(m);
2641
+ this._queue = [];
2642
+ },
2643
+ onText: (t) => this._dispatch("message", { data: t }),
2644
+ onBin: (d) => this._dispatch("message", { data: this._wrap(d) }),
2645
+ onClose: (code, reason) => {
2646
+ this.readyState = 3;
2647
+ this._dispatch("close", { code, reason, wasClean: code === 1000 });
2648
+ },
2649
+ })
2650
+ .then((h) => {
2651
+ this._handle = h;
2652
+ if (this.readyState === 3 && this._closeReq) h.close(this._closeReq.code, this._closeReq.reason);
2653
+ })
2654
+ .catch(() => this._fail());
2655
+ }
2656
+ _wrap(d) {
2657
+ return this.binaryType === "arraybuffer"
2658
+ ? d.buffer.slice(d.byteOffset, d.byteOffset + d.byteLength)
2659
+ : new Blob([d]);
2660
+ }
2661
+ _rawSend(data) {
2662
+ const h = this._handle;
2663
+ if (!h) return;
2664
+ if (typeof data === "string") h.sendText(data);
2665
+ else if (data instanceof Blob) data.arrayBuffer().then((b) => h.sendBin(new Uint8Array(b)));
2666
+ else if (ArrayBuffer.isView(data)) h.sendBin(new Uint8Array(data.buffer, data.byteOffset, data.byteLength));
2667
+ else h.sendBin(new Uint8Array(data));
2668
+ }
2669
+ send(data) {
2670
+ if (this.readyState === 0) this._queue.push(data);
2671
+ else if (this.readyState === 1) this._rawSend(data);
2672
+ }
2673
+ close(code, reason) {
2674
+ if (this.readyState === 3) return;
2675
+ this.readyState = 3;
2676
+ if (this._handle) this._handle.close(code, reason);
2677
+ else this._closeReq = { code, reason };
2678
+ this._dispatch("close", { code: code || 1000, reason: reason || "", wasClean: true });
2679
+ }
2680
+ _fail() {
2681
+ this.readyState = 3;
2682
+ this._dispatch("error", {});
2683
+ this._dispatch("close", { code: 1006, reason: "tunnel open failed", wasClean: false });
2684
+ }
2685
+ addEventListener(t, l) {
2686
+ (this._listeners[t] = this._listeners[t] || new Set()).add(l);
2687
+ }
2688
+ removeEventListener(t, l) {
2689
+ this._listeners[t]?.delete(l);
2690
+ }
2691
+ _dispatch(t, init) {
2692
+ const ev = { type: t, target: this, ...init };
2693
+ this["on" + t]?.call(this, ev);
2694
+ this._listeners[t]?.forEach((l) => l.call(this, ev));
2695
+ }
2696
+ };
2697
+ };
2602
2698
  // Every machine belonging to a room (for an ay-share room, the room itself).
2603
2699
  const roomSources = (name) => [...sources.values()].filter((s) => (s.room || s.id) === name);
2604
2700
  const roomLive = (name) =>