postgresai 0.18.0-dev.17 → 0.18.0-dev.18

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
@@ -229,7 +229,9 @@ and its IP kept: allow it, and run with `--ip-allowed` again. Any database can a
229
229
  monitoring (`--self-hosted`).
230
230
 
231
231
  An Amazon RDS that is not publicly accessible is monitored over AWS PrivateLink: nothing becomes public and no port is
232
- opened. Run the deploy where the database is reachable (in its VPC):
232
+ opened. Run the deploy anywhere: where the database is reachable (in its VPC) it runs the setup SQL itself and checks it
233
+ before the box exists; where it is not, it prints the SQL to run as the master user on a machine that reaches the
234
+ database, and the box checks it over PrivateLink:
233
235
 
234
236
  ```bash
235
237
  pgai mon deploy 'postgresql://postgres:<password>@<instance>.<id>.<region>.rds.amazonaws.com:5432/app'
@@ -13538,7 +13538,7 @@ var {
13538
13538
  // package.json
13539
13539
  var package_default = {
13540
13540
  name: "postgresai",
13541
- version: "0.18.0-dev.17",
13541
+ version: "0.18.0-dev.18",
13542
13542
  description: "postgres_ai CLI",
13543
13543
  license: "Apache-2.0",
13544
13544
  private: false,
@@ -16898,7 +16898,7 @@ var Result = import_lib.default.Result;
16898
16898
  var TypeOverrides = import_lib.default.TypeOverrides;
16899
16899
  var defaults = import_lib.default.defaults;
16900
16900
  // package.json
16901
- var version = "0.18.0-dev.17";
16901
+ var version = "0.18.0-dev.18";
16902
16902
  var package_default2 = {
16903
16903
  name: "postgresai",
16904
16904
  version,
@@ -24157,8 +24157,8 @@ async function readAws(ep, opts, deps, progress) {
24157
24157
  }
24158
24158
  var VERIFY_FAILED = {
24159
24159
  unreachable: "The monitoring box could not reach the database over PrivateLink: check that the stack finished, its load balancer's target is healthy, and the RDS is not publicly accessible.",
24160
- auth_failed: `The monitoring box reached the database, but ${DEFAULT_MONITORING_USER} could not log in: its password changed after this deploy set it (another setup ran its SQL).`,
24161
- nonce_mismatch: "A newer PostgresAI setup SQL ran in this database after this deploy's (another deploy, or the Console), so monitoring does not start."
24160
+ auth_failed: `The monitoring box reached the database, but ${DEFAULT_MONITORING_USER} could not log in with the password this deploy's SQL set: the SQL did not run there, or another setup ran its SQL after it.`,
24161
+ nonce_mismatch: "The database's newest PostgresAI setup is not this deploy's: its SQL did not run in this database, or a newer one ran after it (another deploy, or the Console), so monitoring does not start."
24162
24162
  };
24163
24163
  var utc = (iso) => {
24164
24164
  const d = new Date(iso);
@@ -24552,6 +24552,7 @@ async function privateLinkRole(url, db, opts, deps, progress, stop) {
24552
24552
  }
24553
24553
  };
24554
24554
  const resumeWith = (n) => opts.agent ? `call deploy_monitoring again with monitoring_password and nonce from this result` : `re-run with PGAI_MON_NONCE=${n} and PGAI_MON_PASSWORD set to the v_password value near the top of the SQL`;
