@autohq/cli 0.1.234 → 0.1.236

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.
@@ -23340,7 +23340,7 @@ Object.assign(lookup, {
23340
23340
  // package.json
23341
23341
  var package_default = {
23342
23342
  name: "@autohq/cli",
23343
- version: "0.1.234",
23343
+ version: "0.1.236",
23344
23344
  license: "SEE LICENSE IN README.md",
23345
23345
  publishConfig: {
23346
23346
  access: "public"
package/dist/index.js CHANGED
@@ -22339,7 +22339,7 @@ var init_package = __esm({
22339
22339
  "package.json"() {
22340
22340
  package_default = {
22341
22341
  name: "@autohq/cli",
22342
- version: "0.1.234",
22342
+ version: "0.1.236",
22343
22343
  license: "SEE LICENSE IN README.md",
22344
22344
  publishConfig: {
22345
22345
  access: "public"
@@ -28598,6 +28598,12 @@ import { Box as Box13, Text as Text14, useApp as useApp2, useInput as useInput4,
28598
28598
  import TextInput3 from "ink-text-input";
28599
28599
  import { useCallback as useCallback2, useEffect as useEffect3, useMemo as useMemo3, useRef as useRef2, useState as useState3 } from "react";
28600
28600
  import { Fragment as Fragment3, jsx as jsx14, jsxs as jsxs12 } from "react/jsx-runtime";
28601
+ function shouldAutoStartBrowserLogin(input) {
28602
+ return !input.startedServerUrls.has(browserLoginServerKey(input.serverUrl));
28603
+ }
28604
+ function browserLoginServerKey(serverUrl) {
28605
+ return serverUrl.trim();
28606
+ }
28601
28607
  function resourceNavItem(input) {
28602
28608
  const definition = PROJECT_RESOURCE_TUI_DEFINITIONS_BY_SECTION.get(
28603
28609
  input.section
@@ -28661,11 +28667,18 @@ function inspectableResourceForSelection(input) {
28661
28667
  const selected = selectedNamedResourceForSection(input);
28662
28668
  return definition && selected ? { kind: definition.kind, name: selected.metadata.name, spec: null } : null;
28663
28669
  }
28664
- function HomeView({ apiUrl, notice, returnToAgent }) {
28670
+ function HomeView({
28671
+ apiUrl,
28672
+ browserLoginAutoStartedServers,
28673
+ configPath,
28674
+ notice,
28675
+ returnToAgent
28676
+ }) {
28665
28677
  const client = useApiClient();
28666
28678
  const queryClient = useQueryClient2();
28667
28679
  const { exit } = useApp2();
28668
28680
  const { stdout } = useStdout7();
28681
+ const fallbackBrowserLoginAutoStartedServers = useRef2(/* @__PURE__ */ new Set());
28669
28682
  const [termSize, setTermSize] = useState3({
28670
28683
  width: stdout?.columns ?? 120,
28671
28684
  height: stdout?.rows ?? 24
@@ -29856,6 +29869,8 @@ function HomeView({ apiUrl, notice, returnToAgent }) {
29856
29869
  return /* @__PURE__ */ jsx14(
29857
29870
  BrowserLoginPrompt,
29858
29871
  {
29872
+ autoStartedServerUrls: browserLoginAutoStartedServers ?? fallbackBrowserLoginAutoStartedServers.current,
29873
+ configPath,
29859
29874
  error: authErrorMessage,
29860
29875
  height: termHeight,
29861
29876
  serverUrl: loginServerUrl
@@ -30324,6 +30339,8 @@ function shortSessionId2(id) {
30324
30339
  return tail ? tail.slice(0, 12) : id.slice(0, 12);
30325
30340
  }
30326
30341
  function BrowserLoginPrompt({
30342
+ autoStartedServerUrls,
30343
+ configPath,
30327
30344
  error: error51,
30328
30345
  height,
30329
30346
  serverUrl
@@ -30331,41 +30348,59 @@ function BrowserLoginPrompt({
30331
30348
  const queryClient = useQueryClient2();
30332
30349
  const { exit } = useApp2();
30333
30350
  const [loginError, setLoginError] = useState3(null);
30334
- const [status, setStatus] = useState3(
30335
- "opening"
30336
- );
30351
+ const [status, setStatus] = useState3("idle");
30352
+ const loginInFlight = useRef2(false);
30353
+ const mounted = useRef2(true);
30337
30354
  useEffect3(() => {
30338
- let cancelled = false;
30339
- async function runBrowserLogin() {
30340
- try {
30341
- setStatus("opening");
30342
- await login({
30343
- options: { apiUrl: serverUrl },
30344
- fetch,
30345
- writeOutput: () => {
30346
- }
30347
- });
30348
- if (cancelled) return;
30349
- setStatus("done");
30350
- await queryClient.invalidateQueries();
30351
- } catch (err) {
30352
- if (!cancelled) {
30353
- setLoginError(err instanceof Error ? err.message : String(err));
30355
+ return () => {
30356
+ mounted.current = false;
30357
+ };
30358
+ }, []);
30359
+ const startBrowserLogin = useCallback2(async () => {
30360
+ if (loginInFlight.current) {
30361
+ return;
30362
+ }
30363
+ loginInFlight.current = true;
30364
+ setLoginError(null);
30365
+ setStatus("waiting");
30366
+ try {
30367
+ await login({
30368
+ options: { apiUrl: serverUrl },
30369
+ env: process.env,
30370
+ fetch,
30371
+ configPath,
30372
+ writeOutput: () => {
30354
30373
  }
30374
+ });
30375
+ if (!mounted.current) {
30376
+ return;
30355
30377
  }
30378
+ setStatus("done");
30379
+ await queryClient.invalidateQueries();
30380
+ } catch (err) {
30381
+ if (!mounted.current) {
30382
+ return;
30383
+ }
30384
+ setStatus("idle");
30385
+ setLoginError(err instanceof Error ? err.message : String(err));
30386
+ } finally {
30387
+ loginInFlight.current = false;
30356
30388
  }
30357
- void runBrowserLogin();
30358
- return () => {
30359
- cancelled = true;
30360
- };
30361
- }, [queryClient, serverUrl]);
30389
+ }, [configPath, queryClient, serverUrl]);
30362
30390
  useEffect3(() => {
30363
- if (status === "opening") {
30364
- setStatus("waiting");
30365
- }
30366
- }, [status]);
30367
- useInput4((input) => {
30391
+ if (shouldAutoStartBrowserLogin({
30392
+ serverUrl,
30393
+ startedServerUrls: autoStartedServerUrls
30394
+ })) {
30395
+ autoStartedServerUrls.add(browserLoginServerKey(serverUrl));
30396
+ void startBrowserLogin();
30397
+ }
30398
+ }, [autoStartedServerUrls, serverUrl, startBrowserLogin]);
30399
+ useInput4((input, key) => {
30368
30400
  if (input === "q") exit();
30401
+ if ((key.return || input === "l") && status !== "waiting") {
30402
+ void startBrowserLogin();
30403
+ }
30369
30404
  });
30370
30405
  return /* @__PURE__ */ jsxs12(
30371
30406
  Box13,
@@ -30379,14 +30414,29 @@ function BrowserLoginPrompt({
30379
30414
  children: [
30380
30415
  /* @__PURE__ */ jsx14(Text14, { color: "yellow", bold: true, children: "Login required" }),
30381
30416
  /* @__PURE__ */ jsx14(Text14, { children: error51 }),
30382
- /* @__PURE__ */ jsxs12(Box13, { marginTop: 1, flexDirection: "column", alignItems: "center", children: [
30417
+ /* @__PURE__ */ jsx14(Box13, { marginTop: 1, flexDirection: "column", alignItems: "center", children: status === "waiting" ? /* @__PURE__ */ jsxs12(Fragment3, { children: [
30383
30418
  /* @__PURE__ */ jsxs12(Text14, { children: [
30384
30419
  "Opening ",
30385
30420
  /* @__PURE__ */ jsx14(Text14, { color: "cyan", children: serverUrl }),
30386
30421
  " in your browser."
30387
30422
  ] }),
30388
30423
  /* @__PURE__ */ jsx14(Text14, { dimColor: true, children: "Complete authorization there to return to Auto." })
30389
- ] }),
30424
+ ] }) : status === "done" ? /* @__PURE__ */ jsxs12(Fragment3, { children: [
30425
+ /* @__PURE__ */ jsxs12(Text14, { children: [
30426
+ "Browser authorization completed for",
30427
+ " ",
30428
+ /* @__PURE__ */ jsx14(Text14, { color: "cyan", children: serverUrl }),
30429
+ "."
30430
+ ] }),
30431
+ /* @__PURE__ */ jsx14(Text14, { dimColor: true, children: "Refreshing Auto data." })
30432
+ ] }) : /* @__PURE__ */ jsxs12(Fragment3, { children: [
30433
+ /* @__PURE__ */ jsxs12(Text14, { children: [
30434
+ "Browser login is ready for ",
30435
+ /* @__PURE__ */ jsx14(Text14, { color: "cyan", children: serverUrl }),
30436
+ "."
30437
+ ] }),
30438
+ /* @__PURE__ */ jsx14(Text14, { dimColor: true, children: "Press Enter to open it again." })
30439
+ ] }) }),
30390
30440
  status === "waiting" && /* @__PURE__ */ jsx14(Box13, { marginTop: 1, children: /* @__PURE__ */ jsx14(Spinner, { label: "waiting for browser authorization\u2026" }) }),
30391
30441
  status === "done" && /* @__PURE__ */ jsxs12(Box13, { marginTop: 1, flexDirection: "column", alignItems: "center", children: [
30392
30442
  /* @__PURE__ */ jsx14(Text14, { color: "green", children: "Logged in." }),
@@ -30394,9 +30444,9 @@ function BrowserLoginPrompt({
30394
30444
  ] }),
30395
30445
  loginError && /* @__PURE__ */ jsxs12(Box13, { marginTop: 1, flexDirection: "column", alignItems: "center", children: [
30396
30446
  /* @__PURE__ */ jsx14(Text14, { color: "red", children: loginError }),
30397
- /* @__PURE__ */ jsx14(Text14, { dimColor: true, children: "Press q to quit." })
30447
+ /* @__PURE__ */ jsx14(Text14, { dimColor: true, children: "Press Enter to retry, or q to quit." })
30398
30448
  ] }),
30399
- !loginError && /* @__PURE__ */ jsx14(Box13, { marginTop: 1, children: /* @__PURE__ */ jsx14(Text14, { dimColor: true, children: "Press q to quit." }) })
30449
+ !loginError && status !== "done" && /* @__PURE__ */ jsx14(Box13, { marginTop: 1, children: /* @__PURE__ */ jsx14(Text14, { dimColor: true, children: "Press Enter to retry, or q to quit." }) })
30400
30450
  ]
30401
30451
  }
30402
30452
  );
@@ -30735,12 +30785,15 @@ async function launch(opts) {
30735
30785
  );
30736
30786
  let returnToAgent;
30737
30787
  let notice;
30788
+ const browserLoginAutoStartedServers = /* @__PURE__ */ new Set();
30738
30789
  try {
30739
30790
  while (true) {
30740
30791
  const { waitUntilExit } = render(
30741
30792
  providers(
30742
30793
  React.createElement(HomeView, {
30743
30794
  apiUrl,
30795
+ browserLoginAutoStartedServers,
30796
+ configPath: opts.configPath,
30744
30797
  notice,
30745
30798
  returnToAgent
30746
30799
  })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@autohq/cli",
3
- "version": "0.1.234",
3
+ "version": "0.1.236",
4
4
  "license": "SEE LICENSE IN README.md",
5
5
  "publishConfig": {
6
6
  "access": "public"