@promptbook/core 0.104.0-7 โ†’ 0.104.0-9

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.
@@ -1,4 +1,4 @@
1
- import type { string_agent_name, string_agent_permanent_id, string_url_image } from '../../types/typeAliases';
1
+ import type { string_agent_name, string_agent_permanent_id, string_url, string_url_image } from '../../types/typeAliases';
2
2
  /**
3
3
  * Generates an image for the agent to use as profile image
4
4
  *
@@ -7,7 +7,7 @@ import type { string_agent_name, string_agent_permanent_id, string_url_image } f
7
7
  *
8
8
  * @public exported from `@promptbook/core`
9
9
  */
10
- export declare function generatePlaceholderAgentProfileImageUrl(agentIdOrName: string_agent_permanent_id | string_agent_name, agentsServerUrl?: URL): string_url_image;
10
+ export declare function generatePlaceholderAgentProfileImageUrl(agentIdOrName: string_agent_permanent_id | string_agent_name, agentsServerUrl?: URL | string_url): string_url_image;
11
11
  /**
12
12
  * TODO: [๐Ÿคน] Figure out best placeholder image generator https://i.pravatar.cc/1000?u=568
13
13
  */
@@ -1,7 +1,7 @@
1
1
  import type { SupabaseClient } from '@supabase/supabase-js';
2
2
  import type { AgentBasicInformation } from '../../../../book-2.0/agent-source/AgentBasicInformation';
3
3
  import type { string_book } from '../../../../book-2.0/agent-source/string_book';
4
- import type { string_agent_name } from '../../../../types/typeAliases';
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
7
  /**
@@ -28,7 +28,11 @@ export declare class AgentCollectionInSupabase {
28
28
  /**
29
29
  * [๐Ÿฑโ€๐Ÿš€]@@@
30
30
  */
31
- getAgentSource(agentName: string_agent_name): Promise<string_book>;
31
+ getAgentPermanentId(agentNameOrPermanentId: string_agent_name | string_agent_permanent_id): Promise<string_agent_permanent_id>;
32
+ /**
33
+ * [๐Ÿฑโ€๐Ÿš€]@@@
34
+ */
35
+ getAgentSource(agentNameOrPermanentId: string_agent_name | string_agent_permanent_id): Promise<string_book>;
32
36
  /**
33
37
  * Creates a new agent in the collection
34
38
  *
@@ -38,7 +42,7 @@ export declare class AgentCollectionInSupabase {
38
42
  /**
39
43
  * Updates an existing agent in the collection
40
44
  */
41
- updateAgentSource(agentName: string_agent_name, agentSource: string_book): Promise<void>;
45
+ updateAgentSource(permanentId: string_agent_permanent_id, agentSource: string_book): Promise<void>;
42
46
  /**
43
47
  * List agents that are soft deleted (deletedAt IS NOT NULL)
44
48
  */