24555
+ let away = false;
24555
24556
  if (password === undefined || nonce === undefined) {
24556
24557
  let p;
24557
24558
  try {
@@ -24573,12 +24574,13 @@ async function privateLinkRole(url, db, opts, deps, progress, stop) {
24573
24574
  }, (err) => err);
24574
24575
  if (failed) {
24575
24576
  const e = failed;
24576
- const refusedLogin = typeof e !== "object" || !e || !("severity" in e) || e.severity === "FATAL" || /^(28|3D|08)/.test(String(e.code ?? ""));
24577
+ away = unreachable(failed);
24578
+ const refusedLogin = !away && (typeof e !== "object" || !e || !("severity" in e) || e.severity === "FATAL" || /^(28|3D|08)/.test(String(e.code ?? "")));
24577
24579
  if (refusedLogin)
24578
- return stop(`Could not log in to ${maskConnectionString(inDatabase(url, db))}: ${errorText(failed)}. Check the URL's user and password, and run pgai mon deploy where the database is reachable (in its VPC)`);
24579
- const why = `The user in this URL (${decodeURIComponent(new URL(url).username)}) can't create ${DEFAULT_MONITORING_USER} (${errorText(failed)})`;
24580
+ return stop(`Could not log in to ${maskConnectionString(inDatabase(url, db))}: ${errorText(failed)}. Check the URL's user and password`);
24581
+ const why = away ? `This machine can't reach the database (${errorText(failed)}), so the SQL does not run from here` : `The user in this URL (${decodeURIComponent(new URL(url).username)}) can't create ${DEFAULT_MONITORING_USER} (${errorText(failed)})`;
24580
24582
  const printed = { step: "prepare_db", sql: p.prepare_db_sql, nonce, monitoring_password: password };
24581
- const run = `Run the SQL as the master user, connected to database ${db}`;
24583
+ const run = `Run the SQL as the master user, connected to database ${db}${away ? ", from a machine that reaches it (in its VPC)" : ""}`;
24582
24584
  const only = `A deploy of this database without ${opts.agent ? "them" : "PGAI_MON_PASSWORD and PGAI_MON_NONCE"} issues a new SQL and replaces this one`;
24583
24585
  if (!ask)
24584
24586
  return stop(`${why}. ${run}, then ${resumeWith(nonce)}. ${only}.`, printed);
@@ -24587,11 +24589,19 @@ async function privateLinkRole(url, db, opts, deps, progress, stop) {
24587
24589
  return stop(`Stopped. ${run}, then ${resumeWith(nonce)}.`, { ...printed, sql: undefined });
24588
24590
  }
24589
24591
  }
24592
+ const boxChecks = (why) => {
24593
+ progress("preparing", `Not checked from here (${why}): the monitoring box checks that ${DEFAULT_MONITORING_USER} logs in to ${db} and that this SQL ran, and deploy says if it fails`);
24594
+ return { password, nonce };
24595
+ };
24596
+ if (away)
24597
+ return boxChecks("this machine can't reach the database");
24590
24598
  progress("preparing", `Checking that ${DEFAULT_MONITORING_USER} can log in to ${db} with the password the SQL set`);
24591
24599
  let found;
24592
24600
  try {
24593
24601
  found = await deps.readNonce(roleUrl(url, db, password), warn);
24594
24602
  } catch (err) {
24603
+ if (unreachable(err))
24604
+ return boxChecks(`this machine can't reach the database: ${errorText(err)}`);
24595
24605
  const fresh = opts.agent ? "call again without monitoring_password and nonce for a new SQL" : "re-run without PGAI_MON_PASSWORD and PGAI_MON_NONCE for a new SQL";
24596
24606
  return stop(opts.monitoringPassword === undefined ? `${DEFAULT_MONITORING_USER} could not log in to ${db} with the password the SQL set (${errorText(err)}): run the SQL again, connected to database ${db}` : opts.agent ? `${DEFAULT_MONITORING_USER} could not log in to ${db} with monitoring_password (${errorText(err)}): pass the monitoring_password of the prepare_db result whose SQL ran, or ${fresh}` : `${DEFAULT_MONITORING_USER} could not log in to ${db} with PGAI_MON_PASSWORD (${errorText(err)}): set it to the v_password value near the top of the SQL you ran, or ${fresh}`);
24597
24607
  }
@@ -24611,6 +24621,12 @@ var STOPPED_LOOKING = `${STILL_IN_PROGRESS}: deploy stopped watching before Post
24611
24621
  var NOT_CONFIRMED_AGENT = "PostgresAI did not confirm the monitoring box yet. Call deploy_monitoring again in a minute: it continues with the box if PostgresAI created it. If pgai mon instances list still has no box for this database, ask the user to run pgai mon deploy with --reset-password in a terminal";
24612
24622
  var LOOKUP_MS = 5 * 60000;
24613
24623
  var AGENT_RUN_MS = 50000;
24624
+ function unreachable(err) {
24625
+ if (typeof err !== "object" || !err || "severity" in err)
24626
+ return false;
24627
+ const codes = [err.code, ...(err.errors ?? []).map((e) => e?.code)];
24628
+ return codes.some((c) => ["ECONNREFUSED", "ENOTFOUND", "EAI_AGAIN", "ENETUNREACH", "EHOSTUNREACH", "ETIMEDOUT", "ECONNRESET"].includes(String(c))) || /connection timeout|timeout expired/i.test(err instanceof Error ? err.message : "");
24629
+ }
24614
24630
  function mayHaveRun(err) {
24615
24631
  if (err instanceof HttpRequestTimeoutError)
24616
24632
  return true;
@@ -32339,7 +32355,7 @@ async function startMcpServer(rootOpts, extra) {
32339
32355
  },
32340
32356
  {
32341
32357
  name: "deploy_monitoring",
32342
- description: "Put a Postgres database under PostgresAI Cloud monitoring (same as `pgai mon deploy`): prepares the monitoring role (an admin URL creates it; otherwise returns the SQL), provisions the monitoring box, and returns JSON with status (ready | in_progress | deleting | deleted | inactive | action_required | failed: the same words as pgai dblab deploy), health_url (the project's Health Matrix in the console), dashboard_url (Grafana, signing in with PostgresAI) and next (the exact next action). A billed box is provisioned only with yes: true: without it the result is action_required with the price (and requires_payment_method), so show the price to the user first. It does not wait for the box: call it again to see the status. Safe to call again. When PostgresAI can't reach the database the way an IP allowlist refuses (or with ip_first), the box's IP is reserved first and the result is action_required with step allow_ip (ip, cidr, host, port, reserved_until): give the user the cidr and port to allow on the database, then call again with ip_allowed: true. ClickHouse Managed Postgres, RDS and Supabase are detected from the host. An RDS instance that is not publicly accessible is monitored over AWS PrivateLink (no public IP, nothing opened): the user creates a CloudFormation stack in their AWS account from a link. Until the stack exists the result is action_required with step privatelink_stack and cfn_url: give the user the link to open in the RDS's AWS account (the stack keeps its name); once they say it is created, call again. When this machine's aws CLI can read the RDS (read-only; aws_profile picks the profile, no_aws: true skips it), the link is filled in and the stack is found by itself; otherwise pass vpce_service, the stack's VpceServiceName output. When the URL's user can't create the monitoring role, the result is action_required with step prepare_db, sql, nonce and monitoring_password: the user runs the SQL as the master user in that database, then call again with monitoring_password and nonce. host_stats: true adds host CPU, memory, disk and IOPS through a read-only role the stack creates (host_stats_role: its HostStatsRoleArn output, when not read from AWS). Aurora and RDS Proxy endpoints are not supported over PrivateLink. Supabase needs no password (PostgresAI prepares the database through the Supabase Management API): the first time, the result is action_required with a consent link in next; give it to the user to open and approve, then call again. Elsewhere the URL must carry its password, and only these query parameters: sslmode, channel_binding, application_name. PGAI_MON_PASSWORD, PGPASSWORD and CLICKHOUSE_KEY_ID + CLICKHOUSE_KEY_SECRET of the server process are not used (pass clickhouse_key), and a TLS failure is not retried in plaintext (say sslmode=disable for a server without TLS). For another database on a server PostgresAI already monitors for the org, an admin URL with sslmode=require (or verify-*), each query parameter once, is enough: PostgresAI fills in the password of postgres_ai_mon it keeps, over TLS only (on a server without TLS, pass the postgres_ai_mon URL; if nobody has its password, the user runs in a terminal: pgai mon instances delete the server's other databases, then pgai mon deploy <admin-url> --reset-password with PGAI_MON_PASSWORD set to a new one, then deploys them again with it).",
32358
+ description: "Put a Postgres database under PostgresAI Cloud monitoring (same as `pgai mon deploy`): prepares the monitoring role (an admin URL creates it; otherwise returns the SQL), provisions the monitoring box, and returns JSON with status (ready | in_progress | deleting | deleted | inactive | action_required | failed: the same words as pgai dblab deploy), health_url (the project's Health Matrix in the console), dashboard_url (Grafana, signing in with PostgresAI) and next (the exact next action). A billed box is provisioned only with yes: true: without it the result is action_required with the price (and requires_payment_method), so show the price to the user first. It does not wait for the box: call it again to see the status. Safe to call again. When PostgresAI can't reach the database the way an IP allowlist refuses (or with ip_first), the box's IP is reserved first and the result is action_required with step allow_ip (ip, cidr, host, port, reserved_until): give the user the cidr and port to allow on the database, then call again with ip_allowed: true. ClickHouse Managed Postgres, RDS and Supabase are detected from the host. An RDS instance that is not publicly accessible is monitored over AWS PrivateLink (no public IP, nothing opened): the user creates a CloudFormation stack in their AWS account from a link. Until the stack exists the result is action_required with step privatelink_stack and cfn_url: give the user the link to open in the RDS's AWS account (the stack keeps its name); once they say it is created, call again. When this machine's aws CLI can read the RDS (read-only; aws_profile picks the profile, no_aws: true skips it), the link is filled in and the stack is found by itself; otherwise pass vpce_service, the stack's VpceServiceName output. When the URL's user can't create the monitoring role, or this machine can't reach the database (a private RDS seen from outside its VPC), the result is action_required with step prepare_db, sql, nonce and monitoring_password: the user runs the SQL as the master user in that database, then call again with monitoring_password and nonce. host_stats: true adds host CPU, memory, disk and IOPS through a read-only role the stack creates (host_stats_role: its HostStatsRoleArn output, when not read from AWS). Aurora and RDS Proxy endpoints are not supported over PrivateLink. Supabase needs no password (PostgresAI prepares the database through the Supabase Management API): the first time, the result is action_required with a consent link in next; give it to the user to open and approve, then call again. Elsewhere the URL must carry its password, and only these query parameters: sslmode, channel_binding, application_name. PGAI_MON_PASSWORD, PGPASSWORD and CLICKHOUSE_KEY_ID + CLICKHOUSE_KEY_SECRET of the server process are not used (pass clickhouse_key), and a TLS failure is not retried in plaintext (say sslmode=disable for a server without TLS). For another database on a server PostgresAI already monitors for the org, an admin URL with sslmode=require (or verify-*), each query parameter once, is enough: PostgresAI fills in the password of postgres_ai_mon it keeps, over TLS only (on a server without TLS, pass the postgres_ai_mon URL; if nobody has its password, the user runs in a terminal: pgai mon instances delete the server's other databases, then pgai mon deploy <admin-url> --reset-password with PGAI_MON_PASSWORD set to a new one, then deploys them again with it).",
32343
32359
  inputSchema: {
32344
32360
  type: "object",
32345
32361
  properties: {
@@ -34562,8 +34578,8 @@ async function readAws2(ep, opts, deps, progress) {
34562
34578
  }
34563
34579
  var VERIFY_FAILED2 = {
34564
34580
  unreachable: "The monitoring box could not reach the database over PrivateLink: check that the stack finished, its load balancer's target is healthy, and the RDS is not publicly accessible.",
34565
- auth_failed: `The monitoring box reached the database, but ${DEFAULT_MONITORING_USER} could not log in: its password changed after this deploy set it (another setup ran its SQL).`,
34566
- nonce_mismatch: "A newer PostgresAI setup SQL ran in this database after this deploy's (another deploy, or the Console), so monitoring does not start."
34581
+ auth_failed: `The monitoring box reached the database, but ${DEFAULT_MONITORING_USER} could not log in with the password this deploy's SQL set: the SQL did not run there, or another setup ran its SQL after it.`,
34582
+ nonce_mismatch: "The database's newest PostgresAI setup is not this deploy's: its SQL did not run in this database, or a newer one ran after it (another deploy, or the Console), so monitoring does not start."
34567
34583
  };
