@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.
@@ -0,0 +1 @@
1
+ export {};
@@ -4,23 +4,11 @@ import type { string_book } from '../../../../book-2.0/agent-source/string_book'
4
4
  import type { string_agent_name, string_agent_permanent_id } from '../../../../types/typeAliases';
5
5
  import { AgentCollectionInSupabaseOptions } from './AgentCollectionInSupabaseOptions';
6
6
  import type { AgentsDatabaseSchema } from './AgentsDatabaseSchema';
7
+ import { type CreateAgentPersistenceRecordsOptions } from './createAgentPersistenceRecords';
7
8
  /**
8
9
  * Options for creating a new agent entry.
9
10
  */
10
- type CreateAgentOptions = {
11
- /**
12
- * Visibility for the new agent.
13
- */
14
- readonly visibility?: 'PRIVATE' | 'UNLISTED' | 'PUBLIC';
15
- /**
16
- * Folder identifier to assign the new agent to.
17
- */
18
- readonly folderId?: number | null;
19
- /**
20
- * Sort order for the agent within its parent folder.
21
- */
22
- readonly sortOrder?: number;
23
- };
11
+ type CreateAgentOptions = CreateAgentPersistenceRecordsOptions;
24
12
  /**
25
13
  * Optional controls for persisting one source update.
26
14
  */
@@ -0,0 +1,40 @@
1
+ import type { AgentBasicInformation } from '../../../../book-2.0/agent-source/AgentBasicInformation';
2
+ import type { string_book } from '../../../../book-2.0/agent-source/string_book';
3
+ import type { CreateAgentInput } from '../../CreateAgentInput';
4
+ import type { AgentsDatabaseSchema } from './AgentsDatabaseSchema';
5
+ /**
6
+ * Optional persistence overrides for one new agent row.
7
+ *
8
+ * @private shared persistence helper for `AgentCollectionInSupabase`
9
+ */
10
+ export type CreateAgentPersistenceRecordsOptions = Omit<CreateAgentInput, 'source'>;
11
+ /**
12
+ * Prepared insert rows and returned profile for one newly persisted agent.
13
+ *
14
+ * @private shared persistence helper for `AgentCollectionInSupabase`
15
+ */
16
+ export type CreateAgentPersistenceRecordsResult = {
17
+ /**
18
+ * Parsed created agent profile including the resolved permanent id.
19
+ */
20
+ readonly createdAgent: AgentBasicInformation & Required<Pick<AgentBasicInformation, 'permanentId'>>;
21
+ /**
22
+ * Insert row for the `Agent` table.
23
+ */
24
+ readonly agentInsertRecord: AgentsDatabaseSchema['public']['Tables']['Agent']['Insert'];
25
+ /**
26
+ * Insert row for the `AgentHistory` table.
27
+ */
28
+ readonly agentHistoryInsertRecord: AgentsDatabaseSchema['public']['Tables']['AgentHistory']['Insert'];
29
+ };
30
+ /**
31
+ * Builds normalized insert rows for a newly created persisted agent.
32
+ *
33
+ * @param agentSource - Source content of the agent.
34
+ * @param options - Optional folder placement, ordering, and visibility overrides.
35
+ * @param createdAt - Shared creation timestamp used across all persisted rows.
36
+ * @returns Insert rows and the created agent profile.
37
+ *
38
+ * @private shared persistence helper for `AgentCollectionInSupabase`
39
+ */
40
+ export declare function createAgentPersistenceRecords(agentSource: string_book, options?: CreateAgentPersistenceRecordsOptions, createdAt?: string): CreateAgentPersistenceRecordsResult;
@@ -15,7 +15,7 @@ export declare const BOOK_LANGUAGE_VERSION: string_semantic_version;
15
15
  export declare const PROMPTBOOK_ENGINE_VERSION: string_promptbook_version;
16
16
  /**
17
17
  * Represents the version string of the Promptbook engine.
18
- * It follows semantic versioning (e.g., `0.112.0-40`).
18
+ * It follows semantic versioning (e.g., `0.112.0-41`).
19
19
  *
20
20
  * @generated
21
21
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@promptbook/core",
3
- "version": "0.112.0-41",
3
+ "version": "0.112.0-42",
4
4
  "description": "Promptbook: Turn your company's scattered knowledge into AI ready books",
5
5
  "private": false,
6
6
  "sideEffects": false,
package/umd/index.umd.js CHANGED
@@ -27,7 +27,7 @@
27
27
  * @generated
28
28
  * @see https://github.com/webgptorg/promptbook
29
29
  */
