postgresai 0.11.0-alpha.8 → 0.12.0-alpha.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/lib/util.ts ADDED
@@ -0,0 +1,60 @@
1
+ export function maskSecret(secret: string): string {
2
+ if (!secret) return "";
3
+ if (secret.length <= 8) return "****";
4
+ if (secret.length <= 16) return `${secret.slice(0, 4)}${"*".repeat(secret.length - 8)}${secret.slice(-4)}`;
5
+ return `${secret.slice(0, Math.min(12, secret.length - 8))}${"*".repeat(Math.max(4, secret.length - 16))}${secret.slice(-4)}`;
6
+ }
7
+
8
+
9
+ export interface RootOptsLike {
10
+ apiBaseUrl?: string;
11
+ uiBaseUrl?: string;
12
+ }
13
+
14
+ export interface ConfigLike {
15
+ baseUrl?: string | null;
16
+ }
17
+
18
+ export interface ResolvedBaseUrls {
19
+ apiBaseUrl: string;
20
+ uiBaseUrl: string;
21
+ }
22
+
23
+ /**
24
+ * Normalize a base URL by trimming a single trailing slash and validating.
25
+ * @throws Error if the URL is invalid
26
+ */
27
+ export function normalizeBaseUrl(value: string): string {
28
+ const trimmed = (value || "").replace(/\/$/, "");
29
+ try {
30
+ // Validate
31
+ // eslint-disable-next-line no-new
32
+ new URL(trimmed);
33
+ } catch {
34
+ throw new Error(`Invalid base URL: ${value}`);
35
+ }
36
+ return trimmed;
37
+ }
38
+
39
+ /**
40
+ * Resolve API and UI base URLs using precedence and normalize them.
41
+ * Precedence (API): opts.apiBaseUrl → env.PGAI_API_BASE_URL → cfg.baseUrl → default
42
+ * Precedence (UI): opts.uiBaseUrl → env.PGAI_UI_BASE_URL → default
43
+ */
44
+ export function resolveBaseUrls(
45
+ opts?: RootOptsLike,
46
+ cfg?: ConfigLike,
47
+ defaults: { apiBaseUrl?: string; uiBaseUrl?: string } = {}
48
+ ): ResolvedBaseUrls {
49
+ const defApi = defaults.apiBaseUrl || "https://postgres.ai/api/general/";
50
+ const defUi = defaults.uiBaseUrl || "https://console.postgres.ai";
51
+
52
+ const apiCandidate = (opts?.apiBaseUrl || process.env.PGAI_API_BASE_URL || cfg?.baseUrl || defApi) as string;
53
+ const uiCandidate = (opts?.uiBaseUrl || process.env.PGAI_UI_BASE_URL || defUi) as string;
54
+
55
+ return {
56
+ apiBaseUrl: normalizeBaseUrl(apiCandidate),
57
+ uiBaseUrl: normalizeBaseUrl(uiCandidate),
58
+ };
59
+ }
60
+
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "postgresai",
3
- "version": "0.11.0-alpha.8",
4
- "description": "PostgresAI CLI (Node.js)",
5
- "license": "MIT",
3
+ "version": "0.12.0-alpha.13",
4
+ "description": "postgres_ai CLI (Node.js)",
5
+ "license": "Apache-2.0",
6
6
  "private": false,
7
7
  "repository": {
8
8
  "type": "git",
@@ -13,23 +13,31 @@
13
13
  "url": "https://gitlab.com/postgres-ai/postgres_ai/-/issues"
14
14
  },
15
15
  "bin": {
16
- "postgres-ai": "./bin/postgres-ai.js",
17
- "postgresai": "./bin/postgres-ai.js",
18
- "pgai": "./bin/postgres-ai.js"
16
+ "postgres-ai": "./dist/bin/postgres-ai.js",
17
+ "postgresai": "./dist/bin/postgres-ai.js",
18
+ "pgai": "./dist/bin/postgres-ai.js"
19
19
  },
20
20
  "type": "commonjs",
21
21
  "engines": {
22
22
  "node": ">=18"
23
23
  },
24
24
  "scripts": {
25
- "start": "node ./bin/postgres-ai.js --help"
25
+ "build": "tsc",
26
+ "prepare": "npm run build",
27
+ "start": "node ./dist/bin/postgres-ai.js --help",
28
+ "dev": "tsc --watch"
26
29
  },
27
30
  "dependencies": {
28
- "commander": "^12.1.0"
31
+ "commander": "^12.1.0",
32
+ "js-yaml": "^4.1.0",
33
+ "@modelcontextprotocol/sdk": "^1.20.2"
34
+ },
35
+ "devDependencies": {
36
+ "@types/js-yaml": "^4.0.9",
37
+ "@types/node": "^18.19.0",
38
+ "typescript": "^5.3.3"
29
39
  },
30
40
  "publishConfig": {
31
41
  "access": "public"
32
42
  }
33
43
  }
34
-
35
-
package/tsconfig.json ADDED
@@ -0,0 +1,28 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2020",
4
+ "module": "node16",
5
+ "lib": ["ES2020"],
6
+ "outDir": "./dist",
7
+ "rootDir": "./",
8
+ "strict": true,
9
+ "esModuleInterop": true,
10
+ "skipLibCheck": true,
11
+ "forceConsistentCasingInFileNames": true,
12
+ "resolveJsonModule": true,
13
+ "declaration": true,
14
+ "declarationMap": true,
15
+ "sourceMap": true,
16
+ "moduleResolution": "node16",
17
+ "types": ["node"]
18
+ },
19
+ "include": [
20
+ "bin/**/*",
21
+ "lib/**/*"
22
+ ],
23
+ "exclude": [
24
+ "node_modules",
25
+ "dist"
26
+ ]
27
+ }
28
+