postgresai 0.18.0-dev.12 → 0.18.0-dev.13

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
@@ -235,8 +235,8 @@ payment checks. A private endpoint needs a network path, or monitoring hosted in
235
235
  (`--self-hosted`).
236
236
 
237
237
  `pgai mon deploy` and `pgai dblab deploy` share their options and results: the database URL as the
238
- argument (or `--db-url`), `--name` (default: from the database), `--location` (a Hetzner location;
239
- default: any with capacity), `--wait <minutes>` / `--no-wait`, `--yes` (never prompt), `--json`, the
238
+ argument (or `--db-url`), `--name` (default: from the database), `--cloud` and `--location` (where the box
239
+ runs; see the table), `--wait <minutes>` / `--no-wait`, `--yes` (never prompt), `--json`, the
240
240
  `status` words and exit codes below, and `instances list | watch | delete`, which take an id or a name
241
241
  (a name two instances have is refused, with their ids). `watch` is also `status`.
242
242
 
@@ -262,11 +262,12 @@ terminal, or with `--json`, it only points to `pgai mon deploy`.
262
262
  | `--monitoring-user <name>` | the monitoring role to create or use (default `postgres_ai_mon`; at most 63 bytes; MCP: `monitoring_user`). A custom role always carries its own password: PostgresAI keeps only `postgres_ai_mon`'s, so creating or resetting a custom role needs `PGAI_MON_PASSWORD` (an agent passes the role's URL). A name with `'`, `$`, `%`, backslash or a control character is refused, and so is a role that is a superuser or has `CREATEDB`, `CREATEROLE`, `REPLICATION` or `BYPASSRLS`, is a member of a role other than `pg_monitor`, `pg_read_all_stats`, `pg_read_all_settings` and `pg_stat_scan_tables` (directly or through other roles, also through `pg_monitor` itself), owns objects, has grants in another database of the server, or has grants in the database beyond `CONNECT`, `USAGE` on schemas other than `pg_toast`, `SELECT` outside `pg_catalog` and `pg_toast`, and the grants pgai makes, or holds any grant `WITH GRANT OPTION` or a membership `WITH ADMIN OPTION`. So a custom role used for databases on one server is refused for the second one. `SELECT` on application tables and views is allowed, including a view over `pg_authid`: what a role may read through views is the owner's choice. Ignored for a host handed to the Console (RDS); refused for Supabase, where PostgresAI creates `postgres_ai_mon` through the Supabase Management API |
263
263
  | `--db-url <url>` | the database URL, instead of the argument |
264
264
  | `--name <name>` | the instance's name (default: `host[:port]/database`); ignored, with a note, for a database already monitored |
265
- | `--location <location>` | Hetzner location `fsn1`, `nbg1` or `hel1` (default: any with capacity) |
265
+ | `--cloud <cloud>` | `mon deploy`: `aws` or `hetzner`; default: the database's cloud (its RDS, Aurora, EC2 or Supabase region), else AWS. `dblab deploy`: `hetzner`, `aws` or `gcp` (default `hetzner`) |
266
+ | `--location <location>` | a location of that cloud: an AWS region, or a Hetzner location (`fsn1`, `nbg1`, `hel1`, `ash`, `hil`). `mon deploy` default: the database's region, else us-east-1 on AWS; a location of another cloud is refused before anything is created |
266
267
  | `--vcpus <n>` | `mon deploy` only: the database server's vCPUs. Without it there is no AAS (database load) data; at a terminal you are asked. On a database already monitored, it sets missing vCPUs (a set value is changed with `mon instances set`) |
267
268
  | `--wait <minutes>` | how long to wait for the monitoring box; `0` does not wait (default 20) |
268
269
  | `--no-wait` | the same as `--wait 0` |
269
- | `-y, --yes` | never prompt; accept a billed box's price (`mon deploy` does not start the browser sign-in; `mon instances delete` does not ask) |
270
+ | `-y, --yes` | never prompt: deploy where shown and accept the price (`mon deploy` does not start the browser sign-in; `mon instances delete` does not ask). Without it, `mon deploy` asks before creating any box, free or billed, and at a terminal lets you choose another cloud and location; not at a terminal it stops (exit 3) with the place, the price and `choices` |
270
271
  | `--coupon <code>` | promotion code for the organization's monitoring subscription |
271
272
  | `--json` | JSON output, also on a terminal |
272
273
 
