@promptbook/core 0.112.0-41 → 0.112.0-42

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-41';
31
+ const PROMPTBOOK_ENGINE_VERSION = '0.112.0-42';
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
@@ -23457,6 +23457,60 @@ function stripMetaIdLines(agentSource) {
23457
23457
  return strippedLines.join('\n');
23458
23458
  }
23459
23459
 
23460
+ /**
23461
+ * Builds normalized insert rows for a newly created persisted agent.
23462
+ *
23463
+ * @param agentSource - Source content of the agent.
23464
+ * @param options - Optional folder placement, ordering, and visibility overrides.
23465
+ * @param createdAt - Shared creation timestamp used across all persisted rows.
23466
+ * @returns Insert rows and the created agent profile.
23467
+ *
23468
+ * @private shared persistence helper for `AgentCollectionInSupabase`
23469
+ */
23470
+ function createAgentPersistenceRecords(agentSource, options = {}, createdAt = new Date().toISOString()) {
23471
+ const preparedAgentSource = prepareAgentSourceForPersistence(agentSource);
23472
+ const { agentProfile, agentSource: normalizedAgentSource } = preparedAgentSource;
23473
+ const permanentId = preparedAgentSource.permanentId || $randomBase58(14);
23474
+ const { agentName, agentHash } = agentProfile;
23475
+ const agentInsertRecord = {
23476
+ agentName,
23477
+ agentHash,
23478
+ permanentId,
23479
+ agentProfile,
23480
+ createdAt,
23481
+ updatedAt: null,
23482
+ promptbookEngineVersion: PROMPTBOOK_ENGINE_VERSION,
23483
+ usage: ZERO_USAGE,
23484
+ agentSource: normalizedAgentSource,
23485
+ };
23486
+ if (options.folderId !== undefined) {
23487
+ agentInsertRecord.folderId = options.folderId;
23488
+ }
23489
+ if (options.sortOrder !== undefined) {
23490
+ agentInsertRecord.sortOrder = options.sortOrder;
23491
+ }
23492
+ if (options.visibility !== undefined) {
23493
+ agentInsertRecord.visibility = options.visibility;
23494
+ }
23495
+ return {
23496
+ createdAgent: {
23497
+ ...agentProfile,
23498
+ permanentId,
23499
+ },
23500
+ agentInsertRecord,
23501
+ agentHistoryInsertRecord: {
23502
+ createdAt,
23503
+ agentName,
23504
+ permanentId,
23505
+ agentHash,
23506
+ previousAgentHash: null,
23507
+ agentSource: normalizedAgentSource,
23508
+ promptbookEngineVersion: PROMPTBOOK_ENGINE_VERSION,
23509
+ versionName: null,
23510
+ },
23511
+ };
23512
+ }
23513
+
23460
23514
  /**
23461
23515
  * Normalizes optional history version name before persistence.
23462
23516
  *
@@ -23580,52 +23634,18 @@ class AgentCollectionInSupabase /* TODO: [🌈][🐱‍🚀] implements AgentCol
23580
23634
  * @param options - Optional folder placement and ordering data.
23581
23635
  */
23582
23636
  async createAgent(agentSource, options = {}) {
23583
- const preparedAgentSource = prepareAgentSourceForPersistence(agentSource);
23584
- const { agentProfile, agentSource: normalizedAgentSource } = preparedAgentSource;
23585
- let { permanentId } = preparedAgentSource;
23586
- const { agentName, agentHash } = agentProfile;
23587
- if (!permanentId) {
23588
- permanentId = $randomBase58(14);
23589
- }
23590
- const insertPayload = {
23591
- agentName,
23592
- agentHash,
23593
- permanentId,
23594
- agentProfile,
23595
- createdAt: new Date().toISOString(),
23596
- updatedAt: null,
23597
- promptbookEngineVersion: PROMPTBOOK_ENGINE_VERSION,
23598
- usage: ZERO_USAGE,
23599
- agentSource: normalizedAgentSource,
23600
- };
23601
- if (options.folderId !== undefined) {
23602
- insertPayload.folderId = options.folderId;
23603
- }
23604
- if (options.sortOrder !== undefined) {
23605
- insertPayload.sortOrder = options.sortOrder;
23606
- }
23607
- if (options.visibility !== undefined) {
23608
- insertPayload.visibility = options.visibility;
23609
- }
23610
- const insertAgentResult = await this.supabaseClient.from(this.getTableName('Agent')).insert(insertPayload);
23637
+ const createdAt = new Date().toISOString();
23638
+ const { createdAgent, agentInsertRecord, agentHistoryInsertRecord } = createAgentPersistenceRecords(agentSource, options, createdAt);
23639
+ const insertAgentResult = await this.supabaseClient.from(this.getTableName('Agent')).insert(agentInsertRecord);
23611
23640
  if (insertAgentResult.error) {
23612
23641
  throw new DatabaseError(spaceTrim((block) => `
23613
- Error creating agent "${agentProfile.agentName}" in Supabase:
23642
+ Error creating agent "${createdAgent.agentName}" in Supabase:
23614
23643
 
23615
23644
  ${block(insertAgentResult.error.message)}
23616
23645
  `));
23617
23646
  }
23618
- await this.insertAgentHistoryRow({
23619
- createdAt: new Date().toISOString(),
23620
- agentName,
23621
- permanentId,
23622
- agentHash,
23623
- previousAgentHash: null,
23624
- agentSource: normalizedAgentSource,
23625
- promptbookEngineVersion: PROMPTBOOK_ENGINE_VERSION,
23626
- versionName: null,
23627
- });
23628
- return { ...agentProfile, permanentId };
23647
+ await this.insertAgentHistoryRow(agentHistoryInsertRecord);
23648
+ return createdAgent;
23629
23649
  }
23630
23650
  /**
23631
23651
  * Updates an existing agent in the collection