postgresai 0.18.0-dev.11 → 0.18.0-dev.12

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
@@ -224,6 +224,12 @@ the Console (Monitoring, then the instance). A database that must stay behind an
224
224
  needs AWS PrivateLink (RDS) or self-hosted monitoring (`--self-hosted`).
225
225
 
226
226
  Without `--provider`, RDS hostnames still go to their console integration, and Supabase hostnames to the Supabase consent flow (`pgai mon deploy` for Supabase).
227
+
228
+ A Supabase project needs no URL at all: `pgai mon deploy --provider supabase` connects the Supabase organization
229
+ if needed and lists its projects. At a terminal you pick one; agents and scripts pass
230
+ `--supabase-project <name or project ID>`. Without either, with `--yes`, or not at a terminal, it stops (exit 3) with the list
231
+ in the JSON result (`projects`, each with `selectable` and `reason`). The vCPUs come from the project's compute size.
232
+
227
233
  `generic` does not configure AWS PrivateLink, open a firewall, or remove TLS, permission, or
228
234
  payment checks. A private endpoint needs a network path, or monitoring hosted in that network
229
235
  (`--self-hosted`).
@@ -13533,7 +13533,7 @@ var {
13533
13533
  // package.json
13534
13534
  var package_default = {
13535
13535
  name: "postgresai",
13536
- version: "0.18.0-dev.11",
13536
+ version: "0.18.0-dev.12",
13537
13537
  description: "postgres_ai CLI",
13538
13538
  license: "Apache-2.0",
13539
13539
  private: false,
@@ -16893,7 +16893,7 @@ var Result = import_lib.default.Result;
16893
16893
  var TypeOverrides = import_lib.default.TypeOverrides;
16894
16894
  var defaults = import_lib.default.defaults;
16895
16895
  // package.json
16896
- var version = "0.18.0-dev.11";
16896
+ var version = "0.18.0-dev.12";
16897
16897
  var package_default2 = {
16898
16898
  name: "postgresai",
16899
16899
  version,
@@ -22988,6 +22988,10 @@ function connectStatus(row, provider = row.provider, fresh = false) {
22988
22988
  return { ...base, status, next: `pgai mon instances delete ${row.id} --yes, then pgai mon deploy again` };
22989
22989
  return { ...base, status, next: `pgai mon instances watch ${row.id}` };
22990
22990
  }
22991
+ var ESCAPES = /(?:\x1b\[|\x9b)[0-?]*[ -\/]*[@-~]|(?:\x1b\]|\x9d)[^\x07\x1b\x9c]*(?:\x07|\x1b\\|\x9c)?|\x1b[ -~]?/g;
22992
+ var terminalText = (text) => text.replace(ESCAPES, "").split(`
22993
+ `).map(stripControlsToSpace).join(`
22994
+ `);
22991
22995
  var boxState = (row) => row.status === "launch_requested" && row.registered_at ? "registered" : row.status ?? "starting";
22992
22996
  function boxWords(state) {
22993
22997
  if (!state || state === "starting" || state === "launch_requested")
@@ -23010,7 +23014,7 @@ async function billingFor(q, name, opts, deps, show) {
23010
23014
  if (q.requires_payment_method)
23011
23015
  return { billing, billingPage, billingUrl, accepted: false, stop: billingPage };
23012
23016
  show(billing.price);
23013
- if (q.billed && !opts.yes && !await deps.confirm(`Provision ${name}? (y/N): `)) {
23017
+ if (q.billed && !opts.yes && !await deps.confirm(`Provision ${terminalText(name)}? (y/N): `)) {
23014
23018
  return stop(opts.agent ? `Call deploy_monitoring again with yes: true to accept ${billing.price}` : `Re-run with --yes to accept ${billing.price}`);
23015
23019
  }
23016
23020
  return { billing, billingPage, billingUrl, accepted: q.billed };
@@ -23030,9 +23034,20 @@ async function connect(url, opts, deps) {
23030
23034
  warned.add(message);
23031
23035
  progress(step, message);
23032
23036
  };
23033
- const provider = providerArg(opts.provider) ?? detectCloudProvider(url);
23037
+ const project = opts.supabaseProject?.trim();
23038
+ const provider = providerArg(opts.provider) ?? (!url && project ? "supabase" : detectCloudProvider(url));
23034
23039
  if (!PROVIDERS.includes(provider))
23035
23040
  throw new Error(`--provider must be one of: generic, ${PROVIDERS.join(", ")}`);
23041
+ if (project !== undefined && provider !== "supabase") {
23042
+ return { status: "action_required", provider, name: url ? databaseName2(url) : "", next: "--supabase-project applies to Supabase only: leave it out, or use --provider supabase" };
23043
+ }
23044
+ if (!url) {
23045
+ if (provider !== "supabase")
23046
+ return { status: "action_required", provider, name: "", next: "Pass the database URL: pgai mon deploy postgresql://user:password@host:5432/dbname (Supabase: --provider supabase)" };
23047
+ if (opts.selfHosted)
23048
+ return { status: "action_required", provider, name: "", next: "--self-hosted needs the database URL: pass the project's connection string" };
23049
+ return deploySupabaseProject(undefined, opts, deps, progress);
23050
+ }
23036
23051
  assertEncodedUserinfo(url);
23037
23052
  if (!opts.selfHosted && provider === "supabase")
23038
23053
  return deploySupabase(url, opts, deps, progress);
@@ -23319,29 +23334,25 @@ async function deploySupabase(url, opts, deps, progress) {
23319
23334
  const provider = "supabase";
23320
23335
  const ref = extractProjectRefFromUrl(url);
23321
23336
  if (!ref)
23322
- return { status: "action_required", provider, name: databaseName2(url), next: "Not a Supabase project URL: use the project's connection string (db.<project-ref>.supabase.co, or the pooler with user postgres.<project-ref>)" };
23337
+ return { status: "action_required", provider, name: databaseName2(url), next: "Not a Supabase project URL: use the project's connection string (db.<project-ref>.supabase.co, or the pooler with user postgres.<project-ref>), or pass --provider supabase without a URL to pick the project" };
23323
23338
  const db = decodeURIComponent(new URL(url).pathname.replace(/^\//, "")) || "postgres";
23324
- const project = `postgresql://db.${ref}.supabase.co:5432/${encodeURIComponent(db)}`;
23325
- const name = databaseName2(project);
23326
- const cluster = clusterOf(project);
23339
+ const name = databaseName2(supabaseProjectUrl(ref, db));
23327
23340
  const stop = (next, more = {}) => ({ status: "action_required", provider, name, ...more, next });
23328
23341
  if (db !== "postgres")
23329
23342
  return stop("PostgresAI monitors a Supabase project through its postgres database: use the URL of the postgres database");
23330
- if (opts.resetPassword)
23331
- return stop("--reset-password does not apply to Supabase: PostgresAI creates postgres_ai_mon through the Supabase Management API");
23332
- if (opts.location)
23333
- return stop("--location does not apply to Supabase yet (PostgresAI picks the box's location): re-run without it");
23334
- if (opts.monitoringUser !== undefined && opts.monitoringUser.trim() !== DEFAULT_MONITORING_USER) {
23335
- return stop(`${opts.agent ? "monitoring_user" : "--monitoring-user"} does not apply to Supabase: PostgresAI creates ${DEFAULT_MONITORING_USER} through the Supabase Management API`);
23336
- }
23337
- const row = (await deps.list()).find((d) => !disconnecting(d.status) && d.cluster && serverOf(d.cluster) === cluster && (!d.database || d.database === "postgres"));
23343
+ const refused = supabaseOptionsRefused(opts);
23344
+ if (refused)
23345
+ return stop(refused);
23346
+ if (opts.supabaseProject?.trim())
23347
+ return deploySupabaseProject(ref, opts, deps, progress);
23348
+ const row = await boxOnProject(ref, deps);
23338
23349
  if (row) {
23339
23350
  const note = opts.name && row.name !== opts.name ? `; --name ignored: this database is already monitored as ${row.name}` : "";
23340
23351
  return follow(row, { provider, name, fresh: false, billing: {}, note }, opts, deps, progress);
23341
23352
  }
23342
23353
  let started;
23343
23354
  try {
23344
- started = await deps.supabaseStart(project);
23355
+ started = await deps.supabaseStart(supabaseProjectUrl(ref));
23345
23356
  } catch (err) {
23346
23357
  if (err instanceof HttpStatusError && err.status === 403)
23347
23358
  return stop(notAdminNext);
@@ -23350,30 +23361,170 @@ async function deploySupabase(url, opts, deps, progress) {
23350
23361
  throw err;
23351
23362
  }
23352
23363
  if ("auth_url" in started) {
23353
- if (!isSupabaseUrl(started.auth_url))
23354
- return { status: "failed", provider, name, next: `The platform sent a Supabase consent link that is not ${SUPABASE_API_BASE}: not opened. Re-run pgai mon deploy later.` };
23355
- const approve = `Open ${started.auth_url} in a browser and approve PostgresAI's access to Supabase`;
23356
- if (opts.agent || opts.waitMs <= 0)
23357
- return stop(`${approve}, then ${opts.agent ? "call deploy_monitoring again" : "re-run"}`);
23358
- progress("preparing", `Connect Supabase to PostgresAI: approve access in the browser (open ${started.auth_url} if it did not open). Waiting...`, { auth_url: started.auth_url });
23359
- deps.openUrl?.(started.auth_url);
23360
- const expires = started.expires_at ? Date.parse(started.expires_at) : NaN;
23361
- for (const deadline = deps.now() + Math.min(opts.waitMs, OAUTH_WAIT_MS);; ) {
23362
- if (deps.aborted?.())
23363
- throw new CancelledError;
23364
- const s = await deps.supabaseStatus(started.session_id);
23365
- if (s.status === "connected")
23366
- break;
23367
- if (s.status === "error")
23368
- return stop(`Supabase did not connect (${s.error ?? "no reason given"}): re-run to try again`);
23369
- const now = deps.now();
23370
- if (now >= expires)
23371
- return stop("The Supabase consent link expired before it was approved: re-run pgai mon deploy for a new one");
23372
- if (now >= deadline)
23373
- return stop(`${approve}, then re-run`);
23374
- await deps.sleep(OAUTH_POLL_MS);
23375
- }
23364
+ const waited = await supabaseConsent(started, opts, deps, progress, stop);
23365
+ if (waited)
23366
+ return waited;
23367
+ }
23368
+ return supabaseBox(ref, name, opts, deps, progress, stop);
23369
+ }
23370
+ async function boxOnProject(ref, deps) {
23371
+ const cluster = clusterOf(supabaseProjectUrl(ref));
23372
+ return (await deps.list()).find((d) => !disconnecting(d.status) && d.cluster && serverOf(d.cluster) === cluster && (!d.database || d.database === "postgres"));
23373
+ }
23374
+ function supabaseProjectUrl(ref, db = "postgres") {
23375
+ return `postgresql://db.${ref}.supabase.co:5432/${encodeURIComponent(db)}`;
23376
+ }
23377
+ function supabaseOptionsRefused(opts) {
23378
+ if (opts.resetPassword)
23379
+ return "--reset-password does not apply to Supabase: PostgresAI creates postgres_ai_mon through the Supabase Management API";
23380
+ if (opts.location)
23381
+ return "--location does not apply to Supabase yet (PostgresAI picks the box's location): re-run without it";
23382
+ if (opts.monitoringUser !== undefined && opts.monitoringUser.trim() !== DEFAULT_MONITORING_USER) {
23383
+ return `${opts.agent ? "monitoring_user" : "--monitoring-user"} does not apply to Supabase: PostgresAI creates ${DEFAULT_MONITORING_USER} through the Supabase Management API`;
23376
23384
  }
23385
+ return;
23386
+ }
23387
+ async function supabaseConsent(started, opts, deps, progress, stop) {
23388
+ if (!isSupabaseUrl(started.auth_url))
23389
+ return { ...stop(""), status: "failed", next: `The platform sent a Supabase consent link that is not ${SUPABASE_API_BASE}: not opened. Re-run pgai mon deploy later.` };
23390
+ const approve = `Open ${started.auth_url} in a browser and approve PostgresAI's access to Supabase`;
23391
+ if (opts.agent || opts.waitMs <= 0)
23392
+ return stop(`${approve}, then ${opts.agent ? "call deploy_monitoring again" : "re-run"}`);
23393
+ progress("preparing", `Connect Supabase to PostgresAI: approve access in the browser (open ${started.auth_url} if it did not open). Waiting...`, { auth_url: started.auth_url });
23394
+ deps.openUrl?.(started.auth_url);
23395
+ const expires = started.expires_at ? Date.parse(started.expires_at) : NaN;
23396
+ for (const deadline = deps.now() + Math.min(opts.waitMs, OAUTH_WAIT_MS);; ) {
23397
+ if (deps.aborted?.())
23398
+ throw new CancelledError;
23399
+ const s = await deps.supabaseStatus(started.session_id);
23400
+ if (s.status === "connected")
23401
+ return;
23402
+ if (s.status === "error")
23403
+ return stop(`Supabase did not connect: ${(s.error ?? "no reason given").replace(/\.$/, "")}. Re-run to try again`);
23404
+ const now = deps.now();
23405
+ if (now >= expires)
23406
+ return stop("The Supabase consent link expired before it was approved: re-run pgai mon deploy for a new one");
23407
+ if (now >= deadline)
23408
+ return stop(`${approve}, then re-run`);
23409
+ await deps.sleep(OAUTH_POLL_MS);
23410
+ }
23411
+ }
23412
+ function supabaseStatusWords(status) {
23413
+ if (status === "inactive" || status === "paused")
23414
+ return "paused";
23415
+ if (status === "coming_up")
23416
+ return "starting";
23417
+ if (status === "unknown")
23418
+ return "in an unknown state";
23419
+ return status.replace(/_/g, " ");
23420
+ }
23421
+ function matchSupabaseProject(projects, wanted) {
23422
+ const value = wanted.trim();
23423
+ const byRef = projects.find((p) => p.ref === value);
23424
+ if (byRef)
23425
+ return { project: byRef };
23426
+ const byName = projects.filter((p) => p.name.toLowerCase() === value.toLowerCase());
23427
+ if (byName.length === 1)
23428
+ return { project: byName[0] };
23429
+ if (byName.length > 1)
23430
+ return { ambiguous: byName };
23431
+ return { none: true };
23432
+ }
23433
+ async function deploySupabaseProject(urlRef, opts, deps, progress) {
23434
+ const provider = "supabase";
23435
+ let name = urlRef ? databaseName2(supabaseProjectUrl(urlRef)) : "";
23436
+ const stop = (next, more = {}) => ({ status: "action_required", provider, name, ...more, next });
23437
+ const refused = supabaseOptionsRefused(opts);
23438
+ if (refused)
23439
+ return stop(refused);
23440
+ const urlHint = "pass the project's URL instead (pgai mon deploy 'postgresql://postgres@db.<project-ref>.supabase.co:5432/postgres')";
23441
+ if (!deps.supabaseProjects)
23442
+ return stop(`Picking a Supabase project needs a newer pgai: ${urlHint}`);
23443
+ const listed = async () => {
23444
+ try {
23445
+ return await deps.supabaseProjects();
23446
+ } catch (err) {
23447
+ if (err instanceof HttpStatusError && err.status === 403)
23448
+ return stop(notAdminNext);
23449
+ if (err instanceof HttpStatusError && err.status === 404)
23450
+ return stop(`This PostgresAI API cannot list Supabase projects yet: ${urlHint}`);
23451
+ throw err;
23452
+ }
23453
+ };
23454
+ let list = await listed();
23455
+ if ("status" in list)
23456
+ return list;
23457
+ if (!list.connected) {
23458
+ const waited = await supabaseConsent(list, opts, deps, progress, stop);
23459
+ if (waited)
23460
+ return waited;
23461
+ list = await listed();
23462
+ if ("status" in list)
23463
+ return list;
23464
+ if (!list.connected)
23465
+ return stop("Supabase did not stay connected after the approval: re-run pgai mon deploy --provider supabase");
23466
+ }
23467
+ const org = list.supabase_org_name;
23468
+ const projects = list.projects;
23469
+ const shown = { supabase_org: org, projects };
23470
+ if (!list.synced && !projects.length)
23471
+ return stop("Supabase did not answer the project list: re-run in a minute");
23472
+ const stale = list.synced ? "" : " (Supabase did not answer just now: the list may be out of date)";
23473
+ const inOrg = `organization "${org}"`;
23474
+ const useFlag = "--supabase-project <name or project ID>";
23475
+ if (!projects.length)
23476
+ return stop(`There are no projects in the Supabase ${inOrg}: create one there, then re-run`, shown);
23477
+ const wanted = opts.supabaseProject?.trim();
23478
+ let picked;
23479
+ if (wanted) {
23480
+ const m = matchSupabaseProject(projects, wanted);
23481
+ if ("none" in m)
23482
+ return stop(`No Supabase project "${wanted}" in ${inOrg}: re-run with ${useFlag} of one of its projects`, shown);
23483
+ if ("ambiguous" in m)
23484
+ return stop(`Several projects in ${inOrg} are called "${wanted}": re-run with the project ID instead`, { supabase_org: org, projects: m.ambiguous });
23485
+ picked = m.project;
23486
+ } else {
23487
+ if (!projects.some((p) => p.selectable)) {
23488
+ return stop(projects.some((p) => p.monitored) ? `Every active project in ${inOrg} is already monitored: see pgai mon instances list (a paused project can be monitored once it is resumed in Supabase)` : `No active project in ${inOrg}: resume one in Supabase, then re-run`, shown);
23489
+ }
23490
+ const ask = !opts.agent && !opts.yes ? deps.chooseSupabaseProject : undefined;
23491
+ if (!ask)
23492
+ return stop(`Choose the Supabase project to monitor, then re-run with ${useFlag}${stale}`, shown);
23493
+ const ref = await ask(projects, org);
23494
+ if (deps.aborted?.())
23495
+ throw new CancelledError;
23496
+ if (!ref)
23497
+ return stop(`No project chosen: re-run and pick one, or pass ${useFlag}`, shown);
23498
+ picked = projects.find((p) => p.ref === ref);
23499
+ }
23500
+ if (!picked)
23501
+ return stop(`No project chosen: re-run and pick one, or pass ${useFlag}`, shown);
23502
+ if (urlRef && picked.ref !== urlRef) {
23503
+ const urlProject = projects.find((p) => p.ref === urlRef);
23504
+ return stop(`--supabase-project is ${picked.name}, but the database URL is for ${urlProject ? urlProject.name : `project ${urlRef}`}: pass only one of them`);
23505
+ }
23506
+ name = databaseName2(supabaseProjectUrl(picked.ref));
23507
+ if (picked.monitored) {
23508
+ const box = (await deps.list()).find((d) => d.id === picked.monitored.id);
23509
+ if (box && !disconnecting(box.status)) {
23510
+ const note = opts.name && box.name !== opts.name ? `; --name ignored: this database is already monitored as ${box.name}` : "";
23511
+ return follow(box, { provider, name, fresh: false, billing: {}, note }, opts, deps, progress);
23512
+ }
23513
+ return stop(`${picked.name} is already monitored${picked.monitored.name ? ` as ${picked.monitored.name}` : ""}: see pgai mon instances list`);
23514
+ }
23515
+ if (picked.reason === "paused")
23516
+ return stop(`${picked.name} is paused: resume it in Supabase, then re-run`);
23517
+ if (!picked.selectable)
23518
+ return stop(`${picked.name} is not ready in Supabase (${supabaseStatusWords(picked.status)}): re-run when it is active`);
23519
+ const existing = await boxOnProject(picked.ref, deps);
23520
+ if (existing) {
23521
+ const note = opts.name && existing.name !== opts.name ? `; --name ignored: this database is already monitored as ${existing.name}` : "";
23522
+ return follow(existing, { provider, name, fresh: false, billing: {}, note }, opts, deps, progress);
23523
+ }
23524
+ return supabaseBox(picked.ref, name, opts, deps, progress, stop, `${picked.name} (Supabase)`);
23525
+ }
23526
+ async function supabaseBox(ref, name, opts, deps, progress, stop, label) {
23527
+ const provider = "supabase";
23377
23528
  let quote;
23378
23529
  try {
23379
23530
  quote = await deps.quote(opts.coupon);
@@ -23382,12 +23533,12 @@ async function deploySupabase(url, opts, deps, progress) {
23382
23533
  return stop(notAdminNext);
23383
23534
  throw err;
23384
23535
  }
23385
- const b = await billingFor(quote, name, opts, deps, (price) => progress("billing", estimateLine(price)));
23536
+ const b = await billingFor(quote, label ?? name, opts, deps, (price) => progress("billing", estimateLine(price), label ? { project: label } : {}));
23386
23537
  if (b.stop)
23387
23538
  return { status: "action_required", provider, name, ...b.stop };
23388
23539
  if (deps.aborted?.())
23389
23540
  throw new CancelledError;
23390
- progress("provisioning", `Provisioning monitoring for ${name}`);
23541
+ progress("provisioning", `Provisioning monitoring for ${label ?? name}`, label ? { project: label } : {});
23391
23542
  const created = await deps.supabaseConnect({
23392
23543
  project_ref: ref,
23393
23544
  ...opts.name ? { name: opts.name } : {},
@@ -23749,6 +23900,7 @@ function platformDeps(p) {
23749
23900
  supabaseStart: (dbUrl) => rpc("cloud_monitoring_supabase_start", { db_url: dbUrl }),
23750
23901
  supabaseStatus: (sessionId) => rpc("cloud_monitoring_supabase_status", { session_id: sessionId }),
23751
23902
  supabaseConnect: (body) => rpc("cloud_monitoring_supabase_connect", body),
23903
+ supabaseProjects: () => rpc("cloud_monitoring_supabase_projects", {}),
23752
23904
  handoffUrl: async (provider) => {
23753
23905
  const orgs = await listOrgs({ apiKey: p.apiKey, apiBaseUrl: p.apiBaseUrl });
23754
23906
  const org = orgs.length === 1 ? orgs[0] : orgs.find((o) => o.alias === p.orgScope?.alias || o.org_id === p.orgScope?.id);
@@ -32128,8 +32280,8 @@ function connectStatus2(row, provider = row.provider, fresh = false) {
32128
32280
  return { ...base, status, next: `pgai mon instances delete ${row.id} --yes, then pgai mon deploy again` };
32129
32281
  return { ...base, status, next: `pgai mon instances watch ${row.id}` };
32130
32282
  }
32131
- var ESCAPES = /(?:\x1b\[|\x9b)[0-?]*[ -\/]*[@-~]|(?:\x1b\]|\x9d)[^\x07\x1b\x9c]*(?:\x07|\x1b\\|\x9c)?|\x1b[ -~]?/g;
32132
- var terminalText = (text) => text.replace(ESCAPES, "").split(`
32283
+ var ESCAPES2 = /(?:\x1b\[|\x9b)[0-?]*[ -\/]*[@-~]|(?:\x1b\]|\x9d)[^\x07\x1b\x9c]*(?:\x07|\x1b\\|\x9c)?|\x1b[ -~]?/g;
32284
+ var terminalText2 = (text) => text.replace(ESCAPES2, "").split(`
32133
32285
  `).map(stripControlsToSpace).join(`
32134
32286
  `);
32135
32287
  function stepProgress(o) {
@@ -32140,7 +32292,7 @@ function stepProgress(o) {
32140
32292
  o.onId?.(e.id);
32141
32293
  if (o.json)
32142
32294
  return o.writeEvent(e);
32143
- e = { ...e, message: terminalText(e.message), ...e.state ? { state: terminalText(e.state) } : {} };
32295
+ e = { ...e, message: terminalText2(e.message), ...e.state ? { state: terminalText2(e.state) } : {} };
32144
32296
  if (!o.tty)
32145
32297
  return o.writeLine(progressText(e));
32146
32298
  if (e.event === "billing") {
@@ -32162,7 +32314,7 @@ function stepProgress(o) {
32162
32314
  return { progress, view: () => view };
32163
32315
  }
32164
32316
  function resultLines(r) {
32165
- return personLines(r).map(terminalText);
32317
+ return personLines(r).map(terminalText2);
32166
32318
  }
32167
32319
  function personLines(r) {
32168
32320
  const who = r.name || "this database";
@@ -32184,7 +32336,7 @@ function personLines(r) {
32184
32336
  case "deleted":
32185
32337
  return [`Deleting the monitoring of ${who}.${billing ? ` Billing: ${billing}.` : ""}${r.next && r.next !== "none" ? ` ${r.next}` : ""}`];
32186
32338
  default:
32187
- return [r.next];
32339
+ return r.projects?.length ? [r.next, ...supabaseProjectRows(r.projects)] : [r.next];
32188
32340
  }
32189
32341
  }
32190
32342
  function progressText(e) {
@@ -32218,7 +32370,7 @@ async function billingFor2(q, name, opts, deps, show) {
32218
32370
  if (q.requires_payment_method)
32219
32371
  return { billing, billingPage, billingUrl, accepted: false, stop: billingPage };
32220
32372
  show(billing.price);
32221
- if (q.billed && !opts.yes && !await deps.confirm(`Provision ${name}? (y/N): `)) {
32373
+ if (q.billed && !opts.yes && !await deps.confirm(`Provision ${terminalText2(name)}? (y/N): `)) {
32222
32374
  return stop(opts.agent ? `Call deploy_monitoring again with yes: true to accept ${billing.price}` : `Re-run with --yes to accept ${billing.price}`);
32223
32375
  }
32224
32376
  return { billing, billingPage, billingUrl, accepted: q.billed };
@@ -32238,9 +32390,20 @@ async function connect2(url, opts, deps) {
32238
32390
  warned.add(message);
32239
32391
  progress(step, message);
32240
32392
  };
32241
- const provider = providerArg2(opts.provider) ?? detectCloudProvider2(url);
32393
+ const project = opts.supabaseProject?.trim();
32394
+ const provider = providerArg2(opts.provider) ?? (!url && project ? "supabase" : detectCloudProvider2(url));
32242
32395
  if (!PROVIDERS2.includes(provider))
32243
32396
  throw new Error(`--provider must be one of: generic, ${PROVIDERS2.join(", ")}`);
32397
+ if (project !== undefined && provider !== "supabase") {
32398
+ return { status: "action_required", provider, name: url ? databaseName3(url) : "", next: "--supabase-project applies to Supabase only: leave it out, or use --provider supabase" };
32399
+ }
32400
+ if (!url) {
32401
+ if (provider !== "supabase")
32402
+ return { status: "action_required", provider, name: "", next: "Pass the database URL: pgai mon deploy postgresql://user:password@host:5432/dbname (Supabase: --provider supabase)" };
32403
+ if (opts.selfHosted)
32404
+ return { status: "action_required", provider, name: "", next: "--self-hosted needs the database URL: pass the project's connection string" };
32405
+ return deploySupabaseProject2(undefined, opts, deps, progress);
32406
+ }
32244
32407
  assertEncodedUserinfo(url);
32245
32408
  if (!opts.selfHosted && provider === "supabase")
32246
32409
  return deploySupabase2(url, opts, deps, progress);
@@ -32527,29 +32690,25 @@ async function deploySupabase2(url, opts, deps, progress) {
32527
32690
  const provider = "supabase";
32528
32691
  const ref = extractProjectRefFromUrl(url);
32529
32692
  if (!ref)
32530
- return { status: "action_required", provider, name: databaseName3(url), next: "Not a Supabase project URL: use the project's connection string (db.<project-ref>.supabase.co, or the pooler with user postgres.<project-ref>)" };
32693
+ return { status: "action_required", provider, name: databaseName3(url), next: "Not a Supabase project URL: use the project's connection string (db.<project-ref>.supabase.co, or the pooler with user postgres.<project-ref>), or pass --provider supabase without a URL to pick the project" };
32531
32694
  const db = decodeURIComponent(new URL(url).pathname.replace(/^\//, "")) || "postgres";
32532
- const project = `postgresql://db.${ref}.supabase.co:5432/${encodeURIComponent(db)}`;
32533
- const name = databaseName3(project);
32534
- const cluster = clusterOf2(project);
32695
+ const name = databaseName3(supabaseProjectUrl2(ref, db));
32535
32696
  const stop = (next, more = {}) => ({ status: "action_required", provider, name, ...more, next });
32536
32697
  if (db !== "postgres")
32537
32698
  return stop("PostgresAI monitors a Supabase project through its postgres database: use the URL of the postgres database");
32538
- if (opts.resetPassword)
32539
- return stop("--reset-password does not apply to Supabase: PostgresAI creates postgres_ai_mon through the Supabase Management API");
32540
- if (opts.location)
32541
- return stop("--location does not apply to Supabase yet (PostgresAI picks the box's location): re-run without it");
32542
- if (opts.monitoringUser !== undefined && opts.monitoringUser.trim() !== DEFAULT_MONITORING_USER) {
32543
- return stop(`${opts.agent ? "monitoring_user" : "--monitoring-user"} does not apply to Supabase: PostgresAI creates ${DEFAULT_MONITORING_USER} through the Supabase Management API`);
32544
- }
32545
- const row = (await deps.list()).find((d) => !disconnecting2(d.status) && d.cluster && serverOf2(d.cluster) === cluster && (!d.database || d.database === "postgres"));
32699
+ const refused = supabaseOptionsRefused2(opts);
32700
+ if (refused)
32701
+ return stop(refused);
32702
+ if (opts.supabaseProject?.trim())
32703
+ return deploySupabaseProject2(ref, opts, deps, progress);
32704
+ const row = await boxOnProject2(ref, deps);
32546
32705
  if (row) {
32547
32706
  const note = opts.name && row.name !== opts.name ? `; --name ignored: this database is already monitored as ${row.name}` : "";
32548
32707
  return follow2(row, { provider, name, fresh: false, billing: {}, note }, opts, deps, progress);
32549
32708
  }
32550
32709
  let started;
32551
32710
  try {
32552
- started = await deps.supabaseStart(project);
32711
+ started = await deps.supabaseStart(supabaseProjectUrl2(ref));
32553
32712
  } catch (err) {
32554
32713
  if (err instanceof HttpStatusError && err.status === 403)
32555
32714
  return stop(notAdminNext);
@@ -32558,30 +32717,190 @@ async function deploySupabase2(url, opts, deps, progress) {
32558
32717
  throw err;
32559
32718
  }
32560
32719
  if ("auth_url" in started) {
32561
- if (!isSupabaseUrl2(started.auth_url))
32562
- return { status: "failed", provider, name, next: `The platform sent a Supabase consent link that is not ${SUPABASE_API_BASE}: not opened. Re-run pgai mon deploy later.` };
32563
- const approve = `Open ${started.auth_url} in a browser and approve PostgresAI's access to Supabase`;
32564
- if (opts.agent || opts.waitMs <= 0)
32565
- return stop(`${approve}, then ${opts.agent ? "call deploy_monitoring again" : "re-run"}`);
32566
- progress("preparing", `Connect Supabase to PostgresAI: approve access in the browser (open ${started.auth_url} if it did not open). Waiting...`, { auth_url: started.auth_url });
32567
- deps.openUrl?.(started.auth_url);
32568
- const expires = started.expires_at ? Date.parse(started.expires_at) : NaN;
32569
- for (const deadline = deps.now() + Math.min(opts.waitMs, OAUTH_WAIT_MS2);; ) {
32570
- if (deps.aborted?.())
32571
- throw new CancelledError2;
32572
- const s = await deps.supabaseStatus(started.session_id);
32573
- if (s.status === "connected")
32574
- break;
32575
- if (s.status === "error")
32576
- return stop(`Supabase did not connect (${s.error ?? "no reason given"}): re-run to try again`);
32577
- const now = deps.now();
32578
- if (now >= expires)
32579
- return stop("The Supabase consent link expired before it was approved: re-run pgai mon deploy for a new one");
32580
- if (now >= deadline)
32581
- return stop(`${approve}, then re-run`);
32582
- await deps.sleep(OAUTH_POLL_MS2);
32583
- }
32720
+ const waited = await supabaseConsent2(started, opts, deps, progress, stop);
32721
+ if (waited)
32722
+ return waited;
32723
+ }
32724
+ return supabaseBox2(ref, name, opts, deps, progress, stop);
32725
+ }
32726
+ async function boxOnProject2(ref, deps) {
32727
+ const cluster = clusterOf2(supabaseProjectUrl2(ref));
32728
+ return (await deps.list()).find((d) => !disconnecting2(d.status) && d.cluster && serverOf2(d.cluster) === cluster && (!d.database || d.database === "postgres"));
32729
+ }
32730
+ function supabaseProjectUrl2(ref, db = "postgres") {
32731
+ return `postgresql://db.${ref}.supabase.co:5432/${encodeURIComponent(db)}`;
32732
+ }
32733
+ function supabaseOptionsRefused2(opts) {
32734
+ if (opts.resetPassword)
32735
+ return "--reset-password does not apply to Supabase: PostgresAI creates postgres_ai_mon through the Supabase Management API";
32736
+ if (opts.location)
32737
+ return "--location does not apply to Supabase yet (PostgresAI picks the box's location): re-run without it";
32738
+ if (opts.monitoringUser !== undefined && opts.monitoringUser.trim() !== DEFAULT_MONITORING_USER) {
32739
+ return `${opts.agent ? "monitoring_user" : "--monitoring-user"} does not apply to Supabase: PostgresAI creates ${DEFAULT_MONITORING_USER} through the Supabase Management API`;
32584
32740
  }
32741
+ return;
32742
+ }
32743
+ async function supabaseConsent2(started, opts, deps, progress, stop) {
32744
+ if (!isSupabaseUrl2(started.auth_url))
32745
+ return { ...stop(""), status: "failed", next: `The platform sent a Supabase consent link that is not ${SUPABASE_API_BASE}: not opened. Re-run pgai mon deploy later.` };
32746
+ const approve = `Open ${started.auth_url} in a browser and approve PostgresAI's access to Supabase`;
32747
+ if (opts.agent || opts.waitMs <= 0)
32748
+ return stop(`${approve}, then ${opts.agent ? "call deploy_monitoring again" : "re-run"}`);
32749
+ progress("preparing", `Connect Supabase to PostgresAI: approve access in the browser (open ${started.auth_url} if it did not open). Waiting...`, { auth_url: started.auth_url });
32750
+ deps.openUrl?.(started.auth_url);
32751
+ const expires = started.expires_at ? Date.parse(started.expires_at) : NaN;
32752
+ for (const deadline = deps.now() + Math.min(opts.waitMs, OAUTH_WAIT_MS2);; ) {
32753
+ if (deps.aborted?.())
32754
+ throw new CancelledError2;
32755
+ const s = await deps.supabaseStatus(started.session_id);
32756
+ if (s.status === "connected")
32757
+ return;
32758
+ if (s.status === "error")
32759
+ return stop(`Supabase did not connect: ${(s.error ?? "no reason given").replace(/\.$/, "")}. Re-run to try again`);
32760
+ const now = deps.now();
32761
+ if (now >= expires)
32762
+ return stop("The Supabase consent link expired before it was approved: re-run pgai mon deploy for a new one");
32763
+ if (now >= deadline)
32764
+ return stop(`${approve}, then re-run`);
32765
+ await deps.sleep(OAUTH_POLL_MS2);
32766
+ }
32767
+ }
32768
+ function supabaseStatusWords2(status) {
32769
+ if (status === "inactive" || status === "paused")
32770
+ return "paused";
32771
+ if (status === "coming_up")
32772
+ return "starting";
32773
+ if (status === "unknown")
32774
+ return "in an unknown state";
32775
+ return status.replace(/_/g, " ");
32776
+ }
32777
+ function supabaseWhy(p) {
32778
+ if (p.reason === "monitored")
32779
+ return `already monitored${p.monitored?.name ? ` as ${p.monitored.name}` : ""}`;
32780
+ if (p.reason === "paused")
32781
+ return "paused";
32782
+ if (p.reason?.startsWith("not_ready:"))
32783
+ return `not ready (${supabaseStatusWords2(p.reason.slice("not_ready:".length))})`;
32784
+ return "";
32785
+ }
32786
+ function supabaseProjectRows(projects, numbered = false) {
32787
+ const nameW = Math.max(...projects.map((p) => p.name.length));
32788
+ const regionW = Math.max(...projects.map((p) => (p.region ?? "").length));
32789
+ const numW = String(projects.filter((p) => p.selectable).length).length;
32790
+ let n = 0;
32791
+ return projects.map((p) => {
32792
+ const why = supabaseWhy(p);
32793
+ const mark = numbered ? `${(p.selectable ? `${++n}.` : "-").padStart(numW + 1)} ` : "";
32794
+ return ` ${mark}${p.name.padEnd(nameW)} ${(p.region ?? "").padEnd(regionW)} ${p.ref}${why ? ` ${why}` : ""}`.trimEnd();
32795
+ });
32796
+ }
32797
+ function matchSupabaseProject2(projects, wanted) {
32798
+ const value = wanted.trim();
32799
+ const byRef = projects.find((p) => p.ref === value);
32800
+ if (byRef)
32801
+ return { project: byRef };
32802
+ const byName = projects.filter((p) => p.name.toLowerCase() === value.toLowerCase());
32803
+ if (byName.length === 1)
32804
+ return { project: byName[0] };
32805
+ if (byName.length > 1)
32806
+ return { ambiguous: byName };
32807
+ return { none: true };
32808
+ }
32809
+ async function deploySupabaseProject2(urlRef, opts, deps, progress) {
32810
+ const provider = "supabase";
32811
+ let name = urlRef ? databaseName3(supabaseProjectUrl2(urlRef)) : "";
32812
+ const stop = (next, more = {}) => ({ status: "action_required", provider, name, ...more, next });
32813
+ const refused = supabaseOptionsRefused2(opts);
32814
+ if (refused)
32815
+ return stop(refused);
32816
+ const urlHint = "pass the project's URL instead (pgai mon deploy 'postgresql://postgres@db.<project-ref>.supabase.co:5432/postgres')";
32817
+ if (!deps.supabaseProjects)
32818
+ return stop(`Picking a Supabase project needs a newer pgai: ${urlHint}`);
32819
+ const listed = async () => {
32820
+ try {
32821
+ return await deps.supabaseProjects();
32822
+ } catch (err) {
32823
+ if (err instanceof HttpStatusError && err.status === 403)
32824
+ return stop(notAdminNext);
32825
+ if (err instanceof HttpStatusError && err.status === 404)
32826
+ return stop(`This PostgresAI API cannot list Supabase projects yet: ${urlHint}`);
32827
+ throw err;
32828
+ }
32829
+ };
32830
+ let list = await listed();
32831
+ if ("status" in list)
32832
+ return list;
32833
+ if (!list.connected) {
32834
+ const waited = await supabaseConsent2(list, opts, deps, progress, stop);
32835
+ if (waited)
32836
+ return waited;
32837
+ list = await listed();
32838
+ if ("status" in list)
32839
+ return list;
32840
+ if (!list.connected)
32841
+ return stop("Supabase did not stay connected after the approval: re-run pgai mon deploy --provider supabase");
32842
+ }
32843
+ const org = list.supabase_org_name;
32844
+ const projects = list.projects;
32845
+ const shown = { supabase_org: org, projects };
32846
+ if (!list.synced && !projects.length)
32847
+ return stop("Supabase did not answer the project list: re-run in a minute");
32848
+ const stale = list.synced ? "" : " (Supabase did not answer just now: the list may be out of date)";
32849
+ const inOrg = `organization "${org}"`;
32850
+ const useFlag = "--supabase-project <name or project ID>";
32851
+ if (!projects.length)
32852
+ return stop(`There are no projects in the Supabase ${inOrg}: create one there, then re-run`, shown);
32853
+ const wanted = opts.supabaseProject?.trim();
32854
+ let picked;
32855
+ if (wanted) {
32856
+ const m = matchSupabaseProject2(projects, wanted);
32857
+ if ("none" in m)
32858
+ return stop(`No Supabase project "${wanted}" in ${inOrg}: re-run with ${useFlag} of one of its projects`, shown);
32859
+ if ("ambiguous" in m)
32860
+ return stop(`Several projects in ${inOrg} are called "${wanted}": re-run with the project ID instead`, { supabase_org: org, projects: m.ambiguous });
32861
+ picked = m.project;
32862
+ } else {
32863
+ if (!projects.some((p) => p.selectable)) {
32864
+ return stop(projects.some((p) => p.monitored) ? `Every active project in ${inOrg} is already monitored: see pgai mon instances list (a paused project can be monitored once it is resumed in Supabase)` : `No active project in ${inOrg}: resume one in Supabase, then re-run`, shown);
32865
+ }
32866
+ const ask = !opts.agent && !opts.yes ? deps.chooseSupabaseProject : undefined;
32867
+ if (!ask)
32868
+ return stop(`Choose the Supabase project to monitor, then re-run with ${useFlag}${stale}`, shown);
32869
+ const ref = await ask(projects, org);
32870
+ if (deps.aborted?.())
32871
+ throw new CancelledError2;
32872
+ if (!ref)
32873
+ return stop(`No project chosen: re-run and pick one, or pass ${useFlag}`, shown);
32874
+ picked = projects.find((p) => p.ref === ref);
32875
+ }
32876
+ if (!picked)
32877
+ return stop(`No project chosen: re-run and pick one, or pass ${useFlag}`, shown);
32878
+ if (urlRef && picked.ref !== urlRef) {
32879
+ const urlProject = projects.find((p) => p.ref === urlRef);
32880
+ return stop(`--supabase-project is ${picked.name}, but the database URL is for ${urlProject ? urlProject.name : `project ${urlRef}`}: pass only one of them`);
32881
+ }
32882
+ name = databaseName3(supabaseProjectUrl2(picked.ref));
32883
+ if (picked.monitored) {
32884
+ const box = (await deps.list()).find((d) => d.id === picked.monitored.id);
32885
+ if (box && !disconnecting2(box.status)) {
32886
+ const note = opts.name && box.name !== opts.name ? `; --name ignored: this database is already monitored as ${box.name}` : "";
32887
+ return follow2(box, { provider, name, fresh: false, billing: {}, note }, opts, deps, progress);
32888
+ }
32889
+ return stop(`${picked.name} is already monitored${picked.monitored.name ? ` as ${picked.monitored.name}` : ""}: see pgai mon instances list`);
32890
+ }
32891
+ if (picked.reason === "paused")
32892
+ return stop(`${picked.name} is paused: resume it in Supabase, then re-run`);
32893
+ if (!picked.selectable)
32894
+ return stop(`${picked.name} is not ready in Supabase (${supabaseStatusWords2(picked.status)}): re-run when it is active`);
32895
+ const existing = await boxOnProject2(picked.ref, deps);
32896
+ if (existing) {
32897
+ const note = opts.name && existing.name !== opts.name ? `; --name ignored: this database is already monitored as ${existing.name}` : "";
32898
+ return follow2(existing, { provider, name, fresh: false, billing: {}, note }, opts, deps, progress);
32899
+ }
32900
+ return supabaseBox2(picked.ref, name, opts, deps, progress, stop, `${picked.name} (Supabase)`);
32901
+ }
32902
+ async function supabaseBox2(ref, name, opts, deps, progress, stop, label) {
32903
+ const provider = "supabase";
32585
32904
  let quote;
32586
32905
  try {
32587
32906
  quote = await deps.quote(opts.coupon);
@@ -32590,12 +32909,12 @@ async function deploySupabase2(url, opts, deps, progress) {
32590
32909
  return stop(notAdminNext);
32591
32910
  throw err;
32592
32911
  }
32593
- const b = await billingFor2(quote, name, opts, deps, (price) => progress("billing", estimateLine(price)));
32912
+ const b = await billingFor2(quote, label ?? name, opts, deps, (price) => progress("billing", estimateLine(price), label ? { project: label } : {}));
32594
32913
  if (b.stop)
32595
32914
  return { status: "action_required", provider, name, ...b.stop };
32596
32915
  if (deps.aborted?.())
32597
32916
  throw new CancelledError2;
32598
- progress("provisioning", `Provisioning monitoring for ${name}`);
32917
+ progress("provisioning", `Provisioning monitoring for ${label ?? name}`, label ? { project: label } : {});
32599
32918
  const created = await deps.supabaseConnect({
32600
32919
  project_ref: ref,
32601
32920
  ...opts.name ? { name: opts.name } : {},
@@ -32973,6 +33292,7 @@ function platformDeps2(p) {
32973
33292
  supabaseStart: (dbUrl) => rpc("cloud_monitoring_supabase_start", { db_url: dbUrl }),
32974
33293
  supabaseStatus: (sessionId) => rpc("cloud_monitoring_supabase_status", { session_id: sessionId }),
32975
33294
  supabaseConnect: (body) => rpc("cloud_monitoring_supabase_connect", body),
33295
+ supabaseProjects: () => rpc("cloud_monitoring_supabase_projects", {}),
32976
33296
  handoffUrl: async (provider) => {
32977
33297
  const orgs = await listOrgs({ apiKey: p.apiKey, apiBaseUrl: p.apiBaseUrl });
32978
33298
  const org = orgs.length === 1 ? orgs[0] : orgs.find((o) => o.alias === p.orgScope?.alias || o.org_id === p.orgScope?.id);
@@ -46669,25 +46989,28 @@ Resume: ${resume}`);
46669
46989
  return () => process.removeListener("SIGINT", onSigint);
46670
46990
  }
46671
46991
  async function runConnect(urlArg, opts) {
46672
- let url;
46673
- try {
46674
- url = databaseUrlArg2(urlArg, opts.dbUrl, "pgai mon deploy");
46675
- } catch (err) {
46676
- return optionError({ status: "failed", provider: "self-managed", name: "", next: errorText2(err) }, opts.json);
46992
+ const explicit = providerArg2(opts.provider);
46993
+ const projectMode = !urlArg?.trim() && !opts.dbUrl?.trim() && (explicit === "supabase" || !explicit && !!opts.supabaseProject?.trim());
46994
+ let url = "";
46995
+ if (!projectMode) {
46996
+ try {
46997
+ url = databaseUrlArg2(urlArg, opts.dbUrl, "pgai mon deploy");
46998
+ } catch (err) {
46999
+ return optionError({ status: "failed", provider: "self-managed", name: "", next: errorText2(err) }, opts.json);
47000
+ }
46677
47001
  }
46678
47002
  const json = jsonOutput3(opts.json);
46679
- const name = (() => {
47003
+ const name = projectMode ? "" : (() => {
46680
47004
  try {
46681
47005
  return databaseName3(url);
46682
47006
  } catch {
46683
47007
  return "";
46684
47008
  }
46685
47009
  })();
46686
- if (!name || !/^postgres(ql)?:\/\//.test(url)) {
47010
+ if (!projectMode && (!name || !/^postgres(ql)?:\/\//.test(url))) {
46687
47011
  return optionError({ status: "failed", provider: "self-managed", name, next: "Pass a URL: pgai mon deploy postgresql://user:password@host:5432/dbname" }, opts.json);
46688
47012
  }
46689
- const explicit = providerArg2(opts.provider);
46690
- const provider = PROVIDERS2.find((p) => p === explicit) ?? detectCloudProvider2(url);
47013
+ const provider = projectMode ? "supabase" : PROVIDERS2.find((p) => p === explicit) ?? detectCloudProvider2(url);
46691
47014
  let minutes;
46692
47015
  try {
46693
47016
  minutes = waitMinutes2(opts.wait, 20);
@@ -46706,13 +47029,14 @@ async function runConnect(urlArg, opts) {
46706
47029
  return emitConnect({ status: "action_required", provider, name, next: "Sign in: pgai auth login (agents: set PGAI_API_KEY), then re-run" }, opts.json, true);
46707
47030
  }
46708
47031
  const api = cloudApi(opts.debug);
47032
+ let shownName = name;
46709
47033
  const tty = !json && !!process.stderr.isTTY && !process.env.CI && process.env.TERM !== "dumb";
46710
47034
  let createdId;
46711
47035
  let stopping = false;
46712
47036
  const steps = stepProgress({
46713
47037
  json,
46714
47038
  tty,
46715
- makeView: () => new StepView2(`Deploying monitoring for ${name}`, monitoringSteps(provider), true),
47039
+ makeView: () => new StepView2(`Deploying monitoring for ${shownName || "the Supabase project"}`, monitoringSteps(provider), true),
46716
47040
  writeLine: (line) => console.error(line),
46717
47041
  writeEvent: writeEvent2,
46718
47042
  onId: (id) => {
@@ -46791,10 +47115,37 @@ ${reply}`);
46791
47115
  closeReadline();
46792
47116
  }
46793
47117
  },
47118
+ ...interactive(opts.json) ? { chooseSupabaseProject: async (projects, org) => {
47119
+ const selectable = projects.filter((x) => x.selectable);
47120
+ console.error(terminalText2(`
47121
+ Projects in the Supabase organization "${org}":`));
47122
+ for (const line of supabaseProjectRows(projects, true))
47123
+ console.error(terminalText2(line));
47124
+ if (!selectable.length)
47125
+ return;
47126
+ process.exitCode = 130;
47127
+ try {
47128
+ for (let tries = 0;tries < 3; tries++) {
47129
+ const answer = (await question(`Project to monitor (1-${selectable.length}, Enter to cancel): `)).trim();
47130
+ if (!answer)
47131
+ return;
47132
+ const i = Number(answer);
47133
+ if (Number.isInteger(i) && i >= 1 && i <= selectable.length)
47134
+ return selectable[i - 1].ref;
47135
+ console.error(`Type a number from 1 to ${selectable.length}.`);
47136
+ }
47137
+ return;
47138
+ } finally {
47139
+ process.exitCode = undefined;
47140
+ closeReadline();
47141
+ }
47142
+ } } : {},
46794
47143
  ...interactive(opts.json) ? { openUrl: openInBrowser } : {},
46795
47144
  progress: (e) => {
46796
47145
  if (e.event === "provisioning")
46797
47146
  requested = true;
47147
+ if (e.project)
47148
+ shownName = terminalText2(e.project);
46798
47149
  steps.progress(e);
46799
47150
  },
46800
47151
  aborted: () => stopping
@@ -46833,7 +47184,7 @@ ${reply}`);
46833
47184
  }
46834
47185
  }
46835
47186
  var mon = program2.command("mon").description("monitoring services management");
46836
- sharedDeployOptions2(withOrgOptions(mon.command("deploy")), 20, "instance name (default: host[:port]/database)").description("deploy PostgresAI Cloud monitoring for a database: prepare it, provision the monitoring box, print its Health Matrix and dashboard").option("--provider <provider>", "generic (direct PostgreSQL URL; alias: self-managed) | clickhouse | rds | supabase (default: detected from the host)").option("--clickhouse-key <id:secret>", "ClickHouse Cloud API key (Basic Service API Reader) for CPU, memory and disk; or CLICKHOUSE_KEY_ID + CLICKHOUSE_KEY_SECRET").option("--self-hosted", "run the monitoring stack on this machine (mon local-install) instead of PostgresAI Cloud").option("--reset-password", "the monitoring role exists and its password is lost: set a new one (admin URL; refused while another database on the server is monitored)").option("--monitoring-user <name>", "monitoring role to create or use", DEFAULT_MONITORING_USER2).option("--coupon <code>", "promotion code for the organization's monitoring subscription (applies when it is first created)").option("--vcpus <n>", "vCPUs of the database server; without it there is no AAS (database load) data (asked at a terminal)").addHelpText("after", [
47187
+ sharedDeployOptions2(withOrgOptions(mon.command("deploy")), 20, "instance name (default: host[:port]/database)").description("deploy PostgresAI Cloud monitoring for a database: prepare it, provision the monitoring box, print its Health Matrix and dashboard").option("--provider <provider>", "generic (direct PostgreSQL URL; alias: self-managed) | clickhouse | rds | supabase (default: detected from the host)").option("--clickhouse-key <id:secret>", "ClickHouse Cloud API key (Basic Service API Reader) for CPU, memory and disk; or CLICKHOUSE_KEY_ID + CLICKHOUSE_KEY_SECRET").option("--self-hosted", "run the monitoring stack on this machine (mon local-install) instead of PostgresAI Cloud").option("--reset-password", "the monitoring role exists and its password is lost: set a new one (admin URL; refused while another database on the server is monitored)").option("--monitoring-user <name>", "monitoring role to create or use", DEFAULT_MONITORING_USER2).option("--coupon <code>", "promotion code for the organization's monitoring subscription (applies when it is first created)").option("--vcpus <n>", "vCPUs of the database server; without it there is no AAS (database load) data (asked at a terminal; Supabase: from the project's compute size)").option("--supabase-project <name|project-id>", "the Supabase project to monitor (its exact name, or its project ID), instead of a URL; implies --provider supabase").addHelpText("after", [
46837
47188
  "",
46838
47189
  "Steps (each skipped when already done; safe to re-run): sign in, prepare the database",
46839
47190
  "(an admin URL creates the postgres_ai_mon role; otherwise the SQL is printed), provision",
@@ -46856,6 +47207,11 @@ sharedDeployOptions2(withOrgOptions(mon.command("deploy")), 20, "instance name (
46856
47207
  "Supabase: deploy opens the consent page in the browser (the link is printed too, to open",
46857
47208
  'it elsewhere; "auth_url" in the JSON event) and waits for the approval, up to 10 minutes.',
46858
47209
  'With --wait 0, and for agents, it stops there (exit 3) with the link in "next".',
47210
+ "No URL needed: pgai mon deploy --provider supabase lists the projects of the connected",
47211
+ "Supabase organization to pick one at a terminal; --supabase-project <name|project-id> picks it",
47212
+ "for agents and scripts. Without either, and not at a terminal, it stops (exit 3) with the list",
47213
+ `("projects" in the JSON result). Paused and not-ready projects are listed but can't be`,
47214
+ "picked; an already-monitored one returns its monitoring.",
46859
47215
  "",
46860
47216
  "Exit codes: 0 ready (or in progress with --no-wait), 1 failed, 3 action required (see",
46861
47217
  '"next"), also when the wait ends before the box is ready.',
@@ -46877,12 +47233,16 @@ sharedDeployOptions2(withOrgOptions(mon.command("deploy")), 20, "instance name (
46877
47233
  "Examples:",
46878
47234
  " pgai mon deploy 'postgresql://postgres:<password>@<host>.pg.clickhouse.cloud:5432/postgres?sslmode=require'",
46879
47235
  " CLICKHOUSE_KEY_ID=... CLICKHOUSE_KEY_SECRET=... pgai mon deploy '<url>'",
47236
+ " pgai mon deploy --provider supabase",
47237
+ " pgai mon deploy --supabase-project <name|project-id> --yes --json",
46880
47238
  " pgai mon deploy 'postgresql://postgres@db.<project-ref>.supabase.co:5432/postgres'",
46881
47239
  " pgai mon deploy '<url>' --self-hosted"
46882
47240
  ].join(`
46883
47241
  `)).action((urlArg, opts, cmd) => {
46884
- if (!urlArg?.trim() && !opts.dbUrl?.trim())
46885
- return cmd.error("error: missing required argument 'database-url'");
47242
+ const supabase = providerArg2(opts.provider) === "supabase" || !opts.provider && !!opts.supabaseProject?.trim();
47243
+ if (!urlArg?.trim() && !opts.dbUrl?.trim() && !supabase) {
47244
+ return cmd.error("error: missing required argument 'database-url' (or --provider supabase to pick a Supabase project)");
47245
+ }
46886
47246
  return runConnect(urlArg, opts);
46887
47247
  });
46888
47248
  var interactive = (json) => !!process.stdin.isTTY && !!process.stdout.isTTY && !json;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "postgresai",
3
- "version": "0.18.0-dev.11",
3
+ "version": "0.18.0-dev.12",
4
4
  "description": "postgres_ai CLI",
5
5
  "license": "Apache-2.0",
6
6
  "private": false,