@promptbook/cli 0.112.0-89 → 0.112.0-91

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/src/version.ts CHANGED
@@ -16,11 +16,11 @@ export const BOOK_LANGUAGE_VERSION: string_semantic_version = '2.0.0';
16
16
  * @generated
17
17
  * @see https://github.com/webgptorg/promptbook
18
18
  */
19
- export const PROMPTBOOK_ENGINE_VERSION: string_promptbook_version = '0.112.0-89';
19
+ export const PROMPTBOOK_ENGINE_VERSION: string_promptbook_version = '0.112.0-91';
20
20
 
21
21
  /**
22
22
  * Represents the version string of the Promptbook engine.
23
- * It follows semantic versioning (e.g., `0.112.0-88`).
23
+ * It follows semantic versioning (e.g., `0.112.0-90`).
24
24
  *
25
25
  * @generated
26
26
  */
package/src/versions.txt CHANGED
@@ -1126,3 +1126,5 @@
1126
1126
  0.112.0-82
1127
1127
  0.112.0-88
1128
1128
  0.112.0-89
1129
+ 0.112.0-90
1130
+ 0.112.0-91
@@ -65,6 +65,12 @@ export declare function listRegisteredServers(supabase: Pick<SupabaseClient, 'fr
65
65
  export declare function listRegisteredServersUsingServiceRole(options?: {
66
66
  readonly forceRefresh?: boolean;
67
67
  }): Promise<Array<ServerRecord>>;
68
+ /**
69
+ * Loads virtual server records from the comma-separated `SERVERS` environment variable.
70
+ *
71
+ * @returns Server records with deterministic table prefixes derived from normalized domains.
72
+ */
73
+ export declare function listEnvironmentRegisteredServers(): Array<ServerRecord>;
68
74
  /**
69
75
  * Finds one registered server by incoming host header.
70
76
  *
package/umd/index.umd.js CHANGED
@@ -60,7 +60,7 @@
60
60
  * @generated
61
61
  * @see https://github.com/webgptorg/promptbook
62
62
  */
63
- const PROMPTBOOK_ENGINE_VERSION = '0.112.0-89';
63
+ const PROMPTBOOK_ENGINE_VERSION = '0.112.0-91';
64
64
  /**
65
65
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
66
66
  * Note: [💞] Ignore a discrepancy between file name and entity name
@@ -36108,6 +36108,12 @@
36108
36108
  * @private internal constant of `ptbk agents-server`
36109
36109
  */
36110
36110
  const PTBK_AGENTS_SERVER_SQLITE_PATH_ENV = 'PTBK_AGENTS_SERVER_SQLITE_PATH';
36111
+ /**
36112
+ * Optional hostname used by the internal Next server.
36113
+ *
36114
+ * @private internal constant of `ptbk agents-server`
36115
+ */
36116
+ const PTBK_HOSTNAME_ENV = 'PTBK_HOSTNAME';
36111
36117
  /**
36112
36118
  * Entropy size for the local-only token shared by the CLI pump and the Next app.
36113
36119
  *
@@ -36226,8 +36232,15 @@
36226
36232
  * Starts the production Next server and wires its logs into the foreground dashboard.
36227
36233
  */
36228
36234
  function startNextServer(options) {
36235
+ var _a;
36229
36236
  logRunnerEvent(options.logStreams.runner, 'Starting the Agents Server Next process.');
36230
- const commandProcess = child_process.spawn(process.execPath, [options.nextCliPath, 'start', '--port', String(options.options.port)], {
36237
+ const nextArguments = [options.nextCliPath, 'start', '--port', String(options.options.port)];
36238
+ const hostname = (_a = options.childEnvironment[PTBK_HOSTNAME_ENV]) === null || _a === void 0 ? void 0 : _a.trim();
36239
+ if (hostname) {
36240
+ nextArguments.push('--hostname', hostname);
36241
+ logRunnerEvent(options.logStreams.runner, `Binding Agents Server Next process to ${hostname}.`);
36242
+ }
36243
+ const commandProcess = child_process.spawn(process.execPath, nextArguments, {
36231
36244
  cwd: options.runtimePaths.appPath,
36232
36245
  env: options.childEnvironment,
36233
36246
  stdio: ['ignore', 'pipe', 'pipe'],
@@ -67592,6 +67605,38 @@
67592
67605
  * Global source-of-truth table for server routing and migration targeting.
67593
67606
  */
67594
67607
  const SERVER_REGISTRY_TABLE_NAME = '_Server';
67608
+ /**
67609
+ * Environment variable with comma-separated standalone server domains.
67610
+ */
67611
+ const SERVERS_ENV_NAME = 'SERVERS';
67612
+ /**
67613
+ * Stable timestamp used by virtual server records derived from environment variables.
67614
+ */
67615
+ const ENVIRONMENT_SERVER_TIMESTAMP = '1970-01-01T00:00:00.000Z';
67616
+ /**
67617
+ * Loads virtual server records from the comma-separated `SERVERS` environment variable.
67618
+ *
67619
+ * @returns Server records with deterministic table prefixes derived from normalized domains.
67620
+ */
67621
+ function listEnvironmentRegisteredServers() {
67622
+ const rawServers = process.env[SERVERS_ENV_NAME];
67623
+ if (!rawServers) {
67624
+ return [];
67625
+ }
67626
+ const normalizedDomains = uniqueStrings$1(rawServers
67627
+ .split(',')
67628
+ .map((server) => normalizeServerDomain(server))
67629
+ .filter((server) => Boolean(server)));
67630
+ return normalizedDomains.map((domain, index) => ({
67631
+ id: -(index + 1),
67632
+ name: domain,
67633
+ environment: SERVER_ENVIRONMENT.PRODUCTION,
67634
+ domain,
67635
+ tablePrefix: buildEnvironmentServerTablePrefix(domain),
67636
+ createdAt: ENVIRONMENT_SERVER_TIMESTAMP,
67637
+ updatedAt: ENVIRONMENT_SERVER_TIMESTAMP,
67638
+ }));
67639
+ }
67595
67640
  /**
67596
67641
  * Normalizes one raw `_Server` row and validates required fields.
67597
67642
  *
@@ -67712,6 +67757,39 @@
67712
67757
  function isDefaultPortForProtocol(protocol, port) {
67713
67758
  return (protocol === 'http:' && port === '80') || (protocol === 'https:' && port === '443');
67714
67759
  }
67760
+ /**
67761
+ * Builds a deterministic table prefix from a normalized domain.
67762
+ *
67763
+ * @param domain - Normalized server domain.
67764
+ * @returns Prefix such as `server_www_example_com_`.
67765
+ */
67766
+ function buildEnvironmentServerTablePrefix(domain) {
67767
+ const prefixSuffix = domain
67768
+ .toLowerCase()
67769
+ .replace(/-/gu, '_dash_')
67770
+ .replace(/\./gu, '_')
67771
+ .replace(/:/gu, '_port_')
67772
+ .replace(/[^a-z0-9_]/gu, '_')
67773
+ .replace(/_+/gu, '_')
67774
+ .replace(/^_+|_+$/gu, '');
67775
+ return `server_${prefixSuffix}_`;
67776
+ }
67777
+ /**
67778
+ * Deduplicates non-empty strings while preserving input order.
67779
+ *
67780
+ * @param values - Raw string values.
67781
+ * @returns Unique non-empty strings.
67782
+ */
67783
+ function uniqueStrings$1(values) {
67784
+ const uniqueValues = [];
67785
+ for (const value of values) {
67786
+ if (!value || uniqueValues.includes(value)) {
67787
+ continue;
67788
+ }
67789
+ uniqueValues.push(value);
67790
+ }
67791
+ return uniqueValues;
67792
+ }
67715
67793
 
67716
67794
  /**
67717
67795
  * SQL query used to load all registered servers in a deterministic order.
@@ -68070,7 +68148,7 @@
68070
68148
  const client = await createPostgresClient(connectionString);
68071
68149
  try {
68072
68150
  await client.connect();
68073
- const registeredServers = await listRegisteredServersFromDatabase(client);
68151
+ const registeredServers = mergeRegisteredServers(await listRegisteredServersFromDatabase(client), listEnvironmentRegisteredServers());
68074
68152
  const hasExplicitDefaultPrefix = process.env[SUPABASE_TABLE_PREFIX_ENV_NAME] !== undefined;
68075
68153
  const configuredPrefixes = uniquePrefixes([
68076
68154
  ...(hasExplicitDefaultPrefix
@@ -68231,6 +68309,25 @@
68231
68309
  }
68232
68310
  return result;
68233
68311
  }
68312
+ /**
68313
+ * Combines database and environment registry rows, keeping database rows authoritative.
68314
+ *
68315
+ * @param databaseServers - Persistent `_Server` rows.
68316
+ * @param environmentServers - Virtual rows derived from `SERVERS`.
68317
+ * @returns Merged rows without duplicate domains.
68318
+ */
68319
+ function mergeRegisteredServers(databaseServers, environmentServers) {
68320
+ const seenDomains = new Set(databaseServers.map((server) => server.domain));
68321
+ const mergedServers = [...databaseServers];
68322
+ for (const environmentServer of environmentServers) {
68323
+ if (seenDomains.has(environmentServer.domain)) {
68324
+ continue;
68325
+ }
68326
+ mergedServers.push(environmentServer);
68327
+ seenDomains.add(environmentServer.domain);
68328
+ }
68329
+ return mergedServers;
68330
+ }
68234
68331
  /**
68235
68332
  * Creates one PostgreSQL client using the lazily loaded `pg` package.
68236
68333
  *