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