@flowriki/agent 0.1.0-beta.14 → 0.1.0-beta.17

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.
@@ -6,7 +6,7 @@ import os from "os";
6
6
  import path from "path";
7
7
  import { createRequire } from "module";
8
8
  import { spawnSync } from "child_process";
9
- var AGENT_VERSION = "0.1.0-beta.14";
9
+ var AGENT_VERSION = "0.1.0-beta.17";
10
10
  async function prepareBrowsers() {
11
11
  if (browsersReady()) {
12
12
  return { ok: true, already: true, message: "chromium is already installed" };
@@ -2985,7 +2985,7 @@ var RunActors = class {
2985
2985
  this.current = session;
2986
2986
  this.currentId = id;
2987
2987
  if (this.initialized.has(id)) return;
2988
- await session.page.goto(startUrl, { waitUntil: "domcontentloaded" });
2988
+ if (startUrl) await session.page.goto(startUrl, { waitUntil: "domcontentloaded" });
2989
2989
  if (actor?.startSignedIn) {
2990
2990
  if (kept?.state) {
2991
2991
  const confirmed = await confirmSignedIn(session.page, kept.auth, this.opts.reuseCheckMs ?? 3e3);
@@ -3027,7 +3027,7 @@ var RunActors = class {
3027
3027
  } catch {
3028
3028
  }
3029
3029
  }
3030
- await session.page.goto(startUrl, { waitUntil: "domcontentloaded" });
3030
+ if (startUrl) await session.page.goto(startUrl, { waitUntil: "domcontentloaded" });
3031
3031
  }
3032
3032
  this.initialized.add(id);
3033
3033
  }
@@ -3919,6 +3919,12 @@ var checkStep = (id, proposals) => ({
3919
3919
  legacySelector: "",
3920
3920
  proposals
3921
3921
  });
3922
+ function opensItsOwnEntry(steps, opts) {
3923
+ const first = steps.find((step) => !step.disabled);
3924
+ if (!first || first.type !== "signIn" || !first.auth) return false;
3925
+ if (first.auth.from === "here") return false;
3926
+ return opts.resolveAuth?.(first.auth)?.navigation.kind === "open";
3927
+ }
3922
3928
  function stepFailure(step, detail) {
3923
3929
  return {
3924
3930
  stepId: step.id,
@@ -3940,7 +3946,9 @@ async function runStepsIn(session, steps, opts) {
3940
3946
  let status2 = "passed";
3941
3947
  let error = null;
3942
3948
  try {
3943
- if (opts.startUrl) await page.goto(opts.startUrl, { waitUntil: "domcontentloaded" });
3949
+ if (opts.startUrl && !opensItsOwnEntry(steps, opts)) {
3950
+ await page.goto(opts.startUrl, { waitUntil: "domcontentloaded" });
3951
+ }
3944
3952
  for (const recorded of steps) {
3945
3953
  let step = recorded;
3946
3954
  if (!recorded.disabled) {
@@ -4158,8 +4166,9 @@ async function replayFlow(opts) {
4158
4166
  hydrated: hydrated ? { ...hydrated, id: opts.defaultActorId ?? "default" } : null
4159
4167
  });
4160
4168
  let prepared = null;
4169
+ const entry = opensItsOwnEntry(steps, opts) ? "" : void 0;
4161
4170
  try {
4162
- await actors.select(opts.defaultActorId ?? "default");
4171
+ await actors.select(opts.defaultActorId ?? "default", entry);
4163
4172
  } catch (e) {
4164
4173
  prepared = e.message;
4165
4174
  }
@@ -4780,15 +4789,20 @@ async function startRecordingSession(opts) {
4780
4789
  const page = await context.newPage();
4781
4790
  if (opts.authentication) {
4782
4791
  try {
4783
- await page.goto(url, { waitUntil: "domcontentloaded" });
4792
+ const runnable = opts.authentication.step.auth ? opts.authentication.resolveAuth(opts.authentication.step.auth) : void 0;
4793
+ if (!runnable || runnable.navigation.kind === "continue") {
4794
+ await page.goto(url, { waitUntil: "domcontentloaded" });
4795
+ }
4784
4796
  await executeStep(page, opts.authentication.step, { ...opts.authentication, baseUrl: url });
4785
- const resume = { id: "auth-return", type: "navigate", name: "Open recording start page", role: "", scope: "", value: new URL(url).pathname + new URL(url).search + new URL(url).hash, navigationBase: "application", secret: false, legacySelector: "", proposals: [] };
4786
- steps.push(opts.authentication.step, resume);
4797
+ steps.push(opts.authentication.step);
4787
4798
  onStep?.(opts.authentication.step);
4788
- onStep?.(resume);
4789
4799
  } catch (error) {
4790
- await browser.close();
4791
- throw error;
4800
+ const landed = await page.url().replace(/^https?:\/\/[^/]+/, "");
4801
+ const title = await page.title().catch(() => "");
4802
+ stopped = true;
4803
+ await browser.close().catch(() => {
4804
+ });
4805
+ throw new Error(`${firstLine2(error)} \u2014 the browser was on ${landed || "/"}${title ? ` ("${title}")` : ""}`);
4792
4806
  }
4793
4807
  }
4794
4808
  await context.addInitScript({ content: INIT_SCRIPT });
@@ -4843,7 +4857,8 @@ async function startRecordingSession(opts) {
4843
4857
  });
4844
4858
  });
4845
4859
  try {
4846
- await page.goto(url, { waitUntil: "domcontentloaded", timeout: 45e3 });
4860
+ if (!opts.authentication) await page.goto(url, { waitUntil: "domcontentloaded", timeout: 45e3 });
4861
+ else await ensureInstalled(page);
4847
4862
  } catch (err) {
4848
4863
  stopped = true;
4849
4864
  await browser.close().catch(() => {
@@ -5176,7 +5191,11 @@ async function startDebugSession(opts) {
5176
5191
  publish();
5177
5192
  });
5178
5193
  await context2.exposeBinding("__flCmd", (_src, msg) => {
5179
- void handleCommand(msg);
5194
+ void handleCommand(msg).catch((error) => {
5195
+ failure = { stepId: cursor ?? steps[0]?.id ?? "", error: firstLine2(error) };
5196
+ status2 = "paused";
5197
+ void paint(snapshot());
5198
+ });
5180
5199
  });
5181
5200
  await context2.addInitScript({ content: `${accNameScript2()}
5182
5201
  ;(${installRecorder.toString()})();
@@ -6291,7 +6310,7 @@ function toSummary(row) {
6291
6310
  };
6292
6311
  }
6293
6312
 
6294
- // ../repository-store/dist/chunk-IXRMPDVC.js
6313
+ // ../repository-store/dist/chunk-QSTSWM2T.js
6295
6314
  var FLOWRIKI_DIR = ".flowriki";
6296
6315
  var FEATURES_DIR = `${FLOWRIKI_DIR}/features`;
6297
6316
  var CONFIG_PATH = `${FLOWRIKI_DIR}/config.json`;
package/dist/cli.js CHANGED
@@ -8,7 +8,7 @@ import {
8
8
  resolveCheckouts,
9
9
  start,
10
10
  status
11
- } from "./chunk-OMYFENN7.js";
11
+ } from "./chunk-NTARVVKX.js";
12
12
 
13
13
  // src/cli.ts
14
14
  import { parseArgs } from "util";
@@ -111,6 +111,11 @@ Run \`flowriki-agent --help\`.`);
111
111
  return 0;
112
112
  }
113
113
  case "start": {
114
+ process.on("unhandledRejection", (reason) => {
115
+ const said = reason instanceof Error ? reason.stack ?? reason.message : String(reason);
116
+ console.error(red(`! a command failed without being handled \u2014 the agent is still running`));
117
+ console.error(dim(said.split("\n").slice(0, 4).join("\n")));
118
+ });
114
119
  const started = await start({
115
120
  ...service ? { service } : {},
116
121
  ...projects.length ? { projects } : {},
package/dist/engine.js CHANGED
@@ -9,7 +9,7 @@ import {
9
9
  resolveCheckouts,
10
10
  start,
11
11
  status
12
- } from "./chunk-OMYFENN7.js";
12
+ } from "./chunk-NTARVVKX.js";
13
13
  export {
14
14
  AGENT_VERSION,
15
15
  browsersReady,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flowriki/agent",
3
- "version": "0.1.0-beta.14",
3
+ "version": "0.1.0-beta.17",
4
4
  "description": "Run Flowriki UI tests on your own computer. Connects this machine to your Flowriki account.",
5
5
  "license": "SEE LICENSE IN LICENSE",
6
6
  "type": "module",