@promptbook/core 0.112.0-110 → 0.112.0-112

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/esm/index.es.js CHANGED
@@ -28,7 +28,7 @@ const BOOK_LANGUAGE_VERSION = '2.0.0';
28
28
  * @generated
29
29
  * @see https://github.com/webgptorg/promptbook
30
30
  */
31
- const PROMPTBOOK_ENGINE_VERSION = '0.112.0-110';
31
+ const PROMPTBOOK_ENGINE_VERSION = '0.112.0-112';
32
32
  /**
33
33
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
34
34
  * Note: [💞] Ignore a discrepancy between file name and entity name
@@ -29360,6 +29360,18 @@ function normalizeHistoryVersionName(versionName) {
29360
29360
  const normalizedVersionName = versionName.trim();
29361
29361
  return normalizedVersionName.length > 0 ? normalizedVersionName : null;
29362
29362
  }
29363
+ /**
29364
+ * Builds a Supabase `.or()` filter for agent name or permanent id lookups.
29365
+ *
29366
+ * @param agentNameOrPermanentId - Agent name or stable permanent identifier to match.
29367
+ * @returns `.or()` filter string safe to pass to Supabase.
29368
+ *
29369
+ * @private internal helper of `AgentCollectionInSupabase`
29370
+ */
29371
+ function buildAgentNameOrPermanentIdFilter(agentNameOrPermanentId) {
29372
+ const encodedAgentIdentifier = encodeURIComponent(agentNameOrPermanentId);
29373
+ return `agentName.eq.${encodedAgentIdentifier},permanentId.eq.${encodedAgentIdentifier}`;
29374
+ }
29363
29375
  /**
29364
29376
  * Agent collection stored in a Supabase table.
29365
29377
  *
@@ -29407,21 +29419,63 @@ class AgentCollectionInSupabase /* TODO: [🌈][🐱‍🚀] implements AgentCol
29407
29419
  if (isVerbose) {
29408
29420
  console.info(`Found ${selectResult.data.length} agents in directory`);
29409
29421
  }
29410
- return selectResult.data.map(({ agentName, agentProfile, permanentId }) => {
29411
- if (isVerbose && agentProfile.agentName !== agentName) {
29412
- console.warn(spaceTrim(`
29422
+ return selectResult.data.map((row) => this.mapAgentBasicInformationRow(row, isVerbose));
29423
+ }
29424
+ /**
29425
+ * Finds one active agent profile by its human-readable name or permanent id.
29426
+ *
29427
+ * This keeps route-level lookups from loading the whole agent collection when only
29428
+ * one canonical route identifier is needed.
29429
+ *
29430
+ * @param agentNameOrPermanentId - Agent name or stable permanent identifier.
29431
+ * @returns Matching active agent profile or `null` when not found.
29432
+ *
29433
+ * @public exported from `@promptbook/core`
29434
+ */
29435
+ async findAgentBasicInformation(agentNameOrPermanentId) {
29436
+ var _a;
29437
+ const { isVerbose = DEFAULT_IS_VERBOSE } = this.options || {};
29438
+ const selectResult = await this.supabaseClient
29439
+ .from(this.getTableName('Agent'))
29440
+ .select('agentName,agentProfile,permanentId')
29441
+ .or(buildAgentNameOrPermanentIdFilter(agentNameOrPermanentId))
29442
+ .is('deletedAt', null)
29443
+ .order('createdAt', { ascending: true })
29444
+ .limit(1);
29445
+ if (selectResult.error) {
29446
+ throw new DatabaseError(spaceTrim((block) => `
29447
+
29448
+ Error fetching agent "${agentNameOrPermanentId}" from Supabase:
29449
+
29450
+ ${block(selectResult.error.message)}
29451
+ `));
29452
+ }
29453
+ const row = (_a = selectResult.data) === null || _a === void 0 ? void 0 : _a[0];
29454
+ return row ? this.mapAgentBasicInformationRow(row, isVerbose) : null;
29455
+ }
29456
+ /**
29457
+ * Converts one database row into public agent information.
29458
+ *
29459
+ * @param row - Database row carrying the persisted profile snapshot.
29460
+ * @param isVerbose - Whether profile-name mismatches should be logged.
29461
+ * @returns Agent profile with canonical database name and permanent id.
29462
+ *
29463
+ * @private internal helper of `AgentCollectionInSupabase`
29464
+ */
29465
+ mapAgentBasicInformationRow({ agentName, agentProfile, permanentId }, isVerbose) {
29466
+ if (isVerbose && agentProfile.agentName !== agentName) {
29467
+ console.warn(spaceTrim(`
29413
29468
  Agent name mismatch for agent "${agentName}". Using name from database.
29414
29469
 
29415
29470
  agentName: "${agentName}"
29416
29471
  agentProfile.agentName: "${agentProfile.agentName}"
29417
29472
  `));
29418
- }
29419
- return {
29420
- ...agentProfile,
29421
- agentName,
29422
- permanentId: permanentId || agentProfile.permanentId,
29423
- };
29424
- });
29473
+ }
29474
+ return {
29475
+ ...agentProfile,
29476
+ agentName,
29477
+ permanentId: permanentId || agentProfile.permanentId,
29478
+ };
29425
29479
  }
29426
29480
  /**
29427
29481
  * Retrieves the permanent ID of an agent by its name or permanent ID.
@@ -29430,7 +29484,7 @@ class AgentCollectionInSupabase /* TODO: [🌈][🐱‍🚀] implements AgentCol
29430
29484
  const selectResult = await this.supabaseClient
29431
29485
  .from(this.getTableName('Agent'))
29432
29486
  .select('permanentId')
29433
- .or(`agentName.eq.${agentNameOrPermanentId},permanentId.eq.${agentNameOrPermanentId}`)
29487
+ .or(buildAgentNameOrPermanentIdFilter(agentNameOrPermanentId))
29434
29488
  .order('createdAt', { ascending: true }) // Pick oldest if multiple match by name
29435
29489
  .limit(1);
29436
29490
  if (selectResult.error || !selectResult.data || selectResult.data.length === 0) {
@@ -29445,7 +29499,7 @@ class AgentCollectionInSupabase /* TODO: [🌈][🐱‍🚀] implements AgentCol
29445
29499
  const selectResult = await this.supabaseClient
29446
29500
  .from(this.getTableName('Agent'))
29447
29501
  .select('agentSource')
29448
- .or(`agentName.eq.${agentNameOrPermanentId},permanentId.eq.${agentNameOrPermanentId}`)
29502
+ .or(buildAgentNameOrPermanentIdFilter(agentNameOrPermanentId))
29449
29503
  .is('deletedAt', null)
29450
29504
  .order('createdAt', { ascending: true }) // Pick oldest if multiple match by name
29451
29505
  .limit(1);