@@ -13533,7 +13533,7 @@ var {
13533
13533
  // package.json
13534
13534
  var package_default = {
13535
13535
  name: "postgresai",
13536
- version: "0.18.0-dev.12",
13536
+ version: "0.18.0-dev.13",
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.12";
16896
+ var version = "0.18.0-dev.13";
16897
16897
  var package_default2 = {
16898
16898
  name: "postgresai",
16899
16899
  version,
@@ -22662,8 +22662,11 @@ function nameFromDatabase(url) {
22662
22662
  const slug = (db || "dblab").toLowerCase().replace(/[^a-z0-9-]+/g, "-").replace(/^-+|-+$/g, "").slice(0, 48).replace(/-+$/, "");
22663
22663
  return slug.length >= 2 ? slug : `db-${slug || "x"}`.slice(0, 48);
22664
22664
  }
22665
- function sharedDeployOptions(cmd, waitDefaultMinutes, nameHelp, locationHelp = "Hetzner location: fsn1, nbg1 or hel1 (default: any with capacity)") {
22666
- return cmd.argument("[database-url]", "the database: postgresql://user:password@host:5432/dbname").option("--db-url <url>", "the database URL (the same as the argument)").option("--name <name>", nameHelp).option("--location <location>", locationHelp).option("--wait <minutes>", "how long to wait for it to be ready (0 = do not wait)", String(waitDefaultMinutes)).option("--no-wait", "return once the deploy has started (the same as --wait 0)").option("-y, --yes", "never prompt: accept the price and every confirmation").option("--json", "JSON output: one result on stdout, progress on stderr (the default when stdout is not a terminal)").option("--debug", "print HTTP requests (secrets masked)");
22665
+ function sharedDeployOptions(cmd, waitDefaultMinutes, nameHelp, locationHelp = "Hetzner location: fsn1, nbg1 or hel1 (default: any with capacity)", cloudHelp) {
22666
+ cmd = cmd.argument("[database-url]", "the database: postgresql://user:password@host:5432/dbname").option("--db-url <url>", "the database URL (the same as the argument)").option("--name <name>", nameHelp).option("--location <location>", locationHelp);
22667
+ if (cloudHelp)
22668
+ cmd = cmd.option("--cloud <cloud>", cloudHelp);
22669
+ return cmd.option("--wait <minutes>", "how long to wait for it to be ready (0 = do not wait)", String(waitDefaultMinutes)).option("--no-wait", "return once the deploy has started (the same as --wait 0)").option("-y, --yes", "never prompt: accept the price and every confirmation").option("--json", "JSON output: one result on stdout, progress on stderr (the default when stdout is not a terminal)").option("--debug", "print HTTP requests (secrets masked)");
22667
22670
  }
22668
22671
 
22669
22672
  // lib/joe.ts
@@ -22964,6 +22967,10 @@ function caNote(url) {
22964
22967
  return;
22965
22968
  return `the monitoring box has no copy of the CA in sslrootcert: with sslmode=${q.get("sslmode")} it connects only to a server certificate signed by a public CA (else use sslmode=require)`;
22966
22969
  }
22970
+ function chargeFailed(error, rerun, billingUrl, couponFlag = "--coupon") {
22971
+ const fix = /promotion code|coupon/i.test(error) ? `The promo code cannot be used by this organization: ${rerun} without ${couponFlag}, or with a code this organization can use` : `Update the payment method${billingUrl ? ` at ${billingUrl}` : ""}, then ${rerun}`;
22972
+ return `The first charge failed (${error}): the box is being removed and nothing is billed. ${fix}`;
22973
+ }
22967
22974
  function connectStatus(row, provider = row.provider, fresh = false) {
22968
22975
  const base = { provider, name: row.name, id: row.id, ...row.health_url ? { health_url: row.health_url } : {}, dashboard_url: row.dashboard_url, host_metrics: row.host_metrics };
22969
22976
  const status = stateOf(row.status);
@@ -22971,7 +22978,7 @@ function connectStatus(row, provider = row.provider, fresh = false) {
22971
22978
  return {
22972
22979
  ...base,
22973
22980
  status: "action_required",
22974
- next: `The first charge failed (${row.billing_error}): the box is being removed and nothing is billed. Update the payment method, then re-run pgai mon deploy.`
22981
+ next: `${chargeFailed(row.billing_error, "re-run pgai mon deploy")}.`
22975
22982
  };
22976
22983
  }
22977
22984
  if (status === "ready") {
@@ -22992,6 +22999,7 @@ var ESCAPES = /(?:\x1b\[|\x9b)[0-?]*[ -\/]*[@-~]|(?:\x1b\]|\x9d)[^\x07\x1b\x9c]*
22992
22999
  var terminalText = (text) => text.replace(ESCAPES, "").split(`
22993
23000
  `).map(stripControlsToSpace).join(`
22994
23001
  `);
23002
+ var cloudWord = (cloud) => ({ aws: "AWS", hetzner: "Hetzner" })[cloud] ?? cloud;
22995
23003
  var boxState = (row) => row.status === "launch_requested" && row.registered_at ? "registered" : row.status ?? "starting";
22996
23004
  function boxWords(state) {
22997
23005
  if (!state || state === "starting" || state === "launch_requested")
@@ -23000,7 +23008,7 @@ function boxWords(state) {
23000
23008
  return "installing monitoring";
23001
23009
  return monitoringStatus(state).replace("_", " ");
23002
23010
  }
23003
- async function billingFor(q, name, opts, deps, show) {
23011
+ async function billingFor(q, name, opts, deps, show, ask) {
23004
23012
  const billing = { price: priceText(q), requires_payment_method: q.requires_payment_method };
23005
23013
  if (opts.coupon) {
23006
23014
  billing.coupon = q.promo?.valid ? { code: q.promo.code, valid: true, description: q.promo.discount_description } : { code: opts.coupon, valid: false, error: q.promo?.error ?? "not valid" };
@@ -23014,6 +23022,12 @@ async function billingFor(q, name, opts, deps, show) {
23014
23022
  if (q.requires_payment_method)
23015
23023
  return { billing, billingPage, billingUrl, accepted: false, stop: billingPage };
23016
23024
  show(billing.price);
23025
+ if (ask) {
23026
+ const d = await ask(billing.price);
23027
+ if (!d.go)
23028
+ return { billing, billingPage, billingUrl, accepted: false, stop: { ...billing, ...d.stop } };
23029
+ return { billing, billingPage, billingUrl, accepted: q.billed, placed: d.place };
23030
+ }
23017
23031
  if (q.billed && !opts.yes && !await deps.confirm(`Provision ${terminalText(name)}? (y/N): `)) {
23018
23032
  return stop(opts.agent ? `Call deploy_monitoring again with yes: true to accept ${billing.price}` : `Re-run with --yes to accept ${billing.price}`);
23019
23033
  }
@@ -23104,6 +23118,7 @@ async function connect(url, opts, deps) {
23104
23118
  let billingPage;
23105
23119
  let accepted = false;
23106
23120
  let billingUrl;
23121
+ let place;
23107
23122
  let undoRole;
23108
23123
  const findOrg = async () => {
23109
23124
  try {
@@ -23198,6 +23213,9 @@ async function connect(url, opts, deps) {
23198
23213
  }
23199
23214
  return { status: "action_required", provider, name, ...refusal };
23200
23215
  }
23216
+ const where = { db_host: new URL(url).hostname };
23217
+ const placed = await placeBox(deps, opts, where, progress);
23218
+ place = placed?.place;
23201
23219
  let quote;
23202
23220
  try {
23203
23221
  quote = await deps.quote(opts.coupon, clusterOf(url));
@@ -23206,9 +23224,11 @@ async function connect(url, opts, deps) {
23206
23224
  return { status: "action_required", provider, name, next: notAdminNext };
23207
23225
  throw err;
23208
23226
  }
23209
- const b = await billingFor(quote, name, opts, deps, (price) => progress("billing", estimateLine(price)));
23227
+ const b = await billingFor(quote, name, opts, deps, (price) => progress("billing", estimateLine(price)), placed && ((price) => decide(placed, name, price, opts, deps, where, progress)));
23210
23228
  if (b.stop)
23211
- return { status: "action_required", provider, name, ...b.stop };
23229
+ return { status: "action_required", provider, name, ...place, ...b.stop };
23230
+ if (b.placed)
23231
+ place = b.placed.place;
23212
23232
  if (deps.aborted?.())
23213
23233
  throw new CancelledError;
23214
23234
  ({ billing, billingPage, billingUrl, accepted } = b);
@@ -23278,7 +23298,7 @@ async function connect(url, opts, deps) {
23278
23298
  ...opts.coupon ? { promo_code: opts.coupon } : {},
23279
23299
  ...accepted ? { accept_price: true } : {},
23280
23300
  ...opts.name ? { project_name: opts.name } : {},
23281
- ...opts.location ? { server_location: opts.location } : {},
23301
+ ...place ? { cloud: place.cloud, server_location: place.location } : opts.location ? { server_location: opts.location } : {},
23282
23302
  ...vcpus ? { vcpus } : {}
23283
23303
  }).catch(async (err) => {
23284
23304
  if (err instanceof HttpStatusError && err.status >= 400 && err.status < 500)
@@ -23318,7 +23338,65 @@ async function connect(url, opts, deps) {
23318
23338
  const made = prepared;
23319
23339
  undoRole = () => undo(made);
23320
23340
  }
23321
- return follow(row, { provider, name, fresh, billing, billingUrl, undoRole, note }, opts, deps, progress);
23341
+ return follow(row, { provider, name, fresh, billing, billingUrl, undoRole, note, place }, opts, deps, progress);
23342
+ }
23343
+ async function placeBox(deps, opts, where, progress) {
23344
+ if (!deps.deployOptions)
23345
+ return;
23346
+ const cloud = opts.cloud?.trim().toLowerCase() || undefined;
23347
+ const location = opts.location?.trim() || undefined;
23348
+ const flag = (f) => opts.agent ? f : `--${f}`;
23349
+ let options;
23350
+ try {
23351
+ options = await deps.deployOptions({ ...where, ...cloud ? { cloud } : {}, ...location ? { location } : {}, check_stock: true });
23352
+ } catch (err) {
23353
+ if (httpStatus(err) !== 404)
23354
+ throw err;
23355
+ if (cloud)
23356
+ throw new Error(`This PostgresAI platform does not take ${flag("cloud")} yet: re-run without it. Nothing was created.`);
23357
+ if (location && where.supabase_project_ids) {
23358
+ throw new Error(`This PostgresAI platform does not take ${flag("location")} for Supabase yet: re-run without it. Nothing was created.`);
23359
+ }
23360
+ return;
23361
+ }
23362
+ if (!options.choice) {
23363
+ const said = options.error?.detail ?? options.error?.message ?? "The platform did not say where the monitoring box can run.";
23364
+ const elsewhere = location ? options.clouds.find((c) => c.available && c.code !== cloud && options.locations[c.code]?.some((l) => l.code === location)) : undefined;
23365
+ const available = options.clouds.filter((c) => c.available).map((c) => c.code);
23366
+ const how = elsewhere ? ` ${cloud ? "Use" : "Add"} ${flag("cloud")} ${elsewhere.code}.` : /^(Monitoring on .* is not (available here|offered yet)|Unknown cloud)/.test(said) && available.length ? ` Re-run with ${flag("cloud")} ${available.length === 1 ? available[0] : `set to one of: ${available.join(", ")}`}.` : "";
23367
+ throw new Error(`${said}${how} Nothing was created.`);
23368
+ }
23369
+ const c = options.choice;
23370
+ progress("preparing", `Monitoring box: ${c.cloud_label}, ${c.location} (${c.reason_text})`, { cloud: c.cloud, location: c.location, location_reason: c.reason });
23371
+ return { place: { cloud: c.cloud, location: c.location, location_reason: c.reason, location_reason_text: c.reason_text }, options };
23372
+ }
23373
+ async function decide(placed, name, price, opts, deps, where, progress) {
23374
+ if (opts.yes)
23375
+ return { go: true };
23376
+ const { place, options } = placed;
23377
+ const label = options.choice?.cloud_label ?? cloudWord(place.cloud);
23378
+ const explicit = !!(opts.cloud?.trim() || opts.location?.trim());
23379
+ const nothing = "Nothing was created";
23380
+ if (deps.choosePlace) {
23381
+ if (explicit) {
23382
+ return await deps.confirm(`Deploy ${terminalText(name)} on ${label}, ${place.location}? [y/N] `) ? { go: true } : { go: false, stop: { next: `${nothing}: re-run with --yes to deploy on ${label}, ${place.location}` } };
23383
+ }
23384
+ const answer = await deps.choosePlace(options, name);
23385
+ if (answer === true)
23386
+ return { go: true };
23387
+ if (answer === false)
23388
+ return { go: false, stop: { next: `${nothing}: re-run to deploy, with --cloud and --location to choose where` } };
23389
+ const summary = (_event, message, more) => progress("billing", message, more);
23390
+ const again = await placeBox(deps, { ...opts, cloud: answer.cloud, location: answer.location }, where, summary);
23391
+ if (!again)
23392
+ throw new Error(`The platform did not place the box on ${answer.cloud}, ${answer.location}. ${nothing}.`);
23393
+ summary("billing", `Next time, to skip this question: --cloud ${again.place.cloud} --location ${again.place.location} --yes`);
23394
+ return { go: true, place: again };
23395
+ }
23396
+ const choices = Object.fromEntries(options.clouds.filter((c) => c.available && options.locations[c.code]?.length).map((c) => [c.code, options.locations[c.code].map((l) => l.code)]));
23397
+ const here = `${label}, ${place.location} (${place.location_reason_text})`;
23398
+ const next = opts.agent ? `Show the user where the monitoring box would run (${here}) and the price (${price}), then call deploy_monitoring again with yes: true, or with cloud and location from choices and yes: true. ${nothing}.` : `The monitoring box would run on ${here} for ${price}: re-run with --yes to deploy there, or with --cloud and --location (choices below) and --yes. ${nothing}.`;
23399
+ return { go: false, stop: { location_reason_text: place.location_reason_text, choices, next } };
23322
23400
  }
23323
23401
  var isSupabaseUrl = (link) => {
23324
23402
  try {
@@ -23377,8 +23455,6 @@ function supabaseProjectUrl(ref, db = "postgres") {
23377
23455
  function supabaseOptionsRefused(opts) {
23378
23456
  if (opts.resetPassword)
23379
23457
  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
23458
  if (opts.monitoringUser !== undefined && opts.monitoringUser.trim() !== DEFAULT_MONITORING_USER) {
23383
23459
  return `${opts.agent ? "monitoring_user" : "--monitoring-user"} does not apply to Supabase: PostgresAI creates ${DEFAULT_MONITORING_USER} through the Supabase Management API`;
23384
23460
  }
@@ -23525,6 +23601,9 @@ async function deploySupabaseProject(urlRef, opts, deps, progress) {
23525
23601
  }
23526
23602
  async function supabaseBox(ref, name, opts, deps, progress, stop, label) {
23527
23603
  const provider = "supabase";
23604
+ const where = { supabase_project_ids: [ref] };
23605
+ const placed = await placeBox(deps, opts, where, progress);
23606
+ let place = placed?.place;
23528
23607
  let quote;
23529
23608
  try {
23530
23609
  quote = await deps.quote(opts.coupon);
@@ -23533,9 +23612,11 @@ async function supabaseBox(ref, name, opts, deps, progress, stop, label) {
23533
23612
  return stop(notAdminNext);
23534
23613
  throw err;
23535
23614
  }
23536
- const b = await billingFor(quote, label ?? name, opts, deps, (price) => progress("billing", estimateLine(price), label ? { project: label } : {}));
23615
+ const b = await billingFor(quote, label ?? name, opts, deps, (price) => progress("billing", estimateLine(price), label ? { project: label } : {}), placed && ((price) => decide(placed, label ?? name, price, opts, deps, where, progress)));
23537
23616
  if (b.stop)
23538
- return { status: "action_required", provider, name, ...b.stop };
23617
+ return { status: "action_required", provider, name, ...place, ...b.stop };
23618
+ if (b.placed)
23619
+ place = b.placed.place;
23539
23620
  if (deps.aborted?.())
23540
23621
  throw new CancelledError;
23541
23622
  progress("provisioning", `Provisioning monitoring for ${label ?? name}`, label ? { project: label } : {});
@@ -23544,7 +23625,8 @@ async function supabaseBox(ref, name, opts, deps, progress, stop, label) {
23544
23625
  ...opts.name ? { name: opts.name } : {},
23545
23626
  ...b.accepted ? { accept_price: true } : {},
23546
23627
  ...opts.coupon ? { promo_code: opts.coupon } : {},
23547
- ...opts.vcpus ? { vcpus: opts.vcpus } : {}
23628
+ ...opts.vcpus ? { vcpus: opts.vcpus } : {},
23629
+ ...place ? { cloud: place.cloud, location: place.location } : {}
23548
23630
  }).catch((err) => {
23549
23631
  if (err instanceof HttpStatusError && err.status === 402)
23550
23632
  return /declined/i.test(err.message) ? "declined" : "payment";
@@ -23567,11 +23649,12 @@ async function supabaseBox(ref, name, opts, deps, progress, stop, label) {
23567
23649
  const box = { id: created.id, name: created.name, provider, status: created.status, dashboard_url: null, host_metrics: false };
23568
23650
  if (deps.aborted?.())
23569
23651
  return { ...connectStatus(box, provider, true), ...b.billing };
23570
- return follow(box, { provider, name, fresh: true, billing: b.billing, billingUrl: b.billingUrl, note: "" }, opts, deps, progress);
23652
+ return follow(box, { provider, name, fresh: true, billing: b.billing, billingUrl: b.billingUrl, note: "", place }, opts, deps, progress);
23571
23653
  }
23572
23654
  var STILL_IN_PROGRESS = "Still in progress";
23573
23655
  async function follow(row, f, opts, deps, progress) {
23574
- const { provider, name, fresh, billing, billingUrl, undoRole, note } = f;
23656
+ const { provider, name, fresh, billingUrl, undoRole, note } = f;
23657
+ const billing = { ...f.billing, ...f.place };
23575
23658
  let shown;
23576
23659
  for (const deadline = deps.now() + opts.waitMs;; ) {
23577
23660
  if (row.billing_error && disconnecting(row.status)) {
@@ -23583,7 +23666,7 @@ async function follow(row, f, opts, deps, progress) {
23583
23666
  name,
23584
23667
  id: row.id,
23585
23668
  ...billing,
23586
- next: `The first charge failed (${row.billing_error}): the box is being removed and nothing is billed. Update the payment method${billingUrl ? ` at ${billingUrl}` : ""}, then re-run`
23669
+ next: chargeFailed(row.billing_error, "re-run", billingUrl, opts.agent ? "coupon" : "--coupon")
23587
23670
  };
23588
23671
  }
23589
23672
  const result = connectStatus(row, provider, fresh);
@@ -23901,6 +23984,7 @@ function platformDeps(p) {
23901
23984
  supabaseStatus: (sessionId) => rpc("cloud_monitoring_supabase_status", { session_id: sessionId }),
23902
23985
  supabaseConnect: (body) => rpc("cloud_monitoring_supabase_connect", body),
23903
23986
  supabaseProjects: () => rpc("cloud_monitoring_supabase_projects", {}),
23987
+ deployOptions: (args) => rpc("monitoring_deploy_options", args),
23904
23988
  handoffUrl: async (provider) => {
23905
23989
  const orgs = await listOrgs({ apiKey: p.apiKey, apiBaseUrl: p.apiBaseUrl });
23906
23990
  const org = orgs.length === 1 ? orgs[0] : orgs.find((o) => o.alias === p.orgScope?.alias || o.org_id === p.orgScope?.id);
@@ -30598,6 +30682,8 @@ async function handleToolCall(req, rootOpts, extra) {
30598
30682
  yes: args.yes === true,
30599
30683
  vcpus: args.vcpus === undefined || args.vcpus === null ? undefined : vcpusArg(String(args.vcpus)),
30600
30684
  monitoringUser: args.monitoring_user === undefined || args.monitoring_user === null ? undefined : String(args.monitoring_user),
30685
+ cloud: args.cloud === undefined || args.cloud === null ? undefined : String(args.cloud),
30686
+ location: args.location === undefined || args.location === null ? undefined : String(args.location),
30601
30687
  waitMs: 0,
30602
30688
  agent: true
30603
30689
  }, {
@@ -31180,7 +31266,9 @@ async function startMcpServer(rootOpts, extra) {
31180
31266
  database_url: { type: "string", description: "postgresql:// URL with the password in it (admin, or the postgres_ai_mon role)" },
31181
31267
  provider: { type: "string", description: "generic (direct PostgreSQL URL; alias: self-managed) | clickhouse | rds | supabase (default: detected from the host)" },
31182
31268
  clickhouse_key: { type: "string", description: "ClickHouse Cloud API key as <key-id>:<key-secret> (Basic Service API Reader), for CPU, memory and disk" },
31183
- yes: { type: "boolean", description: "Accept the price of a billed box. Without it, a billed box is not provisioned: the result has status action_required and the price; ask the user, then call again with yes: true" },
31269
+ yes: { type: "boolean", description: "Deploy: accept where the box runs and its price. Without it no box is provisioned, free or billed (on a platform without cloud choice, only a billed one waits for it): the result has status action_required with cloud, location, location_reason_text, price and choices (each cloud's locations); show them to the user, then call again with yes: true (and cloud/location if they chose another place)" },
31270
+ cloud: { type: "string", description: "Where the monitoring box runs: aws or hetzner (default: the database's cloud, else the platform's default). One of the result's choices" },
31271
+ location: { type: "string", description: "A location of that cloud, from the result's choices (default: the database's region, else the cloud's default)" },
31184
31272
  coupon: { type: "string", description: "Stripe promotion code for the organization's monitoring subscription (applies when it is first created)" },
31185
31273
  vcpus: { type: "integer", minimum: 1, maximum: 1024, description: "vCPUs of the database server. Without it there is no AAS (database load) data for this database: ask the user for it" },
31186
31274
  monitoring_user: { type: "string", description: "Monitoring role to create or use (default postgres_ai_mon). A custom role always carries its own password: PostgresAI keeps only postgres_ai_mon's, so pass the role's own URL as database_url (an admin URL creates only postgres_ai_mon). Not for Supabase, where PostgresAI creates postgres_ai_mon" },
@@ -32256,6 +32344,10 @@ function caNote2(url) {
32256
32344
  return;
32257
32345
  return `the monitoring box has no copy of the CA in sslrootcert: with sslmode=${q.get("sslmode")} it connects only to a server certificate signed by a public CA (else use sslmode=require)`;
32258
32346
  }
32347
+ function chargeFailed2(error, rerun, billingUrl, couponFlag = "--coupon") {
32348
+ const fix = /promotion code|coupon/i.test(error) ? `The promo code cannot be used by this organization: ${rerun} without ${couponFlag}, or with a code this organization can use` : `Update the payment method${billingUrl ? ` at ${billingUrl}` : ""}, then ${rerun}`;
32349
+ return `The first charge failed (${error}): the box is being removed and nothing is billed. ${fix}`;
32350
+ }
32259
32351
  function connectStatus2(row, provider = row.provider, fresh = false) {
32260
32352
  const base = { provider, name: row.name, id: row.id, ...row.health_url ? { health_url: row.health_url } : {}, dashboard_url: row.dashboard_url, host_metrics: row.host_metrics };
32261
32353
  const status = stateOf2(row.status);
@@ -32263,7 +32355,7 @@ function connectStatus2(row, provider = row.provider, fresh = false) {
32263
32355
  return {
32264
32356
  ...base,
32265
32357
  status: "action_required",
32266
- next: `The first charge failed (${row.billing_error}): the box is being removed and nothing is billed. Update the payment method, then re-run pgai mon deploy.`
32358
+ next: `${chargeFailed2(row.billing_error, "re-run pgai mon deploy")}.`
32267
32359
  };
32268
32360
  }
32269
32361
  if (status === "ready") {
@@ -32316,6 +32408,7 @@ function stepProgress(o) {
32316
32408
  function resultLines(r) {
32317
32409
  return personLines(r).map(terminalText2);
32318
32410
  }
32411
+ var cloudWord2 = (cloud) => ({ aws: "AWS", hetzner: "Hetzner" })[cloud] ?? cloud;
32319
32412
  function personLines(r) {
32320
32413
  const who = r.name || "this database";
32321
32414
  const extra = (r.next ?? "").split("; ").slice(1).join("; ");
@@ -32327,6 +32420,7 @@ function personLines(r) {
32327
32420
  ...r.health_url ? [` Health Matrix: ${r.health_url}`] : [],
32328
32421
  ...r.dashboard_url ? [` Grafana: ${r.dashboard_url}`] : [],
32329
32422
  ...r.price ? [` Price: ${r.price}`] : [],
32423
+ ...r.cloud ? [` Runs on: ${cloudWord2(r.cloud)}, ${r.location}`] : [],
32330
32424
  ...!r.health_url && !r.dashboard_url && r.next && r.next !== "none" ? [`Next: ${r.next}`] : [],
32331
32425
  ...extra && (r.health_url || r.dashboard_url) ? [`Note: ${extra}`] : []
32332
32426
  ];
@@ -32336,7 +32430,9 @@ function personLines(r) {
32336
32430
  case "deleted":
32337
32431
  return [`Deleting the monitoring of ${who}.${billing ? ` Billing: ${billing}.` : ""}${r.next && r.next !== "none" ? ` ${r.next}` : ""}`];
32338
32432
  default:
32339
- return r.projects?.length ? [r.next, ...supabaseProjectRows(r.projects)] : [r.next];
32433
+ if (r.projects?.length)
32434
+ return [r.next, ...supabaseProjectRows(r.projects)];
32435
+ return r.choices ? [r.next, ...Object.entries(r.choices).map(([cloud, codes]) => ` --cloud ${cloud} --location ${codes.join("|")}`)] : [r.next];
32340
32436
  }
32341
32437
  }
32342
32438
  function progressText(e) {
@@ -32356,7 +32452,7 @@ function boxWords2(state) {
32356
32452
  return "installing monitoring";
32357
32453
  return monitoringStatus(state).replace("_", " ");
32358
32454
  }
32359
- async function billingFor2(q, name, opts, deps, show) {
32455
+ async function billingFor2(q, name, opts, deps, show, ask) {
32360
32456
  const billing = { price: priceText2(q), requires_payment_method: q.requires_payment_method };
32361
32457
  if (opts.coupon) {
32362
32458
  billing.coupon = q.promo?.valid ? { code: q.promo.code, valid: true, description: q.promo.discount_description } : { code: opts.coupon, valid: false, error: q.promo?.error ?? "not valid" };
@@ -32370,6 +32466,12 @@ async function billingFor2(q, name, opts, deps, show) {
32370
32466
  if (q.requires_payment_method)
32371
32467
  return { billing, billingPage, billingUrl, accepted: false, stop: billingPage };
32372
32468
  show(billing.price);
32469
+ if (ask) {
32470
+ const d = await ask(billing.price);
32471
+ if (!d.go)
32472
+ return { billing, billingPage, billingUrl, accepted: false, stop: { ...billing, ...d.stop } };
32473
+ return { billing, billingPage, billingUrl, accepted: q.billed, placed: d.place };
32474
+ }
32373
32475
  if (q.billed && !opts.yes && !await deps.confirm(`Provision ${terminalText2(name)}? (y/N): `)) {
32374
32476
  return stop(opts.agent ? `Call deploy_monitoring again with yes: true to accept ${billing.price}` : `Re-run with --yes to accept ${billing.price}`);
32375
32477
  }
@@ -32460,6 +32562,7 @@ async function connect2(url, opts, deps) {
32460
32562
  let billingPage;
32461
32563
  let accepted = false;
32462
32564
  let billingUrl;
32565
+ let place;
32463
32566
  let undoRole;
32464
32567
  const findOrg = async () => {
32465
32568
  try {
@@ -32554,6 +32657,9 @@ async function connect2(url, opts, deps) {
32554
32657
  }
32555
32658
  return { status: "action_required", provider, name, ...refusal };
32556
32659
  }
32660
+ const where = { db_host: new URL(url).hostname };
32661
+ const placed = await placeBox2(deps, opts, where, progress);
32662
+ place = placed?.place;
32557
32663
  let quote;
32558
32664
  try {
32559
32665
  quote = await deps.quote(opts.coupon, clusterOf2(url));
@@ -32562,9 +32668,11 @@ async function connect2(url, opts, deps) {
32562
32668
  return { status: "action_required", provider, name, next: notAdminNext };
32563
32669
  throw err;
32564
32670
  }
32565
- const b = await billingFor2(quote, name, opts, deps, (price) => progress("billing", estimateLine(price)));
32671
+ const b = await billingFor2(quote, name, opts, deps, (price) => progress("billing", estimateLine(price)), placed && ((price) => decide2(placed, name, price, opts, deps, where, progress)));
32566
32672
  if (b.stop)
32567
- return { status: "action_required", provider, name, ...b.stop };
32673
+ return { status: "action_required", provider, name, ...place, ...b.stop };
32674
+ if (b.placed)
32675
+ place = b.placed.place;
32568
32676
  if (deps.aborted?.())
32569
32677
  throw new CancelledError2;
32570
32678
  ({ billing, billingPage, billingUrl, accepted } = b);
@@ -32634,7 +32742,7 @@ async function connect2(url, opts, deps) {
32634
32742
  ...opts.coupon ? { promo_code: opts.coupon } : {},
32635
32743
  ...accepted ? { accept_price: true } : {},
32636
32744
  ...opts.name ? { project_name: opts.name } : {},
32637
- ...opts.location ? { server_location: opts.location } : {},
32745
+ ...place ? { cloud: place.cloud, server_location: place.location } : opts.location ? { server_location: opts.location } : {},
32638
32746
  ...vcpus ? { vcpus } : {}
32639
32747
  }).catch(async (err) => {
32640
32748
  if (err instanceof HttpStatusError && err.status >= 400 && err.status < 500)
@@ -32674,7 +32782,110 @@ async function connect2(url, opts, deps) {
32674
32782
  const made = prepared;
32675
32783
  undoRole = () => undo(made);
32676
32784
  }
32677
- return follow2(row, { provider, name, fresh, billing, billingUrl, undoRole, note }, opts, deps, progress);
32785
+ return follow2(row, { provider, name, fresh, billing, billingUrl, undoRole, note, place }, opts, deps, progress);
32786
+ }
32787
+ async function placeBox2(deps, opts, where, progress) {
32788
+ if (!deps.deployOptions)
32789
+ return;
32790
+ const cloud = opts.cloud?.trim().toLowerCase() || undefined;
32791
+ const location = opts.location?.trim() || undefined;
32792
+ const flag = (f) => opts.agent ? f : `--${f}`;
32793
+ let options;
32794
+ try {
32795
+ options = await deps.deployOptions({ ...where, ...cloud ? { cloud } : {}, ...location ? { location } : {}, check_stock: true });
32796
+ } catch (err) {
32797
+ if (httpStatus2(err) !== 404)
32798
+ throw err;
32799
+ if (cloud)
32800
+ throw new Error(`This PostgresAI platform does not take ${flag("cloud")} yet: re-run without it. Nothing was created.`);
32801
+ if (location && where.supabase_project_ids) {
32802
+ throw new Error(`This PostgresAI platform does not take ${flag("location")} for Supabase yet: re-run without it. Nothing was created.`);
32803
+ }
32804
+ return;
32805
+ }
32806
+ if (!options.choice) {
32807
+ const said = options.error?.detail ?? options.error?.message ?? "The platform did not say where the monitoring box can run.";
32808
+ const elsewhere = location ? options.clouds.find((c) => c.available && c.code !== cloud && options.locations[c.code]?.some((l) => l.code === location)) : undefined;
32809
+ const available = options.clouds.filter((c) => c.available).map((c) => c.code);
32810
+ const how = elsewhere ? ` ${cloud ? "Use" : "Add"} ${flag("cloud")} ${elsewhere.code}.` : /^(Monitoring on .* is not (available here|offered yet)|Unknown cloud)/.test(said) && available.length ? ` Re-run with ${flag("cloud")} ${available.length === 1 ? available[0] : `set to one of: ${available.join(", ")}`}.` : "";
32811
+ throw new Error(`${said}${how} Nothing was created.`);
32812
+ }
32813
+ const c = options.choice;
32814
+ progress("preparing", `Monitoring box: ${c.cloud_label}, ${c.location} (${c.reason_text})`, { cloud: c.cloud, location: c.location, location_reason: c.reason });
32815
+ return { place: { cloud: c.cloud, location: c.location, location_reason: c.reason, location_reason_text: c.reason_text }, options };
32816
+ }
32817
+ async function pickPlace(options, name, ask, say) {
32818
+ const number = async (what, n) => {
32819
+ for (let tries = 0;tries < 3; tries++) {
32820
+ const answer = (await ask(`${what} (1-${n}, Enter to cancel): `)).trim();
32821
+ if (!answer)
32822
+ return;
32823
+ const i = Number(answer);
32824
+ if (Number.isInteger(i) && i >= 1 && i <= n)
32825
+ return i - 1;
32826
+ say(`Type a number from 1 to ${n}.`);
32827
+ }
32828
+ return;
32829
+ };
32830
+ for (let tries = 0;tries < 3; tries++) {
32831
+ const answer = (await ask(`Deploy ${terminalText2(name)} here? [y]es / [c]hoose another location / [N]o: `)).trim().toLowerCase();
32832
+ if (answer === "y" || answer === "yes")
32833
+ return true;
32834
+ if (!answer || answer === "n" || answer === "no")
32835
+ return false;
32836
+ if (answer !== "c" && answer !== "choose") {
32837
+ say("Type y, c or n.");
32838
+ continue;
32839
+ }
32840
+ const clouds = options.clouds.filter((c) => c.available && options.locations[c.code]?.length);
32841
+ say("Clouds:");
32842
+ clouds.forEach((c, i) => say(` ${i + 1}. ${c.label}`));
32843
+ const ci = await number("Cloud", clouds.length);
32844
+ if (ci === undefined)
32845
+ return false;
32846
+ const cloud = clouds[ci];
32847
+ const locations = options.locations[cloud.code];
32848
+ say(`Locations on ${cloud.label}:`);
32849
+ let part = "";
32850
+ locations.forEach((l, i) => {
32851
+ if (l.world_part !== part)
32852
+ say(` ${part = l.world_part}`);
32853
+ say(` ${i + 1}. ${l.code}${l.label ? ` ${terminalText2(l.label)}` : ""}`);
32854
+ });
32855
+ const li = await number("Location", locations.length);
32856
+ if (li === undefined)
32857
+ return false;
32858
+ return { cloud: cloud.code, location: locations[li].code };
32859
+ }
32860
+ return false;
32861
+ }
32862
+ async function decide2(placed, name, price, opts, deps, where, progress) {
32863
+ if (opts.yes)
32864
+ return { go: true };
32865
+ const { place, options } = placed;
32866
+ const label = options.choice?.cloud_label ?? cloudWord2(place.cloud);
32867
+ const explicit = !!(opts.cloud?.trim() || opts.location?.trim());
32868
+ const nothing = "Nothing was created";
32869
+ if (deps.choosePlace) {
32870
+ if (explicit) {
32871
+ return await deps.confirm(`Deploy ${terminalText2(name)} on ${label}, ${place.location}? [y/N] `) ? { go: true } : { go: false, stop: { next: `${nothing}: re-run with --yes to deploy on ${label}, ${place.location}` } };
32872
+ }
32873
+ const answer = await deps.choosePlace(options, name);
32874
+ if (answer === true)
32875
+ return { go: true };
32876
+ if (answer === false)
32877
+ return { go: false, stop: { next: `${nothing}: re-run to deploy, with --cloud and --location to choose where` } };
32878
+ const summary = (_event, message, more) => progress("billing", message, more);
32879
+ const again = await placeBox2(deps, { ...opts, cloud: answer.cloud, location: answer.location }, where, summary);
32880
+ if (!again)
32881
+ throw new Error(`The platform did not place the box on ${answer.cloud}, ${answer.location}. ${nothing}.`);
32882
+ summary("billing", `Next time, to skip this question: --cloud ${again.place.cloud} --location ${again.place.location} --yes`);
32883
+ return { go: true, place: again };
32884
+ }
32885
+ const choices = Object.fromEntries(options.clouds.filter((c) => c.available && options.locations[c.code]?.length).map((c) => [c.code, options.locations[c.code].map((l) => l.code)]));
32886
+ const here = `${label}, ${place.location} (${place.location_reason_text})`;
32887
+ const next = opts.agent ? `Show the user where the monitoring box would run (${here}) and the price (${price}), then call deploy_monitoring again with yes: true, or with cloud and location from choices and yes: true. ${nothing}.` : `The monitoring box would run on ${here} for ${price}: re-run with --yes to deploy there, or with --cloud and --location (choices below) and --yes. ${nothing}.`;
32888
+ return { go: false, stop: { location_reason_text: place.location_reason_text, choices, next } };
32678
32889
  }
32679
32890
  var isSupabaseUrl2 = (link) => {
32680
32891
  try {
@@ -32733,8 +32944,6 @@ function supabaseProjectUrl2(ref, db = "postgres") {
32733
32944
  function supabaseOptionsRefused2(opts) {
32734
32945
  if (opts.resetPassword)
32735
32946
  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
32947
  if (opts.monitoringUser !== undefined && opts.monitoringUser.trim() !== DEFAULT_MONITORING_USER) {
32739
32948
  return `${opts.agent ? "monitoring_user" : "--monitoring-user"} does not apply to Supabase: PostgresAI creates ${DEFAULT_MONITORING_USER} through the Supabase Management API`;
32740
32949
  }
@@ -32901,6 +33110,9 @@ async function deploySupabaseProject2(urlRef, opts, deps, progress) {
32901
33110
  }
32902
33111
  async function supabaseBox2(ref, name, opts, deps, progress, stop, label) {
32903
33112
  const provider = "supabase";
33113
+ const where = { supabase_project_ids: [ref] };
33114
+ const placed = await placeBox2(deps, opts, where, progress);
33115
+ let place = placed?.place;
32904
33116
  let quote;
32905
33117
  try {
32906
33118
  quote = await deps.quote(opts.coupon);
@@ -32909,9 +33121,11 @@ async function supabaseBox2(ref, name, opts, deps, progress, stop, label) {
32909
33121
  return stop(notAdminNext);
32910
33122
  throw err;
32911
33123
  }
32912
- const b = await billingFor2(quote, label ?? name, opts, deps, (price) => progress("billing", estimateLine(price), label ? { project: label } : {}));
33124
+ const b = await billingFor2(quote, label ?? name, opts, deps, (price) => progress("billing", estimateLine(price), label ? { project: label } : {}), placed && ((price) => decide2(placed, label ?? name, price, opts, deps, where, progress)));
32913
33125
  if (b.stop)
32914
- return { status: "action_required", provider, name, ...b.stop };
33126
+ return { status: "action_required", provider, name, ...place, ...b.stop };
33127
+ if (b.placed)
33128
+ place = b.placed.place;
32915
33129
  if (deps.aborted?.())
32916
33130
  throw new CancelledError2;
32917
33131
  progress("provisioning", `Provisioning monitoring for ${label ?? name}`, label ? { project: label } : {});
@@ -32920,7 +33134,8 @@ async function supabaseBox2(ref, name, opts, deps, progress, stop, label) {
32920
33134
  ...opts.name ? { name: opts.name } : {},
32921
33135
  ...b.accepted ? { accept_price: true } : {},
32922
33136
  ...opts.coupon ? { promo_code: opts.coupon } : {},
32923
- ...opts.vcpus ? { vcpus: opts.vcpus } : {}
33137
+ ...opts.vcpus ? { vcpus: opts.vcpus } : {},
33138
+ ...place ? { cloud: place.cloud, location: place.location } : {}
32924
33139
  }).catch((err) => {
32925
33140
  if (err instanceof HttpStatusError && err.status === 402)
32926
33141
  return /declined/i.test(err.message) ? "declined" : "payment";
@@ -32943,11 +33158,12 @@ async function supabaseBox2(ref, name, opts, deps, progress, stop, label) {
32943
33158
  const box = { id: created.id, name: created.name, provider, status: created.status, dashboard_url: null, host_metrics: false };
32944
33159
  if (deps.aborted?.())
32945
33160
  return { ...connectStatus2(box, provider, true), ...b.billing };
32946
- return follow2(box, { provider, name, fresh: true, billing: b.billing, billingUrl: b.billingUrl, note: "" }, opts, deps, progress);
33161
+ return follow2(box, { provider, name, fresh: true, billing: b.billing, billingUrl: b.billingUrl, note: "", place }, opts, deps, progress);
32947
33162
  }
32948
33163
  var STILL_IN_PROGRESS2 = "Still in progress";
32949
33164
  async function follow2(row, f, opts, deps, progress) {
32950
- const { provider, name, fresh, billing, billingUrl, undoRole, note } = f;
33165
+ const { provider, name, fresh, billingUrl, undoRole, note } = f;
33166
+ const billing = { ...f.billing, ...f.place };
32951
33167
  let shown;
32952
33168
  for (const deadline = deps.now() + opts.waitMs;; ) {
32953
33169
  if (row.billing_error && disconnecting2(row.status)) {
@@ -32959,7 +33175,7 @@ async function follow2(row, f, opts, deps, progress) {
32959
33175
  name,
32960
33176
  id: row.id,
32961
33177
  ...billing,
32962
- next: `The first charge failed (${row.billing_error}): the box is being removed and nothing is billed. Update the payment method${billingUrl ? ` at ${billingUrl}` : ""}, then re-run`
33178
+ next: chargeFailed2(row.billing_error, "re-run", billingUrl, opts.agent ? "coupon" : "--coupon")
32963
33179
  };
32964
33180
  }
32965
33181
  const result = connectStatus2(row, provider, fresh);
@@ -33293,6 +33509,7 @@ function platformDeps2(p) {
33293
33509
  supabaseStatus: (sessionId) => rpc("cloud_monitoring_supabase_status", { session_id: sessionId }),
33294
33510
  supabaseConnect: (body) => rpc("cloud_monitoring_supabase_connect", body),
33295
33511
  supabaseProjects: () => rpc("cloud_monitoring_supabase_projects", {}),
33512
+ deployOptions: (args) => rpc("monitoring_deploy_options", args),
33296
33513
  handoffUrl: async (provider) => {
33297
33514
  const orgs = await listOrgs({ apiKey: p.apiKey, apiBaseUrl: p.apiBaseUrl });
33298
33515
  const org = orgs.length === 1 ? orgs[0] : orgs.find((o) => o.alias === p.orgScope?.alias || o.org_id === p.orgScope?.id);
@@ -35220,8 +35437,11 @@ function assertEncodedUserinfo2(url) {
35220
35437
  throw new Error("The database URL has an '@' after the host: percent-encode it as %40 (in the password, the database name or the query; also / as %2F, ? as %3F, # as %23 in the password).");
35221
35438
  }
35222
35439
  }
35223
- function sharedDeployOptions2(cmd, waitDefaultMinutes, nameHelp, locationHelp = "Hetzner location: fsn1, nbg1 or hel1 (default: any with capacity)") {
35224
- return cmd.argument("[database-url]", "the database: postgresql://user:password@host:5432/dbname").option("--db-url <url>", "the database URL (the same as the argument)").option("--name <name>", nameHelp).option("--location <location>", locationHelp).option("--wait <minutes>", "how long to wait for it to be ready (0 = do not wait)", String(waitDefaultMinutes)).option("--no-wait", "return once the deploy has started (the same as --wait 0)").option("-y, --yes", "never prompt: accept the price and every confirmation").option("--json", "JSON output: one result on stdout, progress on stderr (the default when stdout is not a terminal)").option("--debug", "print HTTP requests (secrets masked)");
35440
+ function sharedDeployOptions2(cmd, waitDefaultMinutes, nameHelp, locationHelp = "Hetzner location: fsn1, nbg1 or hel1 (default: any with capacity)", cloudHelp) {
35441
+ cmd = cmd.argument("[database-url]", "the database: postgresql://user:password@host:5432/dbname").option("--db-url <url>", "the database URL (the same as the argument)").option("--name <name>", nameHelp).option("--location <location>", locationHelp);
35442
+ if (cloudHelp)
35443
+ cmd = cmd.option("--cloud <cloud>", cloudHelp);
35444
+ return cmd.option("--wait <minutes>", "how long to wait for it to be ready (0 = do not wait)", String(waitDefaultMinutes)).option("--no-wait", "return once the deploy has started (the same as --wait 0)").option("-y, --yes", "never prompt: accept the price and every confirmation").option("--json", "JSON output: one result on stdout, progress on stderr (the default when stdout is not a terminal)").option("--debug", "print HTTP requests (secrets masked)");
35225
35445
  }
35226
35446
 
35227
35447
  // lib/promql.ts
@@ -47140,6 +47360,15 @@ Projects in the Supabase organization "${org}":`));
47140
47360
  closeReadline();
47141
47361
  }
47142
47362
  } } : {},
47363
+ ...interactive(opts.json) ? { choosePlace: async (options, name) => {
47364
+ process.exitCode = 130;
47365
+ try {
47366
+ return await pickPlace(options, name, question, (line) => console.error(line));
47367
+ } finally {
47368
+ process.exitCode = undefined;
47369
+ closeReadline();
47370
+ }
47371
+ } } : {},
47143
47372
  ...interactive(opts.json) ? { openUrl: openInBrowser } : {},
47144
47373
  progress: (e) => {
47145
47374
  if (e.event === "provisioning")
@@ -47184,7 +47413,7 @@ Projects in the Supabase organization "${org}":`));
47184
47413
  }
47185
47414
  }
47186
47415
  var mon = program2.command("mon").description("monitoring services management");
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", [
47416
+ sharedDeployOptions2(withOrgOptions(mon.command("deploy")), 20, "instance name (default: host[:port]/database)", "the box's region on its cloud (default: the database's region when that cloud has it; see below)", "where the monitoring box runs: aws or hetzner (default: the database's cloud, else aws)").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", [
47188
47417
  "",
47189
47418
  "Steps (each skipped when already done; safe to re-run): sign in, prepare the database",
47190
47419
  "(an admin URL creates the postgres_ai_mon role; otherwise the SQL is printed), provision",
@@ -47192,6 +47421,17 @@ sharedDeployOptions2(withOrgOptions(mon.command("deploy")), 20, "instance name (
47192
47421
  "your PostgresAI account (dashboard_url). The box runs its first checkup at first_checkup_eta",
47193
47422
  "at the earliest (3 minutes after it is ready), once every target has data (at most 30 minutes).",
47194
47423
  "",
47424
+ "Where the box runs: the platform decides, as the console does, and deploy prints it before the",
47425
+ 'price ("Monitoring box: AWS, us-east-2 (same region as your database)"). Without --cloud and',
47426
+ "--location: the database's cloud and region (a Supabase project's region, an RDS, Aurora, EC2,",
47427
+ "Neon or Supabase pooler host), else AWS us-east-1. --location is a region of that cloud; a cloud",
47428
+ "that is not available, or a location it does not have, is refused before anything is created.",
47429
+ 'Without --yes, deploy asks before it creates a box in PostgresAI Cloud, free or billed: "Deploy',
47430
+ '<db> here? [y]es / [c]hoose another location / [N]o" (with --cloud/--location: "Deploy <db> on',
47431
+ '<cloud>, <location>? [y/N]"). Not at a terminal (piped, --json, agents) it stops (exit 3) with the',
47432
+ 'place, the price and the choices ("choices" in the JSON result): re-run with --yes, and with',
47433
+ "--cloud/--location to pick another place.",
47434
+ "",
47195
47435
  "Network: the database must be reachable from this machine and from PostgresAI. Before provisioning,",
47196
47436
  "PostgresAI tests the connection from an unpublished address, so the port must accept connections",
47197
47437
  "from the internet; after it, the monitoring box connects from the IP shown on its Console page.",
@@ -47199,7 +47439,7 @@ sharedDeployOptions2(withOrgOptions(mon.command("deploy")), 20, "instance name (
47199
47439
  "",
47200
47440
  "Billing is per Postgres cluster observed: another database in a cluster the organization already",
47201
47441
  'monitors is included. Once the URL is checked, deploy shows the price (or "free (N of M free slots)"). A billed',
47202
- "box is provisioned only when accepted: at the prompt, or with --yes. With no payment method",
47442
+ "box is provisioned only when accepted: at the prompt above, or with --yes. With no payment method",
47203
47443
  "it stops (exit 3) and names the console page to add one. --coupon applies a promotion code.",
47204
47444
  "",
47205
47445
  "Supabase: PostgresAI creates postgres_ai_mon through the Supabase Management API (the",
@@ -47236,6 +47476,7 @@ sharedDeployOptions2(withOrgOptions(mon.command("deploy")), 20, "instance name (
47236
47476
  " pgai mon deploy --provider supabase",
47237
47477
  " pgai mon deploy --supabase-project <name|project-id> --yes --json",
47238
47478
  " pgai mon deploy 'postgresql://postgres@db.<project-ref>.supabase.co:5432/postgres'",
47479
+ " pgai mon deploy '<url>' --cloud hetzner --location nbg1",
47239
47480
  " pgai mon deploy '<url>' --self-hosted"
47240
47481
  ].join(`
47241
47482
  `)).action((urlArg, opts, cmd) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "postgresai",
3
- "version": "0.18.0-dev.12",
3
+ "version": "0.18.0-dev.13",
4
4
  "description": "postgres_ai CLI",
5
5
  "license": "Apache-2.0",
6
6
  "private": false,