@promptbook/core 0.104.0-8 → 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 +77 -48
- 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/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/version.d.ts +1 -1
- package/package.json +1 -1
- package/umd/index.umd.js +77 -48
- 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 {
|
|
@@ -12241,20 +12246,35 @@ class AgentCollectionInSupabase /* TODO: [🐱🚀] implements Agent */ {
|
|
|
12241
12246
|
/**
|
|
12242
12247
|
* [🐱🚀]@@@
|
|
12243
12248
|
*/
|
|
12244
|
-
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) {
|
|
12245
12264
|
const selectResult = await this.supabaseClient
|
|
12246
12265
|
.from(this.getTableName('Agent'))
|
|
12247
12266
|
.select('agentSource')
|
|
12248
|
-
.or(`agentName.eq.${
|
|
12267
|
+
.or(`agentName.eq.${agentNameOrPermanentId},permanentId.eq.${agentNameOrPermanentId}`)
|
|
12268
|
+
.is('deletedAt', null);
|
|
12249
12269
|
if (selectResult.data && selectResult.data.length === 0) {
|
|
12250
|
-
throw new NotFoundError(`Agent "${
|
|
12270
|
+
throw new NotFoundError(`Agent "${agentNameOrPermanentId}" not found`);
|
|
12251
12271
|
}
|
|
12252
12272
|
else if (selectResult.data && selectResult.data.length > 1) {
|
|
12253
|
-
throw new UnexpectedError(`More agents with
|
|
12273
|
+
throw new UnexpectedError(`More agents with name or id "${agentNameOrPermanentId}" found`);
|
|
12254
12274
|
}
|
|
12255
12275
|
else if (selectResult.error) {
|
|
12256
12276
|
throw new DatabaseError(spaceTrim((block) => `
|
|
12257
|
-
Error fetching agent "${
|
|
12277
|
+
Error fetching agent "${agentNameOrPermanentId}" from Supabase:
|
|
12258
12278
|
|
|
12259
12279
|
${block(selectResult.error.message)}
|
|
12260
12280
|
`));
|
|
@@ -12269,19 +12289,19 @@ class AgentCollectionInSupabase /* TODO: [🐱🚀] implements Agent */ {
|
|
|
12269
12289
|
async createAgent(agentSource) {
|
|
12270
12290
|
let agentProfile = parseAgentSource(agentSource);
|
|
12271
12291
|
// <- TODO: [🕛]
|
|
12272
|
-
|
|
12292
|
+
// 1. Extract permanentId from the source if present
|
|
12273
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;
|
|
12274
12303
|
if (!permanentId) {
|
|
12275
12304
|
permanentId = $randomBase58(14);
|
|
12276
|
-
const lines = agentSource.split('\n');
|
|
12277
|
-
if (lines.length > 0) {
|
|
12278
|
-
lines.splice(1, 0, `META ID ${permanentId}`);
|
|
12279
|
-
agentSource = lines.join('\n');
|
|
12280
|
-
}
|
|
12281
|
-
else {
|
|
12282
|
-
agentSource = `META ID ${permanentId}\n${agentSource}`;
|
|
12283
|
-
}
|
|
12284
|
-
agentProfile = parseAgentSource(agentSource);
|
|
12285
12305
|
}
|
|
12286
12306
|
const insertAgentResult = await this.supabaseClient.from(this.getTableName('Agent')).insert({
|
|
12287
12307
|
agentName,
|
|
@@ -12304,6 +12324,7 @@ class AgentCollectionInSupabase /* TODO: [🐱🚀] implements Agent */ {
|
|
|
12304
12324
|
await this.supabaseClient.from(this.getTableName('AgentHistory')).insert({
|
|
12305
12325
|
createdAt: new Date().toISOString(),
|
|
12306
12326
|
agentName,
|
|
12327
|
+
permanentId,
|
|
12307
12328
|
agentHash,
|
|
12308
12329
|
previousAgentHash: null,
|
|
12309
12330
|
agentSource,
|
|
@@ -12315,17 +12336,17 @@ class AgentCollectionInSupabase /* TODO: [🐱🚀] implements Agent */ {
|
|
|
12315
12336
|
/**
|
|
12316
12337
|
* Updates an existing agent in the collection
|
|
12317
12338
|
*/
|
|
12318
|
-
async updateAgentSource(
|
|
12319
|
-
console.log('!!! updateAgentSource', {
|
|
12339
|
+
async updateAgentSource(permanentId, agentSource) {
|
|
12340
|
+
console.log('!!! updateAgentSource', { permanentId });
|
|
12320
12341
|
const selectPreviousAgentResult = await this.supabaseClient
|
|
12321
12342
|
.from(this.getTableName('Agent'))
|
|
12322
12343
|
.select('agentHash,agentName,permanentId')
|
|
12323
|
-
.eq('
|
|
12344
|
+
.eq('permanentId', permanentId)
|
|
12324
12345
|
.single();
|
|
12325
12346
|
if (selectPreviousAgentResult.error) {
|
|
12326
12347
|
throw new DatabaseError(spaceTrim((block) => `
|
|
12327
12348
|
|
|
12328
|
-
Error fetching agent "${
|
|
12349
|
+
Error fetching agent "${permanentId}" from Supabase:
|
|
12329
12350
|
|
|
12330
12351
|
${block(selectPreviousAgentResult.error.message)}
|
|
12331
12352
|
`));
|
|
@@ -12336,20 +12357,27 @@ class AgentCollectionInSupabase /* TODO: [🐱🚀] implements Agent */ {
|
|
|
12336
12357
|
const previousPermanentId = selectPreviousAgentResult.data.permanentId;
|
|
12337
12358
|
let agentProfile = parseAgentSource(agentSource);
|
|
12338
12359
|
// <- TODO: [🕛]
|
|
12339
|
-
|
|
12340
|
-
let { permanentId } = agentProfile;
|
|
12341
|
-
|
|
12342
|
-
|
|
12343
|
-
|
|
12344
|
-
|
|
12345
|
-
|
|
12346
|
-
|
|
12347
|
-
}
|
|
12348
|
-
else {
|
|
12349
|
-
agentSource = `META ID ${permanentId}\n${agentSource}`;
|
|
12350
|
-
}
|
|
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
|
|
12351
12368
|
agentProfile = parseAgentSource(agentSource);
|
|
12352
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
|
+
}
|
|
12353
12381
|
const updateAgentResult = await this.supabaseClient
|
|
12354
12382
|
.from(this.getTableName('Agent'))
|
|
12355
12383
|
.update({
|
|
@@ -12361,13 +12389,13 @@ class AgentCollectionInSupabase /* TODO: [🐱🚀] implements Agent */ {
|
|
|
12361
12389
|
agentSource,
|
|
12362
12390
|
promptbookEngineVersion: PROMPTBOOK_ENGINE_VERSION,
|
|
12363
12391
|
})
|
|
12364
|
-
.eq('
|
|
12392
|
+
.eq('permanentId', permanentId);
|
|
12365
12393
|
// console.log('[🐱🚀] updateAgent', updateResult);
|
|
12366
12394
|
// console.log('[🐱🚀] old', oldAgentSource);
|
|
12367
12395
|
// console.log('[🐱🚀] new', newAgentSource);
|
|
12368
12396
|
if (updateAgentResult.error) {
|
|
12369
12397
|
throw new DatabaseError(spaceTrim((block) => `
|
|
12370
|
-
Error updating agent "${
|
|
12398
|
+
Error updating agent "${permanentId}" in Supabase:
|
|
12371
12399
|
|
|
12372
12400
|
${block(updateAgentResult.error.message)}
|
|
12373
12401
|
`));
|
|
@@ -12375,6 +12403,7 @@ class AgentCollectionInSupabase /* TODO: [🐱🚀] implements Agent */ {
|
|
|
12375
12403
|
await this.supabaseClient.from(this.getTableName('AgentHistory')).insert({
|
|
12376
12404
|
createdAt: new Date().toISOString(),
|
|
12377
12405
|
agentName,
|
|
12406
|
+
permanentId,
|
|
12378
12407
|
agentHash,
|
|
12379
12408
|
previousAgentHash,
|
|
12380
12409
|
agentSource,
|
|
@@ -12382,7 +12411,7 @@ class AgentCollectionInSupabase /* TODO: [🐱🚀] implements Agent */ {
|
|
|
12382
12411
|
});
|
|
12383
12412
|
// <- TODO: [🧠] What to do with `insertAgentHistoryResult.error`, ignore? wait?
|
|
12384
12413
|
}
|
|
12385
|
-
// TODO: [🐱🚀] public async getAgentSourceSubject(
|
|
12414
|
+
// TODO: [🐱🚀] public async getAgentSourceSubject(permanentId: string_agent_permanent_id): Promise<BehaviorSubject<string_book>>
|
|
12386
12415
|
// Use Supabase realtime logic
|
|
12387
12416
|
/**
|
|
12388
12417
|
* List agents that are soft deleted (deletedAt IS NOT NULL)
|
|
@@ -12422,15 +12451,15 @@ class AgentCollectionInSupabase /* TODO: [🐱🚀] implements Agent */ {
|
|
|
12422
12451
|
/**
|
|
12423
12452
|
* List history of an agent
|
|
12424
12453
|
*/
|
|
12425
|
-
async listAgentHistory(
|
|
12454
|
+
async listAgentHistory(permanentId) {
|
|
12426
12455
|
const result = await this.supabaseClient
|
|
12427
12456
|
.from(this.getTableName('AgentHistory'))
|
|
12428
12457
|
.select('id, createdAt, agentHash, promptbookEngineVersion')
|
|
12429
|
-
.eq('
|
|
12458
|
+
.eq('permanentId', permanentId)
|
|
12430
12459
|
.order('createdAt', { ascending: false });
|
|
12431
12460
|
if (result.error) {
|
|
12432
12461
|
throw new DatabaseError(spaceTrim((block) => `
|
|
12433
|
-
Error listing history for agent "${
|
|
12462
|
+
Error listing history for agent "${permanentId}" from Supabase:
|
|
12434
12463
|
|
|
12435
12464
|
${block(result.error.message)}
|
|
12436
12465
|
`));
|
|
@@ -12440,15 +12469,15 @@ class AgentCollectionInSupabase /* TODO: [🐱🚀] implements Agent */ {
|
|
|
12440
12469
|
/**
|
|
12441
12470
|
* Restore a soft-deleted agent by setting deletedAt to NULL
|
|
12442
12471
|
*/
|
|
12443
|
-
async restoreAgent(
|
|
12472
|
+
async restoreAgent(permanentId) {
|
|
12444
12473
|
const updateResult = await this.supabaseClient
|
|
12445
12474
|
.from(this.getTableName('Agent'))
|
|
12446
12475
|
.update({ deletedAt: null })
|
|
12447
|
-
.
|
|
12476
|
+
.eq('permanentId', permanentId)
|
|
12448
12477
|
.not('deletedAt', 'is', null);
|
|
12449
12478
|
if (updateResult.error) {
|
|
12450
12479
|
throw new DatabaseError(spaceTrim((block) => `
|
|
12451
|
-
Error restoring agent "${
|
|
12480
|
+
Error restoring agent "${permanentId}" from Supabase:
|
|
12452
12481
|
|
|
12453
12482
|
${block(updateResult.error.message)}
|
|
12454
12483
|
`));
|
|
@@ -12463,7 +12492,7 @@ class AgentCollectionInSupabase /* TODO: [🐱🚀] implements Agent */ {
|
|
|
12463
12492
|
// First, get the history entry
|
|
12464
12493
|
const historyResult = await this.supabaseClient
|
|
12465
12494
|
.from(this.getTableName('AgentHistory'))
|
|
12466
|
-
.select('
|
|
12495
|
+
.select('permanentId, agentSource')
|
|
12467
12496
|
.eq('id', historyId)
|
|
12468
12497
|
.single();
|
|
12469
12498
|
if (historyResult.error) {
|
|
@@ -12476,22 +12505,22 @@ class AgentCollectionInSupabase /* TODO: [🐱🚀] implements Agent */ {
|
|
|
12476
12505
|
if (!historyResult.data) {
|
|
12477
12506
|
throw new NotFoundError(`History entry with id "${historyId}" not found`);
|
|
12478
12507
|
}
|
|
12479
|
-
const {
|
|
12508
|
+
const { permanentId, agentSource } = historyResult.data;
|
|
12480
12509
|
// Update the agent with the source from the history entry
|
|
12481
|
-
await this.updateAgentSource(
|
|
12510
|
+
await this.updateAgentSource(permanentId, agentSource);
|
|
12482
12511
|
}
|
|
12483
12512
|
/**
|
|
12484
12513
|
* Soft delete an agent by setting deletedAt to current timestamp
|
|
12485
12514
|
*/
|
|
12486
|
-
async deleteAgent(
|
|
12515
|
+
async deleteAgent(permanentId) {
|
|
12487
12516
|
const updateResult = await this.supabaseClient
|
|
12488
12517
|
.from(this.getTableName('Agent'))
|
|
12489
12518
|
.update({ deletedAt: new Date().toISOString() })
|
|
12490
|
-
.
|
|
12519
|
+
.eq('permanentId', permanentId)
|
|
12491
12520
|
.is('deletedAt', null);
|
|
12492
12521
|
if (updateResult.error) {
|
|
12493
12522
|
throw new DatabaseError(spaceTrim((block) => `
|
|
12494
|
-
Error deleting agent "${
|
|
12523
|
+
Error deleting agent "${permanentId}" from Supabase:
|
|
12495
12524
|
|
|
12496
12525
|
${block(updateResult.error.message)}
|
|
12497
12526
|
`));
|