@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.
- package/esm/index.es.js +82 -50
- package/esm/index.es.js.map +1 -1
- package/esm/typings/src/book-2.0/agent-source/createAgentModelRequirementsWithCommitments.closed.test.d.ts +1 -0
- package/esm/typings/src/book-2.0/utils/generatePlaceholderAgentProfileImageUrl.d.ts +2 -2
- package/esm/typings/src/collection/agent-collection/constructors/agent-collection-in-supabase/AgentCollectionInSupabase.d.ts +10 -6
- package/esm/typings/src/collection/agent-collection/constructors/agent-collection-in-supabase/AgentsDatabaseSchema.d.ts +6 -3
- package/esm/typings/src/utils/color/utils/colorToDataUrl.d.ts +2 -1
- package/esm/typings/src/version.d.ts +1 -1
- package/package.json +1 -1
- package/umd/index.umd.js +82 -50
- package/umd/index.umd.js.map +1 -1
package/esm/index.es.js
CHANGED
|
@@ -27,7 +27,7 @@ const BOOK_LANGUAGE_VERSION = '2.0.0';
|
|
|
27
27
|
* @generated
|
|
28
28
|
* @see https://github.com/webgptorg/promptbook
|
|
29
29
|
*/
|
|
30
|
-
const PROMPTBOOK_ENGINE_VERSION = '0.104.0-
|
|
30
|
+
const PROMPTBOOK_ENGINE_VERSION = '0.104.0-9';
|
|
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
|
|
@@ -11344,7 +11344,12 @@ async function createAgentModelRequirementsWithCommitments(agentSource, modelNam
|
|
|
11344
11344
|
};
|
|
11345
11345
|
}
|
|
11346
11346
|
// Apply each commitment in order using reduce-like pattern
|
|
11347
|
-
for (
|
|
11347
|
+
for (let i = 0; i < filteredCommitments.length; i++) {
|
|
11348
|
+
const commitment = filteredCommitments[i];
|
|
11349
|
+
// CLOSED commitment should work only if its the last commitment in the book
|
|
11350
|
+
if (commitment.type === 'CLOSED' && i !== filteredCommitments.length - 1) {
|
|
11351
|
+
continue;
|
|
11352
|
+
}
|
|
11348
11353
|
const definition = getCommitmentDefinition(commitment.type);
|
|
11349
11354
|
if (definition) {
|
|
11350
11355
|
try {
|
|
@@ -12131,8 +12136,11 @@ const DEFAULT_BOOK = padBook(validateBook(spaceTrim$2(`
|
|
|
12131
12136
|
*
|
|
12132
12137
|
* @public exported from `@promptbook/core`
|
|
12133
12138
|
*/
|
|
12134
|
-
function generatePlaceholderAgentProfileImageUrl(agentIdOrName, agentsServerUrl =
|
|
12135
|
-
|
|
12139
|
+
function generatePlaceholderAgentProfileImageUrl(agentIdOrName, agentsServerUrl = CORE_SERVER.urls[0]) {
|
|
12140
|
+
if (typeof agentsServerUrl === 'string') {
|
|
12141
|
+
agentsServerUrl = new URL(agentsServerUrl);
|
|
12142
|
+
}
|
|
12143
|
+
return `${agentsServerUrl.href}agents/${agentIdOrName}/images/default-avatar.png`;
|
|
12136
12144
|
}
|
|
12137
12145
|
/**
|
|
12138
12146
|
* TODO: [๐คน] Figure out best placeholder image generator https://i.pravatar.cc/1000?u=568
|
|
@@ -12238,20 +12246,35 @@ class AgentCollectionInSupabase /* TODO: [๐ฑโ๐] implements Agent */ {
|
|
|
12238
12246
|
/**
|
|
12239
12247
|
* [๐ฑโ๐]@@@
|
|
12240
12248
|
*/
|
|
12241
|
-
async
|
|
12249
|
+
async getAgentPermanentId(agentNameOrPermanentId) {
|
|
12250
|
+
const selectResult = await this.supabaseClient
|
|
12251
|
+
.from(this.getTableName('Agent'))
|
|
12252
|
+
.select('permanentId')
|
|
12253
|
+
.or(`agentName.eq.${agentNameOrPermanentId},permanentId.eq.${agentNameOrPermanentId}`)
|
|
12254
|
+
.single();
|
|
12255
|
+
if (selectResult.error || !selectResult.data) {
|
|
12256
|
+
throw new NotFoundError(`Agent with name not id "${agentNameOrPermanentId}" not found`);
|
|
12257
|
+
}
|
|
12258
|
+
return selectResult.data.permanentId;
|
|
12259
|
+
}
|
|
12260
|
+
/**
|
|
12261
|
+
* [๐ฑโ๐]@@@
|
|
12262
|
+
*/
|
|
12263
|
+
async getAgentSource(agentNameOrPermanentId) {
|
|
12242
12264
|
const selectResult = await this.supabaseClient
|
|
12243
12265
|
.from(this.getTableName('Agent'))
|
|
12244
12266
|
.select('agentSource')
|
|
12245
|
-
.or(`agentName.eq.${
|
|
12267
|
+
.or(`agentName.eq.${agentNameOrPermanentId},permanentId.eq.${agentNameOrPermanentId}`)
|
|
12268
|
+
.is('deletedAt', null);
|
|
12246
12269
|
if (selectResult.data && selectResult.data.length === 0) {
|
|
12247
|
-
throw new NotFoundError(`Agent "${
|
|
12270
|
+
throw new NotFoundError(`Agent "${agentNameOrPermanentId}" not found`);
|
|
12248
12271
|
}
|
|
12249
12272
|
else if (selectResult.data && selectResult.data.length > 1) {
|
|
12250
|
-
throw new UnexpectedError(`More agents with
|
|
12273
|
+
throw new UnexpectedError(`More agents with name or id "${agentNameOrPermanentId}" found`);
|
|
12251
12274
|
}
|
|
12252
12275
|
else if (selectResult.error) {
|
|
12253
12276
|
throw new DatabaseError(spaceTrim((block) => `
|
|
12254
|
-
Error fetching agent "${
|
|
12277
|
+
Error fetching agent "${agentNameOrPermanentId}" from Supabase:
|
|
12255
12278
|
|
|
12256
12279
|
${block(selectResult.error.message)}
|
|
12257
12280
|
`));
|
|
@@ -12266,19 +12289,19 @@ class AgentCollectionInSupabase /* TODO: [๐ฑโ๐] implements Agent */ {
|
|
|
12266
12289
|
async createAgent(agentSource) {
|
|
12267
12290
|
let agentProfile = parseAgentSource(agentSource);
|
|
12268
12291
|
// <- TODO: [๐]
|
|
12269
|
-
|
|
12292
|
+
// 1. Extract permanentId from the source if present
|
|
12270
12293
|
let { permanentId } = agentProfile;
|
|
12294
|
+
// 2. Remove META ID from the source
|
|
12295
|
+
const lines = agentSource.split('\n');
|
|
12296
|
+
const strippedLines = lines.filter((line) => !line.trim().startsWith('META ID '));
|
|
12297
|
+
if (lines.length !== strippedLines.length) {
|
|
12298
|
+
agentSource = strippedLines.join('\n');
|
|
12299
|
+
// 3. Re-parse the agent source to get the correct hash and other info
|
|
12300
|
+
agentProfile = parseAgentSource(agentSource);
|
|
12301
|
+
}
|
|
12302
|
+
const { agentName, agentHash } = agentProfile;
|
|
12271
12303
|
if (!permanentId) {
|
|
12272
12304
|
permanentId = $randomBase58(14);
|
|
12273
|
-
const lines = agentSource.split('\n');
|
|
12274
|
-
if (lines.length > 0) {
|
|
12275
|
-
lines.splice(1, 0, `META ID ${permanentId}`);
|
|
12276
|
-
agentSource = lines.join('\n');
|
|
12277
|
-
}
|
|
12278
|
-
else {
|
|
12279
|
-
agentSource = `META ID ${permanentId}\n${agentSource}`;
|
|
12280
|
-
}
|
|
12281
|
-
agentProfile = parseAgentSource(agentSource);
|
|
12282
12305
|
}
|
|
12283
12306
|
const insertAgentResult = await this.supabaseClient.from(this.getTableName('Agent')).insert({
|
|
12284
12307
|
agentName,
|
|
@@ -12301,6 +12324,7 @@ class AgentCollectionInSupabase /* TODO: [๐ฑโ๐] implements Agent */ {
|
|
|
12301
12324
|
await this.supabaseClient.from(this.getTableName('AgentHistory')).insert({
|
|
12302
12325
|
createdAt: new Date().toISOString(),
|
|
12303
12326
|
agentName,
|
|
12327
|
+
permanentId,
|
|
12304
12328
|
agentHash,
|
|
12305
12329
|
previousAgentHash: null,
|
|
12306
12330
|
agentSource,
|
|
@@ -12312,17 +12336,17 @@ class AgentCollectionInSupabase /* TODO: [๐ฑโ๐] implements Agent */ {
|
|
|
12312
12336
|
/**
|
|
12313
12337
|
* Updates an existing agent in the collection
|
|
12314
12338
|
*/
|
|
12315
|
-
async updateAgentSource(
|
|
12316
|
-
console.log('!!! updateAgentSource', {
|
|
12339
|
+
async updateAgentSource(permanentId, agentSource) {
|
|
12340
|
+
console.log('!!! updateAgentSource', { permanentId });
|
|
12317
12341
|
const selectPreviousAgentResult = await this.supabaseClient
|
|
12318
12342
|
.from(this.getTableName('Agent'))
|
|
12319
12343
|
.select('agentHash,agentName,permanentId')
|
|
12320
|
-
.eq('
|
|
12344
|
+
.eq('permanentId', permanentId)
|
|
12321
12345
|
.single();
|
|
12322
12346
|
if (selectPreviousAgentResult.error) {
|
|
12323
12347
|
throw new DatabaseError(spaceTrim((block) => `
|
|
12324
12348
|
|
|
12325
|
-
Error fetching agent "${
|
|
12349
|
+
Error fetching agent "${permanentId}" from Supabase:
|
|
12326
12350
|
|
|
12327
12351
|
${block(selectPreviousAgentResult.error.message)}
|
|
12328
12352
|
`));
|
|
@@ -12333,20 +12357,27 @@ class AgentCollectionInSupabase /* TODO: [๐ฑโ๐] implements Agent */ {
|
|
|
12333
12357
|
const previousPermanentId = selectPreviousAgentResult.data.permanentId;
|
|
12334
12358
|
let agentProfile = parseAgentSource(agentSource);
|
|
12335
12359
|
// <- TODO: [๐]
|
|
12336
|
-
|
|
12337
|
-
let { permanentId } = agentProfile;
|
|
12338
|
-
|
|
12339
|
-
|
|
12340
|
-
|
|
12341
|
-
|
|
12342
|
-
|
|
12343
|
-
|
|
12344
|
-
}
|
|
12345
|
-
else {
|
|
12346
|
-
agentSource = `META ID ${permanentId}\n${agentSource}`;
|
|
12347
|
-
}
|
|
12360
|
+
// 1. Extract permanentId from the source if present
|
|
12361
|
+
let { permanentId: newPermanentId } = agentProfile;
|
|
12362
|
+
// 2. Remove META ID from the source
|
|
12363
|
+
const lines = agentSource.split('\n');
|
|
12364
|
+
const strippedLines = lines.filter((line) => !line.trim().startsWith('META ID '));
|
|
12365
|
+
if (lines.length !== strippedLines.length) {
|
|
12366
|
+
agentSource = strippedLines.join('\n');
|
|
12367
|
+
// 3. Re-parse the agent source to get the correct hash and other info
|
|
12348
12368
|
agentProfile = parseAgentSource(agentSource);
|
|
12349
12369
|
}
|
|
12370
|
+
const { agentHash, agentName } = agentProfile;
|
|
12371
|
+
if (!newPermanentId && previousPermanentId) {
|
|
12372
|
+
newPermanentId = previousPermanentId;
|
|
12373
|
+
}
|
|
12374
|
+
if (!newPermanentId) {
|
|
12375
|
+
newPermanentId = $randomBase58(14);
|
|
12376
|
+
}
|
|
12377
|
+
if (newPermanentId !== permanentId) {
|
|
12378
|
+
// [๐ง ] Should be allowed to change permanentId?
|
|
12379
|
+
throw new UnexpectedError(`Permanent ID mismatch: "${permanentId}" (argument) !== "${newPermanentId}" (in source)`);
|
|
12380
|
+
}
|
|
12350
12381
|
const updateAgentResult = await this.supabaseClient
|
|
12351
12382
|
.from(this.getTableName('Agent'))
|
|
12352
12383
|
.update({
|
|
@@ -12358,13 +12389,13 @@ class AgentCollectionInSupabase /* TODO: [๐ฑโ๐] implements Agent */ {
|
|
|
12358
12389
|
agentSource,
|
|
12359
12390
|
promptbookEngineVersion: PROMPTBOOK_ENGINE_VERSION,
|
|
12360
12391
|
})
|
|
12361
|
-
.eq('
|
|
12392
|
+
.eq('permanentId', permanentId);
|
|
12362
12393
|
// console.log('[๐ฑโ๐] updateAgent', updateResult);
|
|
12363
12394
|
// console.log('[๐ฑโ๐] old', oldAgentSource);
|
|
12364
12395
|
// console.log('[๐ฑโ๐] new', newAgentSource);
|
|
12365
12396
|
if (updateAgentResult.error) {
|
|
12366
12397
|
throw new DatabaseError(spaceTrim((block) => `
|
|
12367
|
-
Error updating agent "${
|
|
12398
|
+
Error updating agent "${permanentId}" in Supabase:
|
|
12368
12399
|
|
|
12369
12400
|
${block(updateAgentResult.error.message)}
|
|
12370
12401
|
`));
|
|
@@ -12372,6 +12403,7 @@ class AgentCollectionInSupabase /* TODO: [๐ฑโ๐] implements Agent */ {
|
|
|
12372
12403
|
await this.supabaseClient.from(this.getTableName('AgentHistory')).insert({
|
|
12373
12404
|
createdAt: new Date().toISOString(),
|
|
12374
12405
|
agentName,
|
|
12406
|
+
permanentId,
|
|
12375
12407
|
agentHash,
|
|
12376
12408
|
previousAgentHash,
|
|
12377
12409
|
agentSource,
|
|
@@ -12379,7 +12411,7 @@ class AgentCollectionInSupabase /* TODO: [๐ฑโ๐] implements Agent */ {
|
|
|
12379
12411
|
});
|
|
12380
12412
|
// <- TODO: [๐ง ] What to do with `insertAgentHistoryResult.error`, ignore? wait?
|
|
12381
12413
|
}
|
|
12382
|
-
// TODO: [๐ฑโ๐] public async getAgentSourceSubject(
|
|
12414
|
+
// TODO: [๐ฑโ๐] public async getAgentSourceSubject(permanentId: string_agent_permanent_id): Promise<BehaviorSubject<string_book>>
|
|
12383
12415
|
// Use Supabase realtime logic
|
|
12384
12416
|
/**
|
|
12385
12417
|
* List agents that are soft deleted (deletedAt IS NOT NULL)
|
|
@@ -12419,15 +12451,15 @@ class AgentCollectionInSupabase /* TODO: [๐ฑโ๐] implements Agent */ {
|
|
|
12419
12451
|
/**
|
|
12420
12452
|
* List history of an agent
|
|
12421
12453
|
*/
|
|
12422
|
-
async listAgentHistory(
|
|
12454
|
+
async listAgentHistory(permanentId) {
|
|
12423
12455
|
const result = await this.supabaseClient
|
|
12424
12456
|
.from(this.getTableName('AgentHistory'))
|
|
12425
12457
|
.select('id, createdAt, agentHash, promptbookEngineVersion')
|
|
12426
|
-
.eq('
|
|
12458
|
+
.eq('permanentId', permanentId)
|
|
12427
12459
|
.order('createdAt', { ascending: false });
|
|
12428
12460
|
if (result.error) {
|
|
12429
12461
|
throw new DatabaseError(spaceTrim((block) => `
|
|
12430
|
-
Error listing history for agent "${
|
|
12462
|
+
Error listing history for agent "${permanentId}" from Supabase:
|
|
12431
12463
|
|
|
12432
12464
|
${block(result.error.message)}
|
|
12433
12465
|
`));
|
|
@@ -12437,15 +12469,15 @@ class AgentCollectionInSupabase /* TODO: [๐ฑโ๐] implements Agent */ {
|
|
|
12437
12469
|
/**
|
|
12438
12470
|
* Restore a soft-deleted agent by setting deletedAt to NULL
|
|
12439
12471
|
*/
|
|
12440
|
-
async restoreAgent(
|
|
12472
|
+
async restoreAgent(permanentId) {
|
|
12441
12473
|
const updateResult = await this.supabaseClient
|
|
12442
12474
|
.from(this.getTableName('Agent'))
|
|
12443
12475
|
.update({ deletedAt: null })
|
|
12444
|
-
.
|
|
12476
|
+
.eq('permanentId', permanentId)
|
|
12445
12477
|
.not('deletedAt', 'is', null);
|
|
12446
12478
|
if (updateResult.error) {
|
|
12447
12479
|
throw new DatabaseError(spaceTrim((block) => `
|
|
12448
|
-
Error restoring agent "${
|
|
12480
|
+
Error restoring agent "${permanentId}" from Supabase:
|
|
12449
12481
|
|
|
12450
12482
|
${block(updateResult.error.message)}
|
|
12451
12483
|
`));
|
|
@@ -12460,7 +12492,7 @@ class AgentCollectionInSupabase /* TODO: [๐ฑโ๐] implements Agent */ {
|
|
|
12460
12492
|
// First, get the history entry
|
|
12461
12493
|
const historyResult = await this.supabaseClient
|
|
12462
12494
|
.from(this.getTableName('AgentHistory'))
|
|
12463
|
-
.select('
|
|
12495
|
+
.select('permanentId, agentSource')
|
|
12464
12496
|
.eq('id', historyId)
|
|
12465
12497
|
.single();
|
|
12466
12498
|
if (historyResult.error) {
|
|
@@ -12473,22 +12505,22 @@ class AgentCollectionInSupabase /* TODO: [๐ฑโ๐] implements Agent */ {
|
|
|
12473
12505
|
if (!historyResult.data) {
|
|
12474
12506
|
throw new NotFoundError(`History entry with id "${historyId}" not found`);
|
|
12475
12507
|
}
|
|
12476
|
-
const {
|
|
12508
|
+
const { permanentId, agentSource } = historyResult.data;
|
|
12477
12509
|
// Update the agent with the source from the history entry
|
|
12478
|
-
await this.updateAgentSource(
|
|
12510
|
+
await this.updateAgentSource(permanentId, agentSource);
|
|
12479
12511
|
}
|
|
12480
12512
|
/**
|
|
12481
12513
|
* Soft delete an agent by setting deletedAt to current timestamp
|
|
12482
12514
|
*/
|
|
12483
|
-
async deleteAgent(
|
|
12515
|
+
async deleteAgent(permanentId) {
|
|
12484
12516
|
const updateResult = await this.supabaseClient
|
|
12485
12517
|
.from(this.getTableName('Agent'))
|
|
12486
12518
|
.update({ deletedAt: new Date().toISOString() })
|
|
12487
|
-
.
|
|
12519
|
+
.eq('permanentId', permanentId)
|
|
12488
12520
|
.is('deletedAt', null);
|
|
12489
12521
|
if (updateResult.error) {
|
|
12490
12522
|
throw new DatabaseError(spaceTrim((block) => `
|
|
12491
|
-
Error deleting agent "${
|
|
12523
|
+
Error deleting agent "${permanentId}" from Supabase:
|
|
12492
12524
|
|
|
12493
12525
|
${block(updateResult.error.message)}
|
|
12494
12526
|
`));
|