30
- const PROMPTBOOK_ENGINE_VERSION = '0.112.0-41';
30
+ const PROMPTBOOK_ENGINE_VERSION = '0.112.0-42';
31
31
  /**
32
32
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
33
33
  * Note: [💞] Ignore a discrepancy between file name and entity name
@@ -23456,6 +23456,60 @@
23456
23456
  return strippedLines.join('\n');
23457
23457
  }
23458
23458
 
23459
+ /**
23460
+ * Builds normalized insert rows for a newly created persisted agent.
23461
+ *
23462
+ * @param agentSource - Source content of the agent.
23463
+ * @param options - Optional folder placement, ordering, and visibility overrides.
23464
+ * @param createdAt - Shared creation timestamp used across all persisted rows.
23465
+ * @returns Insert rows and the created agent profile.
23466
+ *
23467
+ * @private shared persistence helper for `AgentCollectionInSupabase`
23468
+ */
23469
+ function createAgentPersistenceRecords(agentSource, options = {}, createdAt = new Date().toISOString()) {
23470
+ const preparedAgentSource = prepareAgentSourceForPersistence(agentSource);
23471
+ const { agentProfile, agentSource: normalizedAgentSource } = preparedAgentSource;
23472
+ const permanentId = preparedAgentSource.permanentId || $randomBase58(14);
23473
+ const { agentName, agentHash } = agentProfile;
23474
+ const agentInsertRecord = {
23475
+ agentName,
23476
+ agentHash,
23477
+ permanentId,
23478
+ agentProfile,
23479
+ createdAt,
23480
+ updatedAt: null,
23481
+ promptbookEngineVersion: PROMPTBOOK_ENGINE_VERSION,
23482
+ usage: ZERO_USAGE,
23483
+ agentSource: normalizedAgentSource,
23484
+ };
23485
+ if (options.folderId !== undefined) {
23486
+ agentInsertRecord.folderId = options.folderId;
23487
+ }
23488
+ if (options.sortOrder !== undefined) {
23489
+ agentInsertRecord.sortOrder = options.sortOrder;
23490
+ }
23491
+ if (options.visibility !== undefined) {
23492
+ agentInsertRecord.visibility = options.visibility;
23493
+ }
23494
+ return {
23495
+ createdAgent: {
23496
+ ...agentProfile,
23497
+ permanentId,
23498
+ },
23499
+ agentInsertRecord,
23500
+ agentHistoryInsertRecord: {
23501
+ createdAt,
23502
+ agentName,
23503
+ permanentId,
23504
+ agentHash,
23505
+ previousAgentHash: null,
23506
+ agentSource: normalizedAgentSource,
23507
+ promptbookEngineVersion: PROMPTBOOK_ENGINE_VERSION,
23508
+ versionName: null,
23509
+ },
23510
+ };
23511
+ }
23512
+
23459
23513
  /**
23460
23514
  * Normalizes optional history version name before persistence.
23461
23515
  *
@@ -23579,52 +23633,18 @@
23579
23633
  * @param options - Optional folder placement and ordering data.
23580
23634
  */
23581
23635
  async createAgent(agentSource, options = {}) {
23582
- const preparedAgentSource = prepareAgentSourceForPersistence(agentSource);
23583
- const { agentProfile, agentSource: normalizedAgentSource } = preparedAgentSource;
23584
- let { permanentId } = preparedAgentSource;
23585
- const { agentName, agentHash } = agentProfile;
23586
- if (!permanentId) {
23587
- permanentId = $randomBase58(14);
23588
- }
23589
- const insertPayload = {
23590
- agentName,
23591
- agentHash,
23592
- permanentId,
23593
- agentProfile,
23594
- createdAt: new Date().toISOString(),
23595
- updatedAt: null,
23596
- promptbookEngineVersion: PROMPTBOOK_ENGINE_VERSION,
23597
- usage: ZERO_USAGE,
23598
- agentSource: normalizedAgentSource,
23599
- };
23600
- if (options.folderId !== undefined) {
23601
- insertPayload.folderId = options.folderId;
23602
- }
23603
- if (options.sortOrder !== undefined) {
23604
- insertPayload.sortOrder = options.sortOrder;
23605
- }
23606
- if (options.visibility !== undefined) {
23607
- insertPayload.visibility = options.visibility;
23608
- }
23609
- const insertAgentResult = await this.supabaseClient.from(this.getTableName('Agent')).insert(insertPayload);
23636
+ const createdAt = new Date().toISOString();
23637
+ const { createdAgent, agentInsertRecord, agentHistoryInsertRecord } = createAgentPersistenceRecords(agentSource, options, createdAt);
23638
+ const insertAgentResult = await this.supabaseClient.from(this.getTableName('Agent')).insert(agentInsertRecord);
23610
23639
  if (insertAgentResult.error) {
23611
23640
  throw new DatabaseError(spaceTrim((block) => `
23612
- Error creating agent "${agentProfile.agentName}" in Supabase:
23641
+ Error creating agent "${createdAgent.agentName}" in Supabase:
23613
23642
 
23614
23643
  ${block(insertAgentResult.error.message)}
23615
23644
  `));
23616
23645
  }
23617
- await this.insertAgentHistoryRow({
23618
- createdAt: new Date().toISOString(),
23619
- agentName,
23620
- permanentId,
23621
- agentHash,
23622
- previousAgentHash: null,
23623
- agentSource: normalizedAgentSource,
23624
- promptbookEngineVersion: PROMPTBOOK_ENGINE_VERSION,
23625
- versionName: null,
23626
- });
23627
- return { ...agentProfile, permanentId };
23646
+ await this.insertAgentHistoryRow(agentHistoryInsertRecord);
23647
+ return createdAgent;
23628
23648
  }
23629
23649
  /**
23630
23650
  * Updates an existing agent in the collection