@@ -46,7 +50,7 @@ export declare class AgentCollectionInSupabase {
46
50
  /**
47
51
  * List history of an agent
48
52
  */
49
- listAgentHistory(agentName: string_agent_name): Promise<ReadonlyArray<{
53
+ listAgentHistory(permanentId: string_agent_permanent_id): Promise<ReadonlyArray<{
50
54
  id: number;
51
55
  createdAt: string;
52
56
  agentHash: string;
@@ -55,7 +59,7 @@ export declare class AgentCollectionInSupabase {
55
59
  /**
56
60
  * Restore a soft-deleted agent by setting deletedAt to NULL
57
61
  */
58
- restoreAgent(agentIdentifier: string): Promise<void>;
62
+ restoreAgent(permanentId: string_agent_permanent_id): Promise<void>;
59
63
  /**
60
64
  * Restore an agent from a specific history entry
61
65
  *
@@ -65,7 +69,7 @@ export declare class AgentCollectionInSupabase {
65
69
  /**
66
70
  * Soft delete an agent by setting deletedAt to current timestamp
67
71
  */
68
- deleteAgent(agentIdentifier: string): Promise<void>;
72
+ deleteAgent(permanentId: string_agent_permanent_id): Promise<void>;
69
73
  /**
70
74
  * Get the Supabase table name with prefix
71
75
  *
@@ -73,6 +73,7 @@ export type AgentsDatabaseSchema = {
73
73
  id: number;
74
74
  createdAt: string;
75
75
  agentName: string;
76
+ permanentId: string;
76
77
  agentHash: string;
77
78
  previousAgentHash: string | null;
78
79
  agentSource: string;
@@ -82,6 +83,7 @@ export type AgentsDatabaseSchema = {
82
83
  id?: number;
83
84
  createdAt: string;
84
85
  agentName: string;
86
+ permanentId: string;
85
87
  agentHash: string;
86
88
  previousAgentHash?: string | null;
87
89
  agentSource: string;
@@ -91,6 +93,7 @@ export type AgentsDatabaseSchema = {
91
93
  id?: number;
92
94
  createdAt?: string;
93
95
  agentName?: string;
96
+ permanentId?: string;
94
97
  agentHash?: string;
95
98
  previousAgentHash?: string | null;
96
99
  agentSource?: string;
@@ -98,10 +101,10 @@ export type AgentsDatabaseSchema = {
98
101
  };
99
102
  Relationships: [
100
103
  {
101
- foreignKeyName: 'AgentHistory_agentName_fkey';
102
- columns: ['agentName'];
104
+ foreignKeyName: 'AgentHistory_permanentId_fkey';
105
+ columns: ['permanentId'];
103
106
  referencedRelation: 'Agent';
104
- referencedColumns: ['agentName'];
107
+ referencedColumns: ['permanentId'];
105
108
  }
106
109
  ];
107
110
  };
@@ -1,10 +1,11 @@
1
+ import { string_color, string_data_url, string_url_image } from '../../../types/typeAliases';
1
2
  import { Color } from '../Color';
2
3
  /**
3
4
  * Makes data url from color
4
5
  *
5
6
  * @public exported from `@promptbook/color`
6
7
  */
7
- export declare function colorToDataUrl(color: Color): string;
8
+ export declare function colorToDataUrl(color: Color | string_color): string_data_url & string_url_image;
8
9
  /**
9
10
  * TODO: Make as functions NOT const
10
11
  */
@@ -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.104.0-6`).
18
+ * It follows semantic versioning (e.g., `0.104.0-8`).
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.104.0-7",
3
+ "version": "0.104.0-9",
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
@@ -28,7 +28,7 @@
28
28
  * @generated
29
29
  * @see https://github.com/webgptorg/promptbook
30
30
  */
31
- const PROMPTBOOK_ENGINE_VERSION = '0.104.0-7';
31
+ const PROMPTBOOK_ENGINE_VERSION = '0.104.0-9';
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
@@ -11345,7 +11345,12 @@
11345
11345
  };
11346
11346
  }
11347
11347
  // Apply each commitment in order using reduce-like pattern
11348
- for (const commitment of filteredCommitments) {
11348
+ for (let i = 0; i < filteredCommitments.length; i++) {
11349
+ const commitment = filteredCommitments[i];
11350
+ // CLOSED commitment should work only if its the last commitment in the book
11351
+ if (commitment.type === 'CLOSED' && i !== filteredCommitments.length - 1) {
11352
+ continue;
11353
+ }
11349
11354
  const definition = getCommitmentDefinition(commitment.type);
11350
11355
  if (definition) {
11351
11356
  try {
@@ -12132,8 +12137,11 @@
12132
12137
  *
12133
12138
  * @public exported from `@promptbook/core`
12134
12139
  */
12135
- function generatePlaceholderAgentProfileImageUrl(agentIdOrName, agentsServerUrl = new URL(CORE_SERVER.urls[0])) {
12136
- return `${agentsServerUrl}agents/${agentIdOrName}/images/default-avatar.png`;
12140
+ function generatePlaceholderAgentProfileImageUrl(agentIdOrName, agentsServerUrl = CORE_SERVER.urls[0]) {
12141
+ if (typeof agentsServerUrl === 'string') {
12142
+ agentsServerUrl = new URL(agentsServerUrl);
12143
+ }
12144
+ return `${agentsServerUrl.href}agents/${agentIdOrName}/images/default-avatar.png`;
12137
12145
  }
12138
12146
  /**
12139
12147
  * TODO: [๐Ÿคน] Figure out best placeholder image generator https://i.pravatar.cc/1000?u=568
@@ -12239,20 +12247,35 @@
12239
12247
  /**
12240
12248
  * [๐Ÿฑโ€๐Ÿš€]@@@
12241
12249
  */
12242
- async getAgentSource(agentName) {
12250
+ async getAgentPermanentId(agentNameOrPermanentId) {
12251
+ const selectResult = await this.supabaseClient
12252
+ .from(this.getTableName('Agent'))
12253
+ .select('permanentId')
12254
+ .or(`agentName.eq.${agentNameOrPermanentId},permanentId.eq.${agentNameOrPermanentId}`)
12255
+ .single();
12256
+ if (selectResult.error || !selectResult.data) {
12257
+ throw new NotFoundError(`Agent with name not id "${agentNameOrPermanentId}" not found`);
12258
+ }
12259
+ return selectResult.data.permanentId;
12260
+ }
12261
+ /**
12262
+ * [๐Ÿฑโ€๐Ÿš€]@@@
12263
+ */
12264
+ async getAgentSource(agentNameOrPermanentId) {
12243
12265
  const selectResult = await this.supabaseClient
12244
12266
  .from(this.getTableName('Agent'))
12245
12267
  .select('agentSource')
12246
- .or(`agentName.eq.${agentName},permanentId.eq.${agentName}`);
12268
+ .or(`agentName.eq.${agentNameOrPermanentId},permanentId.eq.${agentNameOrPermanentId}`)
12269
+ .is('deletedAt', null);
12247
12270
  if (selectResult.data && selectResult.data.length === 0) {
12248
- throw new NotFoundError(`Agent "${agentName}" not found`);
12271
+ throw new NotFoundError(`Agent "${agentNameOrPermanentId}" not found`);
12249
12272
  }
12250
12273
  else if (selectResult.data && selectResult.data.length > 1) {
12251
- throw new UnexpectedError(`More agents with agentName="${agentName}" found`);
12274
+ throw new UnexpectedError(`More agents with name or id "${agentNameOrPermanentId}" found`);
12252
12275
  }
12253
12276
  else if (selectResult.error) {
12254
12277
  throw new DatabaseError(spaceTrim((block) => `
12255
- Error fetching agent "${agentName}" from Supabase:
12278
+ Error fetching agent "${agentNameOrPermanentId}" from Supabase:
12256
12279
 
12257
12280
  ${block(selectResult.error.message)}
12258
12281
  `));
@@ -12267,19 +12290,19 @@
12267
12290
  async createAgent(agentSource) {
12268
12291
  let agentProfile = parseAgentSource(agentSource);
12269
12292
  // <- TODO: [๐Ÿ•›]
12270
- const { agentName, agentHash } = agentProfile;
12293
+ // 1. Extract permanentId from the source if present
12271
12294
  let { permanentId } = agentProfile;
12295
+ // 2. Remove META ID from the source
12296
+ const lines = agentSource.split('\n');
12297
+ const strippedLines = lines.filter((line) => !line.trim().startsWith('META ID '));
12298
+ if (lines.length !== strippedLines.length) {
12299
+ agentSource = strippedLines.join('\n');
12300
+ // 3. Re-parse the agent source to get the correct hash and other info
12301
+ agentProfile = parseAgentSource(agentSource);
12302
+ }
12303
+ const { agentName, agentHash } = agentProfile;
12272
12304
  if (!permanentId) {
12273
12305
  permanentId = $randomBase58(14);
12274
- const lines = agentSource.split('\n');
12275
- if (lines.length > 0) {
12276
- lines.splice(1, 0, `META ID ${permanentId}`);
12277
- agentSource = lines.join('\n');
12278
- }
12279
- else {
12280
- agentSource = `META ID ${permanentId}\n${agentSource}`;
12281
- }
12282
- agentProfile = parseAgentSource(agentSource);
12283
12306
  }
12284
12307
  const insertAgentResult = await this.supabaseClient.from(this.getTableName('Agent')).insert({
12285
12308
  agentName,
@@ -12302,6 +12325,7 @@
12302
12325
  await this.supabaseClient.from(this.getTableName('AgentHistory')).insert({
12303
12326
  createdAt: new Date().toISOString(),
12304
12327
  agentName,
12328
+ permanentId,
12305
12329
  agentHash,
12306
12330
  previousAgentHash: null,
12307
12331
  agentSource,
@@ -12313,17 +12337,17 @@
12313
12337
  /**
12314
12338
  * Updates an existing agent in the collection
12315
12339
  */
12316
- async updateAgentSource(agentName, agentSource) {
12317
- console.log('!!! updateAgentSource', { agentName });
12340
+ async updateAgentSource(permanentId, agentSource) {
12341
+ console.log('!!! updateAgentSource', { permanentId });
12318
12342
  const selectPreviousAgentResult = await this.supabaseClient
12319
12343
  .from(this.getTableName('Agent'))
12320
12344
  .select('agentHash,agentName,permanentId')
12321
- .eq('agentName', agentName)
12345
+ .eq('permanentId', permanentId)
12322
12346
  .single();
12323
12347
  if (selectPreviousAgentResult.error) {
12324
12348
  throw new DatabaseError(spaceTrim((block) => `
12325
12349
 
12326
- Error fetching agent "${agentName}" from Supabase:
12350
+ Error fetching agent "${permanentId}" from Supabase:
12327
12351
 
12328
12352
  ${block(selectPreviousAgentResult.error.message)}
12329
12353
  `));
@@ -12334,20 +12358,27 @@
12334
12358
  const previousPermanentId = selectPreviousAgentResult.data.permanentId;
12335
12359
  let agentProfile = parseAgentSource(agentSource);
12336
12360
  // <- TODO: [๐Ÿ•›]
12337
- const { agentHash } = agentProfile;
12338
- let { permanentId } = agentProfile;
12339
- if (!permanentId && previousPermanentId) {
12340
- permanentId = previousPermanentId;
12341
- const lines = agentSource.split('\n');
12342
- if (lines.length > 0) {
12343
- lines.splice(1, 0, `META ID ${permanentId}`);
12344
- agentSource = lines.join('\n');
12345
- }
12346
- else {
12347
- agentSource = `META ID ${permanentId}\n${agentSource}`;
12348
- }
12361
+ // 1. Extract permanentId from the source if present
12362
+ let { permanentId: newPermanentId } = agentProfile;
12363
+ // 2. Remove META ID from the source
12364
+ const lines = agentSource.split('\n');
12365
+ const strippedLines = lines.filter((line) => !line.trim().startsWith('META ID '));
12366
+ if (lines.length !== strippedLines.length) {
12367
+ agentSource = strippedLines.join('\n');
12368
+ // 3. Re-parse the agent source to get the correct hash and other info
12349
12369
  agentProfile = parseAgentSource(agentSource);
12350
12370
  }
12371
+ const { agentHash, agentName } = agentProfile;
12372
+ if (!newPermanentId && previousPermanentId) {
12373
+ newPermanentId = previousPermanentId;
12374
+ }
12375
+ if (!newPermanentId) {
12376
+ newPermanentId = $randomBase58(14);
12377
+ }
12378
+ if (newPermanentId !== permanentId) {
12379
+ // [๐Ÿง ] Should be allowed to change permanentId?
12380
+ throw new UnexpectedError(`Permanent ID mismatch: "${permanentId}" (argument) !== "${newPermanentId}" (in source)`);
12381
+ }
12351
12382
  const updateAgentResult = await this.supabaseClient
12352
12383
  .from(this.getTableName('Agent'))
12353
12384
  .update({
@@ -12359,13 +12390,13 @@
12359
12390
  agentSource,
12360
12391
  promptbookEngineVersion: PROMPTBOOK_ENGINE_VERSION,
12361
12392
  })
12362
- .eq('agentName', agentName);
12393
+ .eq('permanentId', permanentId);
12363
12394
  // console.log('[๐Ÿฑโ€๐Ÿš€] updateAgent', updateResult);
12364
12395
  // console.log('[๐Ÿฑโ€๐Ÿš€] old', oldAgentSource);
12365
12396
  // console.log('[๐Ÿฑโ€๐Ÿš€] new', newAgentSource);
12366
12397
  if (updateAgentResult.error) {
12367
12398
  throw new DatabaseError(spaceTrim((block) => `
12368
- Error updating agent "${agentName}" in Supabase:
12399
+ Error updating agent "${permanentId}" in Supabase:
12369
12400
 
12370
12401
  ${block(updateAgentResult.error.message)}
12371
12402
  `));
@@ -12373,6 +12404,7 @@
12373
12404
  await this.supabaseClient.from(this.getTableName('AgentHistory')).insert({
12374
12405
  createdAt: new Date().toISOString(),
12375
12406
  agentName,
12407
+ permanentId,
12376
12408
  agentHash,
12377
12409
  previousAgentHash,
12378
12410
  agentSource,
@@ -12380,7 +12412,7 @@
12380
12412
  });
12381
12413
  // <- TODO: [๐Ÿง ] What to do with `insertAgentHistoryResult.error`, ignore? wait?
12382
12414
  }
12383
- // TODO: [๐Ÿฑโ€๐Ÿš€] public async getAgentSourceSubject(agentName: string_agent_name): Promise<BehaviorSubject<string_book>>
12415
+ // TODO: [๐Ÿฑโ€๐Ÿš€] public async getAgentSourceSubject(permanentId: string_agent_permanent_id): Promise<BehaviorSubject<string_book>>
12384
12416
  // Use Supabase realtime logic
12385
12417
  /**
12386
12418
  * List agents that are soft deleted (deletedAt IS NOT NULL)
@@ -12420,15 +12452,15 @@
12420
12452
  /**
12421
12453
  * List history of an agent
12422
12454
  */
12423
- async listAgentHistory(agentName) {
12455
+ async listAgentHistory(permanentId) {
12424
12456
  const result = await this.supabaseClient
12425
12457
  .from(this.getTableName('AgentHistory'))
12426
12458
  .select('id, createdAt, agentHash, promptbookEngineVersion')
12427
- .eq('agentName', agentName)
12459
+ .eq('permanentId', permanentId)
12428
12460
  .order('createdAt', { ascending: false });
12429
12461
  if (result.error) {
12430
12462
  throw new DatabaseError(spaceTrim((block) => `
12431
- Error listing history for agent "${agentName}" from Supabase:
12463
+ Error listing history for agent "${permanentId}" from Supabase:
12432
12464
 
12433
12465
  ${block(result.error.message)}
12434
12466
  `));
@@ -12438,15 +12470,15 @@
12438
12470
  /**
12439
12471
  * Restore a soft-deleted agent by setting deletedAt to NULL
12440
12472
  */
12441
- async restoreAgent(agentIdentifier) {
12473
+ async restoreAgent(permanentId) {
12442
12474
  const updateResult = await this.supabaseClient
12443
12475
  .from(this.getTableName('Agent'))
12444
12476
  .update({ deletedAt: null })
12445
- .or(`agentName.eq.${agentIdentifier},permanentId.eq.${agentIdentifier}`)
12477
+ .eq('permanentId', permanentId)
12446
12478
  .not('deletedAt', 'is', null);
12447
12479
  if (updateResult.error) {
12448
12480
  throw new DatabaseError(spaceTrim((block) => `
12449
- Error restoring agent "${agentIdentifier}" from Supabase:
12481
+ Error restoring agent "${permanentId}" from Supabase:
12450
12482
 
12451
12483
  ${block(updateResult.error.message)}
12452
12484
  `));
@@ -12461,7 +12493,7 @@
12461
12493
  // First, get the history entry
12462
12494
  const historyResult = await this.supabaseClient
12463
12495
  .from(this.getTableName('AgentHistory'))
12464
- .select('agentName, agentSource')
12496
+ .select('permanentId, agentSource')
12465
12497
  .eq('id', historyId)
12466
12498
  .single();
12467
12499
  if (historyResult.error) {
@@ -12474,22 +12506,22 @@
12474
12506
  if (!historyResult.data) {
12475
12507
  throw new NotFoundError(`History entry with id "${historyId}" not found`);
12476
12508
  }
12477
- const { agentName, agentSource } = historyResult.data;
12509
+ const { permanentId, agentSource } = historyResult.data;
12478
12510
  // Update the agent with the source from the history entry
12479
- await this.updateAgentSource(agentName, agentSource);
12511
+ await this.updateAgentSource(permanentId, agentSource);
12480
12512
  }
12481
12513
  /**
12482
12514
  * Soft delete an agent by setting deletedAt to current timestamp
12483
12515
  */
12484
- async deleteAgent(agentIdentifier) {
12516
+ async deleteAgent(permanentId) {
12485
12517
  const updateResult = await this.supabaseClient
12486
12518
  .from(this.getTableName('Agent'))
12487
12519
  .update({ deletedAt: new Date().toISOString() })
12488
- .or(`agentName.eq.${agentIdentifier},permanentId.eq.${agentIdentifier}`)
12520
+ .eq('permanentId', permanentId)
12489
12521
  .is('deletedAt', null);
12490
12522
  if (updateResult.error) {
12491
12523
  throw new DatabaseError(spaceTrim((block) => `
12492
- Error deleting agent "${agentIdentifier}" from Supabase:
12524
+ Error deleting agent "${permanentId}" from Supabase:
12493
12525
 
12494
12526
  ${block(updateResult.error.message)}
12495
12527
  `));