34568
34584
  async function privateLinkOf(d, rdsStatus) {
34569
34585
  if (!rdsStatus || disconnecting2(d.status))
@@ -34976,6 +34992,7 @@ async function privateLinkRole2(url, db, opts, deps, progress, stop) {
34976
34992
  }
34977
34993
  };
34978
34994
  const resumeWith = (n) => opts.agent ? `call deploy_monitoring again with monitoring_password and nonce from this result` : `re-run with PGAI_MON_NONCE=${n} and PGAI_MON_PASSWORD set to the v_password value near the top of the SQL`;
34995
+ let away = false;
34979
34996
  if (password === undefined || nonce === undefined) {
34980
34997
  let p;
34981
34998
  try {
@@ -34997,12 +35014,13 @@ async function privateLinkRole2(url, db, opts, deps, progress, stop) {
34997
35014
  }, (err) => err);
34998
35015
  if (failed) {
34999
35016
  const e = failed;
35000
- const refusedLogin = typeof e !== "object" || !e || !("severity" in e) || e.severity === "FATAL" || /^(28|3D|08)/.test(String(e.code ?? ""));
35017
+ away = unreachable2(failed);
35018
+ const refusedLogin = !away && (typeof e !== "object" || !e || !("severity" in e) || e.severity === "FATAL" || /^(28|3D|08)/.test(String(e.code ?? "")));
35001
35019
  if (refusedLogin)
35002
- return stop(`Could not log in to ${maskConnectionString(inDatabase2(url, db))}: ${errorText2(failed)}. Check the URL's user and password, and run pgai mon deploy where the database is reachable (in its VPC)`);
35003
- const why = `The user in this URL (${decodeURIComponent(new URL(url).username)}) can't create ${DEFAULT_MONITORING_USER} (${errorText2(failed)})`;
35020
+ return stop(`Could not log in to ${maskConnectionString(inDatabase2(url, db))}: ${errorText2(failed)}. Check the URL's user and password`);
35021
+ const why = away ? `This machine can't reach the database (${errorText2(failed)}), so the SQL does not run from here` : `The user in this URL (${decodeURIComponent(new URL(url).username)}) can't create ${DEFAULT_MONITORING_USER} (${errorText2(failed)})`;
35004
35022
  const printed = { step: "prepare_db", sql: p.prepare_db_sql, nonce, monitoring_password: password };
35005
- const run = `Run the SQL as the master user, connected to database ${db}`;
35023
+ const run = `Run the SQL as the master user, connected to database ${db}${away ? ", from a machine that reaches it (in its VPC)" : ""}`;
35006
35024
  const only = `A deploy of this database without ${opts.agent ? "them" : "PGAI_MON_PASSWORD and PGAI_MON_NONCE"} issues a new SQL and replaces this one`;
35007
35025
  if (!ask)
35008
35026
  return stop(`${why}. ${run}, then ${resumeWith(nonce)}. ${only}.`, printed);
@@ -35011,11 +35029,19 @@ async function privateLinkRole2(url, db, opts, deps, progress, stop) {
35011
35029
  return stop(`Stopped. ${run}, then ${resumeWith(nonce)}.`, { ...printed, sql: undefined });
35012
35030
  }
35013
35031
  }
35032
+ const boxChecks = (why) => {
35033
+ progress("preparing", `Not checked from here (${why}): the monitoring box checks that ${DEFAULT_MONITORING_USER} logs in to ${db} and that this SQL ran, and deploy says if it fails`);
35034
+ return { password, nonce };
35035
+ };
35036
+ if (away)
35037
+ return boxChecks("this machine can't reach the database");
35014
35038
  progress("preparing", `Checking that ${DEFAULT_MONITORING_USER} can log in to ${db} with the password the SQL set`);
35015
35039
  let found;
35016
35040
  try {
35017
35041
  found = await deps.readNonce(roleUrl2(url, db, password), warn);
35018
35042
  } catch (err) {
35043
+ if (unreachable2(err))
35044
+ return boxChecks(`this machine can't reach the database: ${errorText2(err)}`);
35019
35045
  const fresh = opts.agent ? "call again without monitoring_password and nonce for a new SQL" : "re-run without PGAI_MON_PASSWORD and PGAI_MON_NONCE for a new SQL";
35020
35046
  return stop(opts.monitoringPassword === undefined ? `${DEFAULT_MONITORING_USER} could not log in to ${db} with the password the SQL set (${errorText2(err)}): run the SQL again, connected to database ${db}` : opts.agent ? `${DEFAULT_MONITORING_USER} could not log in to ${db} with monitoring_password (${errorText2(err)}): pass the monitoring_password of the prepare_db result whose SQL ran, or ${fresh}` : `${DEFAULT_MONITORING_USER} could not log in to ${db} with PGAI_MON_PASSWORD (${errorText2(err)}): set it to the v_password value near the top of the SQL you ran, or ${fresh}`);
35021
35047
  }
@@ -35035,6 +35061,12 @@ var STOPPED_LOOKING2 = `${STILL_IN_PROGRESS2}: deploy stopped watching before Po
35035
35061
  var NOT_CONFIRMED_AGENT2 = "PostgresAI did not confirm the monitoring box yet. Call deploy_monitoring again in a minute: it continues with the box if PostgresAI created it. If pgai mon instances list still has no box for this database, ask the user to run pgai mon deploy with --reset-password in a terminal";
35036
35062
  var LOOKUP_MS2 = 5 * 60000;
35037
35063
  var AGENT_RUN_MS2 = 50000;
35064
+ function unreachable2(err) {
35065
+ if (typeof err !== "object" || !err || "severity" in err)
35066
+ return false;
35067
+ const codes = [err.code, ...(err.errors ?? []).map((e) => e?.code)];
35068
+ return codes.some((c) => ["ECONNREFUSED", "ENOTFOUND", "EAI_AGAIN", "ENETUNREACH", "EHOSTUNREACH", "ETIMEDOUT", "ECONNRESET"].includes(String(c))) || /connection timeout|timeout expired/i.test(err instanceof Error ? err.message : "");
35069
+ }
35038
35070
  function mayHaveRun2(err) {
35039
35071
  if (err instanceof HttpRequestTimeoutError)
35040
35072
  return true;
@@ -49540,7 +49572,8 @@ sharedDeployOptions2(withOrgOptions(mon.command("deploy")), 20, "instance name (
49540
49572
  "up to 90 minutes, then is removed and the IP kept: allow it and re-run with --ip-allowed.",
49541
49573
  "",
49542
49574
  "Amazon RDS that is not publicly accessible: over AWS PrivateLink (nothing becomes public, no",
49543
- "port is opened). Run deploy where the database is reachable (in its VPC). It reads the instance",
49575
+ "port is opened). Run deploy anywhere (where it can't reach the database, it prints the setup SQL",
49576
+ "to run where the database is reachable, and the box checks it). It reads the instance",
49544
49577
  "with the aws CLI when it can (read-only: the profile it uses is printed; --aws-profile picks one,",
49545
49578
  "--no-aws skips it), else asks public DNS; --privatelink / --no-privatelink decide instead. Then:",
49546
49579
  "the price, a CloudFormation link that creates the stack in your AWS account (filled in with what",
@@ -49549,7 +49582,7 @@ sharedDeployOptions2(withOrgOptions(mon.command("deploy")), 20, "instance name (
49549
49582
  "its RDS; with several, you pick one), or without AWS asks for its VpceServiceName;",
49550
49583
  'elsewhere it stops (exit 3, "step":"privatelink_stack" with cfn_url): create the stack,',
49551
49584
  "then re-run (with --vpce-service <VpceServiceName> when AWS is not read here). When the URL's",
49552
- `user can't create the role, the SQL is printed ("step":"prepare_db" with sql, nonce,`,
49585
+ `user can't create the role, or this machine can't reach the database, the SQL is printed ("step":"prepare_db" with sql, nonce,`,
49553
49586
  "monitoring_password): run it as the master user in that database, then re-run with",
49554
49587
  "PGAI_MON_PASSWORD and PGAI_MON_NONCE set to those two. Aurora and RDS Proxy: not over PrivateLink.",
49555
49588
  "Any database can also be monitored from this machine with --self-hosted.",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "postgresai",
3
- "version": "0.18.0-dev.17",
3
+ "version": "0.18.0-dev.18",
4
4
  "description": "postgres_ai CLI",
5
5
  "license": "Apache-2.0",
6
6
  "private": false,