@promptbook/wizard 0.106.0-0 → 0.108.0-0
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 +1178 -129
- package/esm/index.es.js.map +1 -1
- package/esm/typings/src/_packages/components.index.d.ts +4 -0
- package/esm/typings/src/_packages/markdown-utils.index.d.ts +2 -0
- package/esm/typings/src/_packages/types.index.d.ts +15 -1
- package/esm/typings/src/_packages/utils.index.d.ts +2 -2
- package/esm/typings/src/book-components/BookEditor/BookEditor.d.ts +26 -2
- package/esm/typings/src/book-components/Chat/types/ChatMessage.d.ts +10 -2
- package/esm/typings/src/book-components/Chat/utils/getChatMessageTimingDisplay.d.ts +26 -0
- package/esm/typings/src/book-components/Chat/utils/{getToolCallChipletText.d.ts → getToolCallChipletInfo.d.ts} +8 -8
- package/esm/typings/src/types/ToolCall.d.ts +76 -1
- package/esm/typings/src/utils/linguistic-hash/LinguisticHashLanguage.d.ts +41 -0
- package/esm/typings/src/utils/linguistic-hash/linguisticHash.d.ts +37 -0
- package/esm/typings/src/utils/linguistic-hash/linguisticHashTypes.d.ts +19 -0
- package/esm/typings/src/utils/linguistic-hash/linguisticHashWords.cs.d.ts +10 -0
- package/esm/typings/src/utils/linguistic-hash/linguisticHashWords.en.d.ts +10 -0
- package/esm/typings/src/utils/markdown/humanizeAiTextSources.d.ts +13 -0
- package/esm/typings/src/version.d.ts +1 -1
- package/package.json +2 -2
- package/umd/index.umd.js +1178 -129
- package/umd/index.umd.js.map +1 -1
- package/esm/typings/src/utils/misc/linguisticHash.d.ts +0 -9
- /package/esm/typings/src/utils/{misc → linguistic-hash}/linguisticHash.test.d.ts +0 -0
package/esm/index.es.js
CHANGED
|
@@ -37,7 +37,7 @@ const BOOK_LANGUAGE_VERSION = '2.0.0';
|
|
|
37
37
|
* @generated
|
|
38
38
|
* @see https://github.com/webgptorg/promptbook
|
|
39
39
|
*/
|
|
40
|
-
const PROMPTBOOK_ENGINE_VERSION = '0.
|
|
40
|
+
const PROMPTBOOK_ENGINE_VERSION = '0.108.0-0';
|
|
41
41
|
/**
|
|
42
42
|
* TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
|
|
43
43
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
@@ -6252,13 +6252,125 @@ function escapePromptParameterValue(value, options) {
|
|
|
6252
6252
|
return value.replace(pattern, '\\$&');
|
|
6253
6253
|
}
|
|
6254
6254
|
/**
|
|
6255
|
-
* Builds
|
|
6255
|
+
* Builds numeric parameter name used in prompt placeholders.
|
|
6256
6256
|
*
|
|
6257
6257
|
* @param index Zero-based parameter index.
|
|
6258
6258
|
*/
|
|
6259
|
-
function
|
|
6259
|
+
function buildNumericParameterName(index) {
|
|
6260
6260
|
return `${index + 1}`;
|
|
6261
6261
|
}
|
|
6262
|
+
/**
|
|
6263
|
+
* Builds alphabetic parameter name used in prompt placeholders.
|
|
6264
|
+
*
|
|
6265
|
+
* @param index Zero-based parameter index.
|
|
6266
|
+
*/
|
|
6267
|
+
function buildAlphabeticParameterName(index) {
|
|
6268
|
+
const alphabet = 'abcdefghijklmnopqrstuvwxyz';
|
|
6269
|
+
let result = '';
|
|
6270
|
+
let remaining = index;
|
|
6271
|
+
while (remaining >= 0) {
|
|
6272
|
+
result = alphabet[remaining % alphabet.length] + result;
|
|
6273
|
+
remaining = Math.floor(remaining / alphabet.length) - 1;
|
|
6274
|
+
}
|
|
6275
|
+
return result;
|
|
6276
|
+
}
|
|
6277
|
+
/**
|
|
6278
|
+
* Converts a positive integer into a Roman numeral string.
|
|
6279
|
+
*
|
|
6280
|
+
* @param value Positive integer value.
|
|
6281
|
+
*/
|
|
6282
|
+
function toRomanNumeral(value) {
|
|
6283
|
+
const romanTable = [
|
|
6284
|
+
{ symbol: 'M', value: 1000 },
|
|
6285
|
+
{ symbol: 'CM', value: 900 },
|
|
6286
|
+
{ symbol: 'D', value: 500 },
|
|
6287
|
+
{ symbol: 'CD', value: 400 },
|
|
6288
|
+
{ symbol: 'C', value: 100 },
|
|
6289
|
+
{ symbol: 'XC', value: 90 },
|
|
6290
|
+
{ symbol: 'L', value: 50 },
|
|
6291
|
+
{ symbol: 'XL', value: 40 },
|
|
6292
|
+
{ symbol: 'X', value: 10 },
|
|
6293
|
+
{ symbol: 'IX', value: 9 },
|
|
6294
|
+
{ symbol: 'V', value: 5 },
|
|
6295
|
+
{ symbol: 'IV', value: 4 },
|
|
6296
|
+
{ symbol: 'I', value: 1 },
|
|
6297
|
+
];
|
|
6298
|
+
let remaining = Math.max(1, Math.floor(value));
|
|
6299
|
+
let result = '';
|
|
6300
|
+
for (const entry of romanTable) {
|
|
6301
|
+
while (remaining >= entry.value) {
|
|
6302
|
+
result += entry.symbol;
|
|
6303
|
+
remaining -= entry.value;
|
|
6304
|
+
}
|
|
6305
|
+
}
|
|
6306
|
+
return result;
|
|
6307
|
+
}
|
|
6308
|
+
/**
|
|
6309
|
+
* Builds Roman numeral parameter name used in prompt placeholders.
|
|
6310
|
+
*
|
|
6311
|
+
* @param index Zero-based parameter index.
|
|
6312
|
+
*/
|
|
6313
|
+
function buildRomanParameterName(index) {
|
|
6314
|
+
return toRomanNumeral(index + 1);
|
|
6315
|
+
}
|
|
6316
|
+
/**
|
|
6317
|
+
* Creates a parameter name builder that prefixes another builder.
|
|
6318
|
+
*
|
|
6319
|
+
* @param prefix Prefix to add.
|
|
6320
|
+
* @param builder Base builder to wrap.
|
|
6321
|
+
*/
|
|
6322
|
+
function buildPrefixedParameterName(prefix, builder) {
|
|
6323
|
+
return (index) => `${prefix}${builder(index)}`;
|
|
6324
|
+
}
|
|
6325
|
+
/**
|
|
6326
|
+
* Ordered list of strategies for parameter naming.
|
|
6327
|
+
*/
|
|
6328
|
+
const PARAMETER_NAME_STRATEGIES = [
|
|
6329
|
+
{ buildName: buildNumericParameterName },
|
|
6330
|
+
{ buildName: buildAlphabeticParameterName },
|
|
6331
|
+
{ buildName: buildRomanParameterName },
|
|
6332
|
+
{ buildName: buildPrefixedParameterName('p', buildNumericParameterName) },
|
|
6333
|
+
{ buildName: buildPrefixedParameterName('p', buildAlphabeticParameterName) },
|
|
6334
|
+
];
|
|
6335
|
+
/**
|
|
6336
|
+
* Collects bracketed tokens from parameter values to avoid placeholder collisions.
|
|
6337
|
+
*
|
|
6338
|
+
* @param values Parameter values to scan.
|
|
6339
|
+
*/
|
|
6340
|
+
function collectBracketedParameterTokens(values) {
|
|
6341
|
+
const tokens = new Set();
|
|
6342
|
+
for (const value of values) {
|
|
6343
|
+
const pattern = /{(\w+)}/g;
|
|
6344
|
+
let match;
|
|
6345
|
+
while ((match = pattern.exec(value)) !== null) {
|
|
6346
|
+
const token = match[1];
|
|
6347
|
+
if (token) {
|
|
6348
|
+
tokens.add(token);
|
|
6349
|
+
}
|
|
6350
|
+
}
|
|
6351
|
+
}
|
|
6352
|
+
return tokens;
|
|
6353
|
+
}
|
|
6354
|
+
/**
|
|
6355
|
+
* Builds parameter names used in prompt placeholders while avoiding collisions.
|
|
6356
|
+
*
|
|
6357
|
+
* @param values Parameter values to scan for conflicting tokens.
|
|
6358
|
+
*/
|
|
6359
|
+
function buildParameterNames(values) {
|
|
6360
|
+
const count = values.length;
|
|
6361
|
+
if (count === 0) {
|
|
6362
|
+
return [];
|
|
6363
|
+
}
|
|
6364
|
+
const conflicts = collectBracketedParameterTokens(values);
|
|
6365
|
+
for (const strategy of PARAMETER_NAME_STRATEGIES) {
|
|
6366
|
+
const names = Array.from({ length: count }, (_, index) => strategy.buildName(index));
|
|
6367
|
+
const hasConflict = names.some((name) => conflicts.has(name));
|
|
6368
|
+
if (!hasConflict) {
|
|
6369
|
+
return names;
|
|
6370
|
+
}
|
|
6371
|
+
}
|
|
6372
|
+
return Array.from({ length: count }, (_, index) => `${REPLACING_NONCE}${index + 1}`);
|
|
6373
|
+
}
|
|
6262
6374
|
/**
|
|
6263
6375
|
* Formats the placeholder used in the prompt body for a parameter.
|
|
6264
6376
|
*
|
|
@@ -6313,26 +6425,40 @@ function prompt(strings, ...values) {
|
|
|
6313
6425
|
return new PromptString(spaceTrim$2(strings.join('')));
|
|
6314
6426
|
}
|
|
6315
6427
|
const stringsWithHiddenParameters = strings.map((stringsItem) => hideBrackets(stringsItem));
|
|
6316
|
-
const
|
|
6317
|
-
const name = buildParameterName(index);
|
|
6428
|
+
const parameterMetadata = values.map((value) => {
|
|
6318
6429
|
const isPrompt = isPromptString(value);
|
|
6319
6430
|
const stringValue = isPrompt ? value.toString() : valueToString(value);
|
|
6320
6431
|
const isInline = isPrompt ? true : shouldInlineParameterValue(stringValue);
|
|
6321
6432
|
const jsonValue = !isPrompt && !isInline ? normalizeJsonString(stringValue) : null;
|
|
6433
|
+
return { isPrompt, stringValue, isInline, jsonValue };
|
|
6434
|
+
});
|
|
6435
|
+
const parameterNames = buildParameterNames(parameterMetadata.map((entry) => entry.stringValue));
|
|
6436
|
+
const parameterEntries = parameterMetadata.map((entry, index) => {
|
|
6437
|
+
var _a;
|
|
6438
|
+
const name = (_a = parameterNames[index]) !== null && _a !== void 0 ? _a : buildNumericParameterName(index);
|
|
6322
6439
|
const promptMarker = `${REPLACING_NONCE}prompt-${index}`;
|
|
6323
6440
|
const parameterMarker = `${REPLACING_NONCE}parameter-${index}`;
|
|
6324
|
-
const templateValue = isPrompt
|
|
6441
|
+
const templateValue = entry.isPrompt
|
|
6325
6442
|
? promptMarker
|
|
6326
|
-
: isInline
|
|
6327
|
-
? escapePromptParameterValue(stringValue, { includeBraces: false })
|
|
6443
|
+
: entry.isInline
|
|
6444
|
+
? escapePromptParameterValue(entry.stringValue, { includeBraces: false })
|
|
6328
6445
|
: parameterMarker;
|
|
6329
|
-
return {
|
|
6446
|
+
return {
|
|
6447
|
+
name,
|
|
6448
|
+
stringValue: entry.stringValue,
|
|
6449
|
+
jsonValue: entry.jsonValue,
|
|
6450
|
+
isPrompt: entry.isPrompt,
|
|
6451
|
+
isInline: entry.isInline,
|
|
6452
|
+
promptMarker,
|
|
6453
|
+
parameterMarker,
|
|
6454
|
+
templateValue,
|
|
6455
|
+
};
|
|
6330
6456
|
});
|
|
6331
6457
|
const parameters = Object.fromEntries(parameterEntries.map((entry) => [entry.name, entry.templateValue]));
|
|
6332
|
-
const
|
|
6458
|
+
const parameterNamesOrdered = parameterEntries.map((entry) => entry.name);
|
|
6333
6459
|
// Combine strings and values
|
|
6334
6460
|
let pipelineString = stringsWithHiddenParameters.reduce((result, stringsItem, i) => {
|
|
6335
|
-
const parameterName =
|
|
6461
|
+
const parameterName = parameterNamesOrdered[i];
|
|
6336
6462
|
return parameterName === undefined
|
|
6337
6463
|
? `${result}${stringsItem}`
|
|
6338
6464
|
: `${result}${stringsItem}${formatParameterPlaceholder(parameterName)}`;
|
|
@@ -6345,7 +6471,7 @@ function prompt(strings, ...values) {
|
|
|
6345
6471
|
if (!(error instanceof PipelineExecutionError)) {
|
|
6346
6472
|
throw error;
|
|
6347
6473
|
}
|
|
6348
|
-
console.error({ pipelineString, parameters, parameterNames, error });
|
|
6474
|
+
console.error({ pipelineString, parameters, parameterNames: parameterNamesOrdered, error });
|
|
6349
6475
|
throw new UnexpectedError(spaceTrim$2((block) => `
|
|
6350
6476
|
Internal error in prompt template literal
|
|
6351
6477
|
|
|
@@ -6360,9 +6486,7 @@ function prompt(strings, ...values) {
|
|
|
6360
6486
|
continue;
|
|
6361
6487
|
}
|
|
6362
6488
|
if (!entry.isInline) {
|
|
6363
|
-
pipelineString = pipelineString
|
|
6364
|
-
.split(entry.parameterMarker)
|
|
6365
|
-
.join(formatParameterPlaceholder(entry.name));
|
|
6489
|
+
pipelineString = pipelineString.split(entry.parameterMarker).join(formatParameterPlaceholder(entry.name));
|
|
6366
6490
|
}
|
|
6367
6491
|
}
|
|
6368
6492
|
const structuredParameters = parameterEntries.filter((entry) => !entry.isPrompt && !entry.isInline);
|
|
@@ -6442,103 +6566,564 @@ function capitalize(word) {
|
|
|
6442
6566
|
return word.substring(0, 1).toUpperCase() + word.substring(1);
|
|
6443
6567
|
}
|
|
6444
6568
|
|
|
6569
|
+
// spell-checker: disable
|
|
6445
6570
|
/**
|
|
6446
|
-
*
|
|
6571
|
+
* @@@
|
|
6447
6572
|
*
|
|
6448
|
-
* @
|
|
6449
|
-
*/
|
|
6450
|
-
|
|
6451
|
-
|
|
6452
|
-
|
|
6453
|
-
|
|
6454
|
-
|
|
6455
|
-
|
|
6456
|
-
'
|
|
6457
|
-
'
|
|
6458
|
-
'
|
|
6459
|
-
'
|
|
6460
|
-
'
|
|
6461
|
-
'
|
|
6462
|
-
'
|
|
6463
|
-
'
|
|
6464
|
-
'
|
|
6465
|
-
'
|
|
6466
|
-
'
|
|
6467
|
-
'
|
|
6573
|
+
* @private utility of `linguisticHash`
|
|
6574
|
+
*/
|
|
6575
|
+
const ADJECTIVES$1 = [
|
|
6576
|
+
'červený',
|
|
6577
|
+
'modrý',
|
|
6578
|
+
'zelený',
|
|
6579
|
+
'žlutý',
|
|
6580
|
+
'rychlý',
|
|
6581
|
+
'pomalý',
|
|
6582
|
+
'jasný',
|
|
6583
|
+
'temný',
|
|
6584
|
+
'veselý',
|
|
6585
|
+
'smutný',
|
|
6586
|
+
'statečný',
|
|
6587
|
+
'klidný',
|
|
6588
|
+
'chytrý',
|
|
6589
|
+
'bystrý',
|
|
6590
|
+
'dychtivý',
|
|
6591
|
+
'honosný',
|
|
6592
|
+
'velkolepý',
|
|
6593
|
+
'hravý',
|
|
6594
|
+
'laskavý',
|
|
6595
|
+
'šťastný',
|
|
6596
|
+
'hrdý',
|
|
6597
|
+
'pošetilý',
|
|
6598
|
+
'moudrý',
|
|
6599
|
+
'mladý',
|
|
6600
|
+
'starý',
|
|
6601
|
+
'veliký',
|
|
6602
|
+
'malý',
|
|
6603
|
+
'drobný',
|
|
6604
|
+
'obrovský',
|
|
6605
|
+
'krátký',
|
|
6606
|
+
'dlouhý',
|
|
6607
|
+
'blízký',
|
|
6608
|
+
'vzdálený',
|
|
6609
|
+
'vnitřní',
|
|
6610
|
+
'vnější',
|
|
6611
|
+
'trpělivý',
|
|
6612
|
+
'stálý',
|
|
6613
|
+
'ušlechtilý',
|
|
6614
|
+
'čistý',
|
|
6615
|
+
'špinavý',
|
|
6616
|
+
'čerstvý',
|
|
6617
|
+
'zvětralý',
|
|
6618
|
+
'ostrý',
|
|
6619
|
+
'tupý',
|
|
6620
|
+
'tlustý',
|
|
6621
|
+
'tenký',
|
|
6622
|
+
'široký',
|
|
6623
|
+
'úzký',
|
|
6624
|
+
'hluboký',
|
|
6625
|
+
'mělký',
|
|
6626
|
+
'mocný',
|
|
6627
|
+
'jemný',
|
|
6628
|
+
'divoký',
|
|
6629
|
+
'tichý',
|
|
6630
|
+
'hlučný',
|
|
6631
|
+
'pokojný',
|
|
6632
|
+
'rušný',
|
|
6633
|
+
'prázdný',
|
|
6634
|
+
'plný',
|
|
6635
|
+
'kulatý',
|
|
6636
|
+
'hranatý',
|
|
6637
|
+
'plochý',
|
|
6638
|
+
'křivý',
|
|
6639
|
+
'tvrdý',
|
|
6640
|
+
'měkký',
|
|
6641
|
+
'teplý',
|
|
6642
|
+
'chladný',
|
|
6643
|
+
'sladký',
|
|
6644
|
+
'kyselý',
|
|
6645
|
+
'hořký',
|
|
6646
|
+
'slaný',
|
|
6647
|
+
'silný',
|
|
6648
|
+
'slabý',
|
|
6649
|
+
'pevný',
|
|
6650
|
+
'pružný',
|
|
6651
|
+
'křehký',
|
|
6652
|
+
'houževnatý',
|
|
6653
|
+
'lesklý',
|
|
6654
|
+
'matný',
|
|
6655
|
+
'kluzký',
|
|
6656
|
+
'lepkavý',
|
|
6657
|
+
'svěží',
|
|
6658
|
+
'vybledlý',
|
|
6659
|
+
'mlhavý',
|
|
6660
|
+
'bouřlivý',
|
|
6661
|
+
'slunný',
|
|
6662
|
+
'větrný',
|
|
6663
|
+
'deštivý',
|
|
6664
|
+
'mrazivý',
|
|
6665
|
+
'zlatý',
|
|
6666
|
+
'stříbrný',
|
|
6667
|
+
'ledový',
|
|
6668
|
+
'žhavý',
|
|
6669
|
+
'prastarý',
|
|
6670
|
+
'moderní',
|
|
6671
|
+
'skrytý',
|
|
6672
|
+
'ztracený',
|
|
6673
|
+
'nalezený',
|
|
6674
|
+
'magický',
|
|
6675
|
+
'tajemný',
|
|
6676
|
+
'kosmický',
|
|
6677
|
+
'hvězdný',
|
|
6678
|
+
'měsíční',
|
|
6679
|
+
'sluneční',
|
|
6680
|
+
'mlžný',
|
|
6681
|
+
'ranní',
|
|
6682
|
+
'večerní',
|
|
6683
|
+
'noční',
|
|
6684
|
+
'denní',
|
|
6685
|
+
'osamělý',
|
|
6686
|
+
'společenský',
|
|
6687
|
+
'soukromý',
|
|
6688
|
+
'veřejný',
|
|
6689
|
+
'tajný',
|
|
6690
|
+
'slavný',
|
|
6691
|
+
'jistý',
|
|
6692
|
+
'neurčitý',
|
|
6693
|
+
'prostý',
|
|
6694
|
+
'snadný',
|
|
6695
|
+
'krotký',
|
|
6696
|
+
'mírný',
|
|
6697
|
+
'horký',
|
|
6698
|
+
'suchý',
|
|
6699
|
+
'mokrý',
|
|
6700
|
+
'vlhký',
|
|
6701
|
+
'promočený',
|
|
6702
|
+
'vyprahlý',
|
|
6703
|
+
'hladový',
|
|
6704
|
+
'žíznivý',
|
|
6705
|
+
'ospalý',
|
|
6706
|
+
'bdělý',
|
|
6707
|
+
'unavený',
|
|
6708
|
+
'líný',
|
|
6709
|
+
'neklidný',
|
|
6710
|
+
'nestálý',
|
|
6711
|
+
'odvážný',
|
|
6712
|
+
'bázlivý',
|
|
6713
|
+
'upřímný',
|
|
6714
|
+
'věrný',
|
|
6715
|
+
'pravý',
|
|
6716
|
+
'falešný',
|
|
6717
|
+
'spravedlivý',
|
|
6718
|
+
'jednoduchý',
|
|
6719
|
+
'složitý',
|
|
6720
|
+
'přirozený',
|
|
6721
|
+
'umělý',
|
|
6722
|
+
'živý',
|
|
6723
|
+
'mrtvý',
|
|
6724
|
+
'zvídavý',
|
|
6725
|
+
'zvláštní',
|
|
6726
|
+
'běžný',
|
|
6727
|
+
'vzácný',
|
|
6728
|
+
'jedinečný',
|
|
6729
|
+
'základní',
|
|
6730
|
+
'prvotní',
|
|
6731
|
+
'hbitý',
|
|
6468
6732
|
];
|
|
6469
|
-
const
|
|
6470
|
-
|
|
6471
|
-
'
|
|
6472
|
-
'
|
|
6473
|
-
'
|
|
6474
|
-
'
|
|
6475
|
-
'
|
|
6476
|
-
'
|
|
6477
|
-
'
|
|
6478
|
-
'
|
|
6479
|
-
'
|
|
6480
|
-
'
|
|
6481
|
-
'
|
|
6482
|
-
'
|
|
6483
|
-
'
|
|
6484
|
-
'
|
|
6733
|
+
const NOUNS$1 = [
|
|
6734
|
+
'jablko',
|
|
6735
|
+
'nebe',
|
|
6736
|
+
'strom',
|
|
6737
|
+
'liška',
|
|
6738
|
+
'kočka',
|
|
6739
|
+
'pták',
|
|
6740
|
+
'pes',
|
|
6741
|
+
'řeka',
|
|
6742
|
+
'hora',
|
|
6743
|
+
'les',
|
|
6744
|
+
'oceán',
|
|
6745
|
+
'hvězda',
|
|
6746
|
+
'měsíc',
|
|
6747
|
+
'slunce',
|
|
6748
|
+
'mrak',
|
|
6749
|
+
'květ',
|
|
6750
|
+
'list',
|
|
6751
|
+
'kámen',
|
|
6752
|
+
'vítr',
|
|
6753
|
+
'déšť',
|
|
6754
|
+
'oheň',
|
|
6755
|
+
'led',
|
|
6756
|
+
'kniha',
|
|
6757
|
+
'sen',
|
|
6758
|
+
'píseň',
|
|
6759
|
+
'cesta',
|
|
6760
|
+
'brána',
|
|
6761
|
+
'klíč',
|
|
6762
|
+
'lampa',
|
|
6763
|
+
'mapa',
|
|
6764
|
+
'dům',
|
|
6765
|
+
'město',
|
|
6766
|
+
'most',
|
|
6767
|
+
'pole',
|
|
6768
|
+
'zahrada',
|
|
6769
|
+
'jezero',
|
|
6770
|
+
'pláž',
|
|
6771
|
+
'ostrov',
|
|
6772
|
+
'údolí',
|
|
6773
|
+
'poušť',
|
|
6774
|
+
'svět',
|
|
6775
|
+
'duch',
|
|
6776
|
+
'srdce',
|
|
6777
|
+
'mysl',
|
|
6778
|
+
'duše',
|
|
6779
|
+
'život',
|
|
6780
|
+
'čas',
|
|
6781
|
+
'prostor',
|
|
6782
|
+
'světlo',
|
|
6783
|
+
'stín',
|
|
6784
|
+
'zvuk',
|
|
6785
|
+
'hudba',
|
|
6786
|
+
'hlas',
|
|
6787
|
+
'slovo',
|
|
6788
|
+
'stránka',
|
|
6789
|
+
'příběh',
|
|
6790
|
+
'perla',
|
|
6791
|
+
'zlato',
|
|
6792
|
+
'stříbro',
|
|
6793
|
+
'krystal',
|
|
6794
|
+
'diamant',
|
|
6795
|
+
'smaragd',
|
|
6796
|
+
'rubín',
|
|
6797
|
+
'stezka',
|
|
6798
|
+
'vrchol',
|
|
6799
|
+
'břeh',
|
|
6800
|
+
'vlna',
|
|
6801
|
+
'příliv',
|
|
6802
|
+
'plamen',
|
|
6803
|
+
'jiskra',
|
|
6804
|
+
'paprsek',
|
|
6805
|
+
'semínko',
|
|
6806
|
+
'kořen',
|
|
6807
|
+
'větev',
|
|
6808
|
+
'pupen',
|
|
6809
|
+
'trn',
|
|
6810
|
+
'kůra',
|
|
6811
|
+
'skořápka',
|
|
6812
|
+
'pírko',
|
|
6813
|
+
'křídlo',
|
|
6814
|
+
'dráp',
|
|
6815
|
+
'tlapa',
|
|
6816
|
+
'hnízdo',
|
|
6817
|
+
'jeskyně',
|
|
6818
|
+
'hájek',
|
|
6819
|
+
'věž',
|
|
6820
|
+
'hrad',
|
|
6821
|
+
'koruna',
|
|
6822
|
+
'meč',
|
|
6823
|
+
'štít',
|
|
6824
|
+
'mince',
|
|
6825
|
+
'drahokam',
|
|
6826
|
+
'prsten',
|
|
6827
|
+
'zvonek',
|
|
6828
|
+
'hodiny',
|
|
6829
|
+
'kompas',
|
|
6830
|
+
'kotva',
|
|
6831
|
+
'pochodeň',
|
|
6832
|
+
'flétna',
|
|
6833
|
+
'harfa',
|
|
6834
|
+
'buben',
|
|
6835
|
+
'čočka',
|
|
6836
|
+
'sklo',
|
|
6837
|
+
'písek',
|
|
6838
|
+
'prach',
|
|
6839
|
+
'mlha',
|
|
6840
|
+
'rosa',
|
|
6841
|
+
'svítání',
|
|
6842
|
+
'soumrak',
|
|
6843
|
+
'noc',
|
|
6844
|
+
'den',
|
|
6845
|
+
'rok',
|
|
6846
|
+
'věk',
|
|
6847
|
+
'blesk',
|
|
6848
|
+
'kapka',
|
|
6849
|
+
'bouře',
|
|
6850
|
+
'sníh',
|
|
6851
|
+
'kroupa',
|
|
6852
|
+
'kouř',
|
|
6853
|
+
'pára',
|
|
6854
|
+
'plyn',
|
|
6855
|
+
'kov',
|
|
6856
|
+
'skála',
|
|
6857
|
+
'hlína',
|
|
6858
|
+
'sůl',
|
|
6859
|
+
'cukr',
|
|
6860
|
+
'dřevo',
|
|
6861
|
+
'kost',
|
|
6862
|
+
'kůže',
|
|
6863
|
+
'tělo',
|
|
6864
|
+
'krev',
|
|
6865
|
+
'buňka',
|
|
6866
|
+
'atom',
|
|
6867
|
+
'tep',
|
|
6868
|
+
'dech',
|
|
6869
|
+
'vzdech',
|
|
6870
|
+
'jméno',
|
|
6871
|
+
'ozvěna',
|
|
6872
|
+
'obraz',
|
|
6873
|
+
'vize',
|
|
6874
|
+
'myšlenka',
|
|
6875
|
+
'nápad',
|
|
6876
|
+
'plán',
|
|
6877
|
+
'cíl',
|
|
6878
|
+
'přání',
|
|
6879
|
+
'naděje',
|
|
6880
|
+
'strach',
|
|
6881
|
+
'radost',
|
|
6882
|
+
'láska',
|
|
6883
|
+
'nenávist',
|
|
6884
|
+
'vůle',
|
|
6885
|
+
'síla',
|
|
6886
|
+
'energie',
|
|
6887
|
+
'pohyb',
|
|
6888
|
+
'rychlost',
|
|
6889
|
+
'místo',
|
|
6890
|
+
'bod',
|
|
6891
|
+
'linie',
|
|
6892
|
+
'tvar',
|
|
6893
|
+
'forma',
|
|
6894
|
+
'velikost',
|
|
6895
|
+
'hmota',
|
|
6896
|
+
'váha',
|
|
6897
|
+
'teplo',
|
|
6898
|
+
'chlad',
|
|
6899
|
+
'barva',
|
|
6900
|
+
'tón',
|
|
6901
|
+
'rytmus',
|
|
6902
|
+
'nálada',
|
|
6903
|
+
'stav',
|
|
6904
|
+
'krok',
|
|
6905
|
+
'pád',
|
|
6906
|
+
'skok',
|
|
6907
|
+
'běh',
|
|
6908
|
+
'let',
|
|
6909
|
+
'klid',
|
|
6910
|
+
'úkol',
|
|
6911
|
+
'práce',
|
|
6912
|
+
'hra',
|
|
6913
|
+
'sport',
|
|
6914
|
+
'umění',
|
|
6915
|
+
'řemeslo',
|
|
6916
|
+
'nástroj',
|
|
6917
|
+
'loď',
|
|
6918
|
+
'člun',
|
|
6919
|
+
'auto',
|
|
6920
|
+
'kolo',
|
|
6921
|
+
'vlak',
|
|
6922
|
+
'letadlo',
|
|
6923
|
+
'uzel',
|
|
6924
|
+
'síť',
|
|
6925
|
+
'krabice',
|
|
6926
|
+
'taška',
|
|
6927
|
+
'dóza',
|
|
6928
|
+
'hrnek',
|
|
6929
|
+
'miska',
|
|
6930
|
+
'talíř',
|
|
6931
|
+
'lžíce',
|
|
6932
|
+
'vidlička',
|
|
6933
|
+
'nůž',
|
|
6934
|
+
'pánev',
|
|
6935
|
+
'hrnec',
|
|
6936
|
+
'postel',
|
|
6937
|
+
'stůl',
|
|
6938
|
+
'židle',
|
|
6939
|
+
'dveře',
|
|
6940
|
+
'stěna',
|
|
6941
|
+
'střecha',
|
|
6942
|
+
'podlaha',
|
|
6943
|
+
'okno',
|
|
6944
|
+
'chodba',
|
|
6485
6945
|
];
|
|
6486
|
-
const
|
|
6487
|
-
|
|
6488
|
-
|
|
6489
|
-
|
|
6490
|
-
|
|
6946
|
+
const VERBS$1 = [
|
|
6947
|
+
'skáče',
|
|
6948
|
+
'tančí',
|
|
6949
|
+
'letí',
|
|
6950
|
+
'běží',
|
|
6951
|
+
'zpívá',
|
|
6952
|
+
'svítí',
|
|
6953
|
+
'roste',
|
|
6954
|
+
'plyne',
|
|
6955
|
+
'padá',
|
|
6956
|
+
'stoupá',
|
|
6957
|
+
'spí',
|
|
6958
|
+
'kráčí',
|
|
6959
|
+
'mluví',
|
|
6960
|
+
'myslí',
|
|
6961
|
+
'sní',
|
|
6962
|
+
'hledá',
|
|
6963
|
+
'nachází',
|
|
6964
|
+
'dává',
|
|
6965
|
+
'bere',
|
|
6966
|
+
'tvoří',
|
|
6967
|
+
'hoří',
|
|
6968
|
+
'mrzne',
|
|
6969
|
+
'taje',
|
|
6970
|
+
'dýchá',
|
|
6971
|
+
'pulzuje',
|
|
6972
|
+
'bije',
|
|
6973
|
+
'žije',
|
|
6974
|
+
'učí',
|
|
6975
|
+
'ví',
|
|
6976
|
+
'skrývá',
|
|
6977
|
+
'ukazuje',
|
|
6978
|
+
'láme',
|
|
6979
|
+
'opravuje',
|
|
6980
|
+
'ztrácí',
|
|
6981
|
+
'nalézá',
|
|
6982
|
+
'začíná',
|
|
6983
|
+
'končí',
|
|
6984
|
+
'plave',
|
|
6985
|
+
'pluje',
|
|
6986
|
+
'klouže',
|
|
6987
|
+
'točí',
|
|
6988
|
+
'mění',
|
|
6989
|
+
'bledne',
|
|
6990
|
+
'mizí',
|
|
6991
|
+
'rodí',
|
|
6992
|
+
'hučí',
|
|
6993
|
+
'pláče',
|
|
6994
|
+
'závodí',
|
|
6995
|
+
'plíží',
|
|
6996
|
+
'sleduje',
|
|
6997
|
+
'slyší',
|
|
6998
|
+
'cítí',
|
|
6999
|
+
'touží',
|
|
7000
|
+
'doufá',
|
|
7001
|
+
'miluje',
|
|
7002
|
+
'bloudí',
|
|
7003
|
+
'putuje',
|
|
7004
|
+
'cestuje',
|
|
7005
|
+
'překračuje',
|
|
7006
|
+
'potkává',
|
|
7007
|
+
'drží',
|
|
7008
|
+
'sdílí',
|
|
7009
|
+
'jiskří',
|
|
7010
|
+
'plápolá',
|
|
7011
|
+
'léčí',
|
|
7012
|
+
'řeší',
|
|
7013
|
+
'otevírá',
|
|
7014
|
+
'zavírá',
|
|
7015
|
+
'zvedá',
|
|
7016
|
+
'táhne',
|
|
7017
|
+
'tlačí',
|
|
7018
|
+
'hází',
|
|
7019
|
+
'chytá',
|
|
7020
|
+
'dělá',
|
|
7021
|
+
'vidí',
|
|
7022
|
+
'chutná',
|
|
7023
|
+
'voní',
|
|
7024
|
+
'spěchá',
|
|
7025
|
+
'zastaví',
|
|
7026
|
+
'jde',
|
|
7027
|
+
'přichází',
|
|
7028
|
+
'odchází',
|
|
7029
|
+
'jedná',
|
|
7030
|
+
'existuje',
|
|
7031
|
+
'zmenšuje',
|
|
7032
|
+
'rozšiřuje',
|
|
7033
|
+
'zužuje',
|
|
7034
|
+
'hřeje',
|
|
7035
|
+
'chladí',
|
|
7036
|
+
'suší',
|
|
7037
|
+
'máčí',
|
|
7038
|
+
'plní',
|
|
7039
|
+
'vyprazdňuje',
|
|
7040
|
+
'pouští',
|
|
7041
|
+
'získává',
|
|
7042
|
+
'vítězí',
|
|
7043
|
+
'selhává',
|
|
7044
|
+
'zkouší',
|
|
7045
|
+
'používá',
|
|
7046
|
+
'dostává',
|
|
7047
|
+
'měří',
|
|
7048
|
+
'stojí',
|
|
7049
|
+
'dosahuje',
|
|
7050
|
+
'míjí',
|
|
7051
|
+
'udeří',
|
|
7052
|
+
'vede',
|
|
7053
|
+
'následuje',
|
|
7054
|
+
'pomáhá',
|
|
7055
|
+
'slouží',
|
|
7056
|
+
'trénuje',
|
|
7057
|
+
'kóduje',
|
|
7058
|
+
'píše',
|
|
7059
|
+
'čte',
|
|
7060
|
+
'kreslí',
|
|
7061
|
+
'maluje',
|
|
7062
|
+
'tvaruje',
|
|
7063
|
+
'spojuje',
|
|
7064
|
+
'dělí',
|
|
7065
|
+
'váže',
|
|
7066
|
+
'zraňuje',
|
|
7067
|
+
'chrání',
|
|
7068
|
+
'bojuje',
|
|
7069
|
+
'brání',
|
|
7070
|
+
'útočí',
|
|
7071
|
+
'uniká',
|
|
7072
|
+
'lapá',
|
|
7073
|
+
'osvobozuje',
|
|
7074
|
+
'poutá',
|
|
7075
|
+
'spřádá',
|
|
7076
|
+
'tká',
|
|
7077
|
+
'vrhá',
|
|
7078
|
+
'nese',
|
|
7079
|
+
'přenáší',
|
|
7080
|
+
'vrací',
|
|
7081
|
+
'zrychluje',
|
|
7082
|
+
'zpomaluje',
|
|
7083
|
+
'probouzí',
|
|
7084
|
+
'uspává',
|
|
7085
|
+
'šeptá',
|
|
7086
|
+
'volá',
|
|
7087
|
+
'hledí',
|
|
7088
|
+
'čeká',
|
|
7089
|
+
'bdí',
|
|
7090
|
+
'rozkvétá',
|
|
7091
|
+
'klíčí',
|
|
7092
|
+
'zraje',
|
|
7093
|
+
'chvěje',
|
|
7094
|
+
'třpytí',
|
|
7095
|
+
'shromažďuje',
|
|
7096
|
+
'rozhazuje',
|
|
7097
|
+
'tápe',
|
|
7098
|
+
'žhne',
|
|
7099
|
+
'vibruje',
|
|
7100
|
+
'šumí',
|
|
7101
|
+
'stéká',
|
|
7102
|
+
'vypráví',
|
|
7103
|
+
'plánuje',
|
|
7104
|
+
'počítá',
|
|
7105
|
+
'váhá',
|
|
7106
|
+
'riskuje',
|
|
6491
7107
|
];
|
|
6492
7108
|
/**
|
|
6493
|
-
*
|
|
6494
|
-
|
|
6495
|
-
|
|
6496
|
-
const expandedHash = `${hash}${hash}`;
|
|
6497
|
-
const start = (segmentIndex * HASH_SEGMENT_LENGTH + segmentIndex) % hash.length;
|
|
6498
|
-
return parseInt(expandedHash.substring(start, start + HASH_SEGMENT_LENGTH), 16);
|
|
6499
|
-
}
|
|
6500
|
-
/**
|
|
6501
|
-
* Picks a deterministic item from a list based on the hash seed.
|
|
6502
|
-
*/
|
|
6503
|
-
function pickFromHash(hash, segmentIndex, list) {
|
|
6504
|
-
const seed = getHashSeed(hash, segmentIndex);
|
|
6505
|
-
return list[seed % list.length];
|
|
6506
|
-
}
|
|
6507
|
-
/**
|
|
6508
|
-
* Index constants for story part selection to avoid magic numbers.
|
|
6509
|
-
*/
|
|
6510
|
-
const ADJECTIVE3_INDEX = 9;
|
|
6511
|
-
const NOUN3_INDEX = 10;
|
|
6512
|
-
/**
|
|
6513
|
-
* Creates the deterministic story parts used by the sentence templates.
|
|
7109
|
+
* Czech word lists used by the linguistic hash.
|
|
7110
|
+
*
|
|
7111
|
+
* @private utility of `linguisticHash`
|
|
6514
7112
|
*/
|
|
6515
|
-
|
|
6516
|
-
|
|
6517
|
-
|
|
6518
|
-
|
|
6519
|
-
|
|
6520
|
-
adjective1: pickFromHash(hash, 3, ADJECTIVES),
|
|
6521
|
-
noun1: pickFromHash(hash, 4, NOUNS),
|
|
6522
|
-
verb1: pickFromHash(hash, 5, VERBS),
|
|
6523
|
-
adjective2: pickFromHash(hash, 6, ADJECTIVES),
|
|
6524
|
-
noun2: pickFromHash(hash, 7, NOUNS),
|
|
6525
|
-
verb2: pickFromHash(hash, 8, VERBS),
|
|
6526
|
-
adjective3: pickFromHash(hash, ADJECTIVE3_INDEX, ADJECTIVES),
|
|
6527
|
-
noun3: pickFromHash(hash, NOUN3_INDEX, NOUNS),
|
|
6528
|
-
};
|
|
6529
|
-
}
|
|
7113
|
+
const LINGUISTIC_HASH_WORD_LISTS_CS = {
|
|
7114
|
+
adjective: ADJECTIVES$1,
|
|
7115
|
+
noun: NOUNS$1,
|
|
7116
|
+
verb: VERBS$1,
|
|
7117
|
+
};
|
|
6530
7118
|
/**
|
|
6531
|
-
*
|
|
7119
|
+
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
6532
7120
|
*/
|
|
6533
|
-
|
|
7121
|
+
|
|
6534
7122
|
/**
|
|
6535
|
-
*
|
|
7123
|
+
* @@@
|
|
7124
|
+
*
|
|
7125
|
+
* @private utility of `linguisticHash`
|
|
6536
7126
|
*/
|
|
6537
|
-
function createStorySentence(hash) {
|
|
6538
|
-
const parts = createStoryParts(hash);
|
|
6539
|
-
const template = pickFromHash(hash, STORY_TEMPLATE_INDEX, STORY_TEMPLATES);
|
|
6540
|
-
return template(parts).trim();
|
|
6541
|
-
}
|
|
6542
7127
|
const ADJECTIVES = [
|
|
6543
7128
|
'red',
|
|
6544
7129
|
'blue',
|
|
@@ -7213,8 +7798,203 @@ const VERBS = [
|
|
|
7213
7798
|
'spinning',
|
|
7214
7799
|
];
|
|
7215
7800
|
/**
|
|
7216
|
-
*
|
|
7801
|
+
* English word lists used by the linguistic hash.
|
|
7802
|
+
*
|
|
7803
|
+
* @private utility of `linguisticHash`
|
|
7804
|
+
*/
|
|
7805
|
+
const LINGUISTIC_HASH_WORD_LISTS_EN = {
|
|
7806
|
+
adjective: ADJECTIVES,
|
|
7807
|
+
noun: NOUNS,
|
|
7808
|
+
verb: VERBS,
|
|
7809
|
+
};
|
|
7810
|
+
/**
|
|
7811
|
+
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
7812
|
+
*/
|
|
7813
|
+
|
|
7814
|
+
/**
|
|
7815
|
+
* Default language used for linguistic hashes.
|
|
7816
|
+
*
|
|
7817
|
+
* @private utility of `linguisticHash`
|
|
7818
|
+
*/
|
|
7819
|
+
const DEFAULT_LINGUISTIC_HASH_LANGUAGE = 'en';
|
|
7820
|
+
/**
|
|
7821
|
+
* @@@
|
|
7822
|
+
*
|
|
7823
|
+
* @private utility of `linguisticHash`
|
|
7824
|
+
*/
|
|
7825
|
+
const LANGUAGE_CONFIGS = {
|
|
7826
|
+
en: {
|
|
7827
|
+
language: 'en',
|
|
7828
|
+
label: 'English',
|
|
7829
|
+
wordLists: LINGUISTIC_HASH_WORD_LISTS_EN,
|
|
7830
|
+
},
|
|
7831
|
+
cs: {
|
|
7832
|
+
language: 'cs',
|
|
7833
|
+
label: 'Czech',
|
|
7834
|
+
wordLists: LINGUISTIC_HASH_WORD_LISTS_CS,
|
|
7835
|
+
},
|
|
7836
|
+
};
|
|
7837
|
+
/**
|
|
7838
|
+
* Normalizes a requested language to a supported linguistic hash language.
|
|
7839
|
+
*
|
|
7840
|
+
* @private utility of `linguisticHash`
|
|
7841
|
+
*/
|
|
7842
|
+
function normalizeLinguisticHashLanguage(language) {
|
|
7843
|
+
if (typeof language !== 'string') {
|
|
7844
|
+
return DEFAULT_LINGUISTIC_HASH_LANGUAGE;
|
|
7845
|
+
}
|
|
7846
|
+
const normalized = language.trim().toLowerCase();
|
|
7847
|
+
if (normalized === 'cs') {
|
|
7848
|
+
return 'cs';
|
|
7849
|
+
}
|
|
7850
|
+
if (normalized === 'en') {
|
|
7851
|
+
return 'en';
|
|
7852
|
+
}
|
|
7853
|
+
return DEFAULT_LINGUISTIC_HASH_LANGUAGE;
|
|
7854
|
+
}
|
|
7855
|
+
/**
|
|
7856
|
+
* Returns the language configuration for linguistic hash generation.
|
|
7857
|
+
*
|
|
7858
|
+
* @private utility of `linguisticHash`
|
|
7859
|
+
*/
|
|
7860
|
+
function getLinguisticHashLanguageConfig(language) {
|
|
7861
|
+
const normalized = normalizeLinguisticHashLanguage(language);
|
|
7862
|
+
return LANGUAGE_CONFIGS[normalized];
|
|
7863
|
+
}
|
|
7864
|
+
|
|
7865
|
+
// <- TODO: !!!! Remove re-exports
|
|
7866
|
+
/**
|
|
7867
|
+
* Creates a human-readable hash as a short, story-like phrase.
|
|
7868
|
+
*
|
|
7869
|
+
* @param wordCount how many words to include (defaults to {@link DEFAULT_LINGUISTIC_HASH_WORD_COUNT}, clamped to
|
|
7870
|
+
* {@link MIN_LINGUISTIC_HASH_WORD_COUNT}..{@link MAX_LINGUISTIC_HASH_WORD_COUNT})
|
|
7871
|
+
* @param language optional language code (defaults to {@link DEFAULT_LINGUISTIC_HASH_LANGUAGE})
|
|
7872
|
+
*
|
|
7873
|
+
* @public exported from `@promptbook/utils`
|
|
7874
|
+
*/
|
|
7875
|
+
async function linguisticHash(input, wordCount, language) {
|
|
7876
|
+
const hash = computeHash(input);
|
|
7877
|
+
const normalizedWordCount = normalizeLinguisticHashWordCount(wordCount);
|
|
7878
|
+
const languageConfig = getLinguisticHashLanguageConfig(language);
|
|
7879
|
+
const words = createLinguisticHashWords(hash, normalizedWordCount, languageConfig.wordLists);
|
|
7880
|
+
return capitalize(words.join(' '));
|
|
7881
|
+
}
|
|
7882
|
+
/**
|
|
7883
|
+
* @@@
|
|
7884
|
+
*
|
|
7885
|
+
* @private utility of `linguisticHash`
|
|
7886
|
+
*/
|
|
7887
|
+
const HASH_SEGMENT_LENGTH = 8;
|
|
7888
|
+
/**
|
|
7889
|
+
* The minimum number of words for a linguistic hash.
|
|
7890
|
+
*
|
|
7891
|
+
* @private utility of `linguisticHash`
|
|
7892
|
+
*/
|
|
7893
|
+
const MIN_LINGUISTIC_HASH_WORD_COUNT = 1;
|
|
7894
|
+
/**
|
|
7895
|
+
* The default number of words for a linguistic hash.
|
|
7896
|
+
*
|
|
7897
|
+
* @private utility of `linguisticHash`
|
|
7898
|
+
*/
|
|
7899
|
+
const DEFAULT_LINGUISTIC_HASH_WORD_COUNT = 7;
|
|
7900
|
+
/**
|
|
7901
|
+
* Extracts a deterministic numeric seed from a SHA-256 hash.
|
|
7902
|
+
*
|
|
7903
|
+
* @private utility of `linguisticHash`
|
|
7904
|
+
*/
|
|
7905
|
+
function getHashSeed(hash, segmentIndex) {
|
|
7906
|
+
const expandedHash = `${hash}${hash}`;
|
|
7907
|
+
const start = (segmentIndex * HASH_SEGMENT_LENGTH + segmentIndex) % hash.length;
|
|
7908
|
+
return parseInt(expandedHash.substring(start, start + HASH_SEGMENT_LENGTH), 16);
|
|
7909
|
+
}
|
|
7910
|
+
/**
|
|
7911
|
+
* Picks a deterministic item from a list based on the hash seed.
|
|
7912
|
+
*
|
|
7913
|
+
* @private utility of `linguisticHash`
|
|
7914
|
+
*/
|
|
7915
|
+
function pickFromHash(hash, segmentIndex, list) {
|
|
7916
|
+
const seed = getHashSeed(hash, segmentIndex);
|
|
7917
|
+
return list[seed % list.length];
|
|
7918
|
+
}
|
|
7919
|
+
/**
|
|
7920
|
+
* Ordered word kinds used to build the linguistic hash output.
|
|
7921
|
+
*
|
|
7922
|
+
* @private utility of `linguisticHash`
|
|
7923
|
+
*/
|
|
7924
|
+
const WORD_SEQUENCE = [
|
|
7925
|
+
'adjective',
|
|
7926
|
+
'noun',
|
|
7927
|
+
'verb',
|
|
7928
|
+
'adjective',
|
|
7929
|
+
'noun',
|
|
7930
|
+
'verb',
|
|
7931
|
+
'adjective',
|
|
7932
|
+
'noun',
|
|
7933
|
+
'verb',
|
|
7934
|
+
'adjective',
|
|
7935
|
+
'noun',
|
|
7936
|
+
'verb',
|
|
7937
|
+
'adjective',
|
|
7938
|
+
'noun',
|
|
7939
|
+
'verb',
|
|
7940
|
+
'adjective',
|
|
7941
|
+
'noun',
|
|
7942
|
+
'verb',
|
|
7943
|
+
'adjective',
|
|
7944
|
+
'noun',
|
|
7945
|
+
];
|
|
7946
|
+
/**
|
|
7947
|
+
* The maximum number of words for a linguistic hash.
|
|
7948
|
+
*
|
|
7949
|
+
* @private utility of `linguisticHash`
|
|
7950
|
+
*/
|
|
7951
|
+
const MAX_LINGUISTIC_HASH_WORD_COUNT = WORD_SEQUENCE.length;
|
|
7952
|
+
/**
|
|
7953
|
+
* Index of the noun used for single-word hashes.
|
|
7954
|
+
*
|
|
7955
|
+
* @private utility of `linguisticHash`
|
|
7956
|
+
*/
|
|
7957
|
+
const SINGLE_WORD_INDEX = 1;
|
|
7958
|
+
/**
|
|
7959
|
+
* Normalizes the word count to a supported integer range.
|
|
7960
|
+
*
|
|
7961
|
+
* @private utility of `linguisticHash`
|
|
7962
|
+
*/
|
|
7963
|
+
function normalizeLinguisticHashWordCount(wordCount) {
|
|
7964
|
+
if (typeof wordCount !== 'number' || !Number.isFinite(wordCount)) {
|
|
7965
|
+
return DEFAULT_LINGUISTIC_HASH_WORD_COUNT;
|
|
7966
|
+
}
|
|
7967
|
+
const rounded = Math.round(wordCount);
|
|
7968
|
+
return Math.min(MAX_LINGUISTIC_HASH_WORD_COUNT, Math.max(MIN_LINGUISTIC_HASH_WORD_COUNT, rounded));
|
|
7969
|
+
}
|
|
7970
|
+
/**
|
|
7971
|
+
* Picks a deterministic word from the hash by kind.
|
|
7972
|
+
*
|
|
7973
|
+
* @private utility of `linguisticHash`
|
|
7974
|
+
*/
|
|
7975
|
+
function pickWordFromHash(hash, segmentIndex, wordKind, wordLists) {
|
|
7976
|
+
return pickFromHash(hash, segmentIndex, wordLists[wordKind]);
|
|
7977
|
+
}
|
|
7978
|
+
/**
|
|
7979
|
+
* Creates the deterministic word sequence used for the linguistic hash output.
|
|
7980
|
+
*
|
|
7981
|
+
* @private utility of `linguisticHash`
|
|
7982
|
+
*/
|
|
7983
|
+
function createLinguisticHashWordSequence(hash, wordLists) {
|
|
7984
|
+
return WORD_SEQUENCE.map((wordKind, index) => pickWordFromHash(hash, index, wordKind, wordLists));
|
|
7985
|
+
}
|
|
7986
|
+
/**
|
|
7987
|
+
* Selects the requested number of words from the hash output.
|
|
7988
|
+
*
|
|
7989
|
+
* @private utility of `linguisticHash`
|
|
7217
7990
|
*/
|
|
7991
|
+
function createLinguisticHashWords(hash, wordCount, wordLists) {
|
|
7992
|
+
const words = createLinguisticHashWordSequence(hash, wordLists);
|
|
7993
|
+
if (wordCount === 1) {
|
|
7994
|
+
return [words[SINGLE_WORD_INDEX]];
|
|
7995
|
+
}
|
|
7996
|
+
return words.slice(0, wordCount);
|
|
7997
|
+
}
|
|
7218
7998
|
|
|
7219
7999
|
/**
|
|
7220
8000
|
* Function parseNumber will parse number from string
|
|
@@ -9828,17 +10608,32 @@ class OpenAiAssistantExecutionTools extends OpenAiExecutionTools {
|
|
|
9828
10608
|
});
|
|
9829
10609
|
}
|
|
9830
10610
|
async createNewAssistant(options) {
|
|
10611
|
+
var _a, _b, _c;
|
|
9831
10612
|
if (!this.isCreatingNewAssistantsAllowed) {
|
|
9832
10613
|
throw new NotAllowed(`Creating new assistants is not allowed. Set \`isCreatingNewAssistantsAllowed: true\` in options to enable this feature.`);
|
|
9833
10614
|
}
|
|
9834
10615
|
// await this.playground();
|
|
9835
10616
|
const { name, instructions, knowledgeSources, tools } = options;
|
|
10617
|
+
const preparationStartedAtMs = Date.now();
|
|
10618
|
+
const knowledgeSourcesCount = (_a = knowledgeSources === null || knowledgeSources === void 0 ? void 0 : knowledgeSources.length) !== null && _a !== void 0 ? _a : 0;
|
|
10619
|
+
const toolsCount = (_b = tools === null || tools === void 0 ? void 0 : tools.length) !== null && _b !== void 0 ? _b : 0;
|
|
10620
|
+
if (this.options.isVerbose) {
|
|
10621
|
+
console.info('[🤰]', 'Starting OpenAI assistant creation', {
|
|
10622
|
+
name,
|
|
10623
|
+
knowledgeSourcesCount,
|
|
10624
|
+
toolsCount,
|
|
10625
|
+
instructionsLength: instructions.length,
|
|
10626
|
+
});
|
|
10627
|
+
}
|
|
9836
10628
|
const client = await this.getClient();
|
|
9837
10629
|
let vectorStoreId;
|
|
9838
10630
|
// If knowledge sources are provided, create a vector store with them
|
|
9839
10631
|
if (knowledgeSources && knowledgeSources.length > 0) {
|
|
9840
10632
|
if (this.options.isVerbose) {
|
|
9841
|
-
console.info(
|
|
10633
|
+
console.info('[🤰]', 'Creating vector store with knowledge sources', {
|
|
10634
|
+
name,
|
|
10635
|
+
knowledgeSourcesCount,
|
|
10636
|
+
});
|
|
9842
10637
|
}
|
|
9843
10638
|
// Create a vector store
|
|
9844
10639
|
const vectorStore = await client.beta.vectorStores.create({
|
|
@@ -9846,12 +10641,22 @@ class OpenAiAssistantExecutionTools extends OpenAiExecutionTools {
|
|
|
9846
10641
|
});
|
|
9847
10642
|
vectorStoreId = vectorStore.id;
|
|
9848
10643
|
if (this.options.isVerbose) {
|
|
9849
|
-
console.info(
|
|
10644
|
+
console.info('[🤰]', 'Vector store created', {
|
|
10645
|
+
vectorStoreId,
|
|
10646
|
+
});
|
|
9850
10647
|
}
|
|
9851
10648
|
// Upload files from knowledge sources to the vector store
|
|
9852
10649
|
const fileStreams = [];
|
|
9853
|
-
for (const source of knowledgeSources) {
|
|
10650
|
+
for (const [index, source] of knowledgeSources.entries()) {
|
|
9854
10651
|
try {
|
|
10652
|
+
if (this.options.isVerbose) {
|
|
10653
|
+
console.info('[🤰]', 'Processing knowledge source', {
|
|
10654
|
+
index: index + 1,
|
|
10655
|
+
total: knowledgeSources.length,
|
|
10656
|
+
source,
|
|
10657
|
+
sourceType: source.startsWith('http') || source.startsWith('https') ? 'url' : 'file',
|
|
10658
|
+
});
|
|
10659
|
+
}
|
|
9855
10660
|
// Check if it's a URL
|
|
9856
10661
|
if (source.startsWith('http://') || source.startsWith('https://')) {
|
|
9857
10662
|
// Download the file
|
|
@@ -9896,7 +10701,10 @@ class OpenAiAssistantExecutionTools extends OpenAiExecutionTools {
|
|
|
9896
10701
|
files: fileStreams,
|
|
9897
10702
|
});
|
|
9898
10703
|
if (this.options.isVerbose) {
|
|
9899
|
-
console.info(
|
|
10704
|
+
console.info('[🤰]', 'Uploaded files to vector store', {
|
|
10705
|
+
vectorStoreId,
|
|
10706
|
+
fileCount: fileStreams.length,
|
|
10707
|
+
});
|
|
9900
10708
|
}
|
|
9901
10709
|
}
|
|
9902
10710
|
catch (error) {
|
|
@@ -9924,8 +10732,21 @@ class OpenAiAssistantExecutionTools extends OpenAiExecutionTools {
|
|
|
9924
10732
|
},
|
|
9925
10733
|
};
|
|
9926
10734
|
}
|
|
10735
|
+
if (this.options.isVerbose) {
|
|
10736
|
+
console.info('[🤰]', 'Creating OpenAI assistant', {
|
|
10737
|
+
name,
|
|
10738
|
+
model: assistantConfig.model,
|
|
10739
|
+
toolCount: (_c = assistantConfig === null || assistantConfig === void 0 ? void 0 : assistantConfig.tools) === null || _c === void 0 ? void 0 : _c.length,
|
|
10740
|
+
hasVectorStore: Boolean(vectorStoreId),
|
|
10741
|
+
});
|
|
10742
|
+
}
|
|
9927
10743
|
const assistant = await client.beta.assistants.create(assistantConfig);
|
|
9928
|
-
|
|
10744
|
+
if (this.options.isVerbose) {
|
|
10745
|
+
console.info('[🤰]', 'OpenAI assistant created', {
|
|
10746
|
+
assistantId: assistant.id,
|
|
10747
|
+
elapsedMs: Date.now() - preparationStartedAtMs,
|
|
10748
|
+
});
|
|
10749
|
+
}
|
|
9929
10750
|
// TODO: [🐱🚀] Try listing existing assistants
|
|
9930
10751
|
// TODO: [🐱🚀] Try marking existing assistants by DISCRIMINANT
|
|
9931
10752
|
// TODO: [🐱🚀] Allow to update and reconnect to existing assistants
|
|
@@ -9936,17 +10757,34 @@ class OpenAiAssistantExecutionTools extends OpenAiExecutionTools {
|
|
|
9936
10757
|
});
|
|
9937
10758
|
}
|
|
9938
10759
|
async updateAssistant(options) {
|
|
10760
|
+
var _a, _b, _c, _d;
|
|
9939
10761
|
if (!this.isCreatingNewAssistantsAllowed) {
|
|
9940
10762
|
throw new NotAllowed(`Updating assistants is not allowed. Set \`isCreatingNewAssistantsAllowed: true\` in options to enable this feature.`);
|
|
9941
10763
|
}
|
|
9942
10764
|
const { assistantId, name, instructions, knowledgeSources, tools } = options;
|
|
10765
|
+
const preparationStartedAtMs = Date.now();
|
|
10766
|
+
const knowledgeSourcesCount = (_a = knowledgeSources === null || knowledgeSources === void 0 ? void 0 : knowledgeSources.length) !== null && _a !== void 0 ? _a : 0;
|
|
10767
|
+
const toolsCount = (_b = tools === null || tools === void 0 ? void 0 : tools.length) !== null && _b !== void 0 ? _b : 0;
|
|
10768
|
+
if (this.options.isVerbose) {
|
|
10769
|
+
console.info('[🤰]', 'Starting OpenAI assistant update', {
|
|
10770
|
+
assistantId,
|
|
10771
|
+
name,
|
|
10772
|
+
knowledgeSourcesCount,
|
|
10773
|
+
toolsCount,
|
|
10774
|
+
instructionsLength: (_c = instructions === null || instructions === void 0 ? void 0 : instructions.length) !== null && _c !== void 0 ? _c : 0,
|
|
10775
|
+
});
|
|
10776
|
+
}
|
|
9943
10777
|
const client = await this.getClient();
|
|
9944
10778
|
let vectorStoreId;
|
|
9945
10779
|
// If knowledge sources are provided, create a vector store with them
|
|
9946
10780
|
// TODO: [🧠] Reuse vector store creation logic from createNewAssistant
|
|
9947
10781
|
if (knowledgeSources && knowledgeSources.length > 0) {
|
|
9948
10782
|
if (this.options.isVerbose) {
|
|
9949
|
-
console.info(
|
|
10783
|
+
console.info('[🤰]', 'Creating vector store for assistant update', {
|
|
10784
|
+
assistantId,
|
|
10785
|
+
name,
|
|
10786
|
+
knowledgeSourcesCount,
|
|
10787
|
+
});
|
|
9950
10788
|
}
|
|
9951
10789
|
// Create a vector store
|
|
9952
10790
|
const vectorStore = await client.beta.vectorStores.create({
|
|
@@ -9954,12 +10792,22 @@ class OpenAiAssistantExecutionTools extends OpenAiExecutionTools {
|
|
|
9954
10792
|
});
|
|
9955
10793
|
vectorStoreId = vectorStore.id;
|
|
9956
10794
|
if (this.options.isVerbose) {
|
|
9957
|
-
console.info(
|
|
10795
|
+
console.info('[🤰]', 'Vector store created for assistant update', {
|
|
10796
|
+
vectorStoreId,
|
|
10797
|
+
});
|
|
9958
10798
|
}
|
|
9959
10799
|
// Upload files from knowledge sources to the vector store
|
|
9960
10800
|
const fileStreams = [];
|
|
9961
|
-
for (const source of knowledgeSources) {
|
|
10801
|
+
for (const [index, source] of knowledgeSources.entries()) {
|
|
9962
10802
|
try {
|
|
10803
|
+
if (this.options.isVerbose) {
|
|
10804
|
+
console.info('[🤰]', 'Processing knowledge source for update', {
|
|
10805
|
+
index: index + 1,
|
|
10806
|
+
total: knowledgeSources.length,
|
|
10807
|
+
source,
|
|
10808
|
+
sourceType: source.startsWith('http') || source.startsWith('https') ? 'url' : 'file',
|
|
10809
|
+
});
|
|
10810
|
+
}
|
|
9963
10811
|
// Check if it's a URL
|
|
9964
10812
|
if (source.startsWith('http://') || source.startsWith('https://')) {
|
|
9965
10813
|
// Download the file
|
|
@@ -10004,7 +10852,10 @@ class OpenAiAssistantExecutionTools extends OpenAiExecutionTools {
|
|
|
10004
10852
|
files: fileStreams,
|
|
10005
10853
|
});
|
|
10006
10854
|
if (this.options.isVerbose) {
|
|
10007
|
-
console.info(
|
|
10855
|
+
console.info('[🤰]', 'Uploaded files to vector store for update', {
|
|
10856
|
+
vectorStoreId,
|
|
10857
|
+
fileCount: fileStreams.length,
|
|
10858
|
+
});
|
|
10008
10859
|
}
|
|
10009
10860
|
}
|
|
10010
10861
|
catch (error) {
|
|
@@ -10028,9 +10879,20 @@ class OpenAiAssistantExecutionTools extends OpenAiExecutionTools {
|
|
|
10028
10879
|
},
|
|
10029
10880
|
};
|
|
10030
10881
|
}
|
|
10882
|
+
if (this.options.isVerbose) {
|
|
10883
|
+
console.info('[🤰]', 'Updating OpenAI assistant', {
|
|
10884
|
+
assistantId,
|
|
10885
|
+
name,
|
|
10886
|
+
toolCount: (_d = assistantUpdate === null || assistantUpdate === void 0 ? void 0 : assistantUpdate.tools) === null || _d === void 0 ? void 0 : _d.length,
|
|
10887
|
+
hasVectorStore: Boolean(vectorStoreId),
|
|
10888
|
+
});
|
|
10889
|
+
}
|
|
10031
10890
|
const assistant = await client.beta.assistants.update(assistantId, assistantUpdate);
|
|
10032
10891
|
if (this.options.isVerbose) {
|
|
10033
|
-
console.
|
|
10892
|
+
console.info('[🤰]', 'OpenAI assistant updated', {
|
|
10893
|
+
assistantId: assistant.id,
|
|
10894
|
+
elapsedMs: Date.now() - preparationStartedAtMs,
|
|
10895
|
+
});
|
|
10034
10896
|
}
|
|
10035
10897
|
return new OpenAiAssistantExecutionTools({
|
|
10036
10898
|
...this.options,
|
|
@@ -27818,6 +28680,21 @@ function book(strings, ...values) {
|
|
|
27818
28680
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
27819
28681
|
*/
|
|
27820
28682
|
|
|
28683
|
+
/**
|
|
28684
|
+
* Tool call name emitted while preparing a GPT assistant for an agent.
|
|
28685
|
+
*
|
|
28686
|
+
* @public exported from `@promptbook/types`
|
|
28687
|
+
*/
|
|
28688
|
+
const ASSISTANT_PREPARATION_TOOL_CALL_NAME = 'assistant_preparation';
|
|
28689
|
+
/**
|
|
28690
|
+
* Checks whether a tool call is the assistant preparation marker.
|
|
28691
|
+
*
|
|
28692
|
+
* @public exported from `@promptbook/types`
|
|
28693
|
+
*/
|
|
28694
|
+
function isAssistantPreparationToolCall(toolCall) {
|
|
28695
|
+
return toolCall.name === ASSISTANT_PREPARATION_TOOL_CALL_NAME;
|
|
28696
|
+
}
|
|
28697
|
+
|
|
27821
28698
|
/*! *****************************************************************************
|
|
27822
28699
|
Copyright (c) Microsoft Corporation.
|
|
27823
28700
|
|
|
@@ -27930,14 +28807,27 @@ function humanizeAiTextEmdashed(aiText) {
|
|
|
27930
28807
|
* @public exported from `@promptbook/markdown-utils`
|
|
27931
28808
|
*/
|
|
27932
28809
|
function humanizeAiTextQuotes(aiText) {
|
|
27933
|
-
return aiText
|
|
27934
|
-
.replace(/[“”„‟«»❝❞〝〞〟"]/g, '"')
|
|
27935
|
-
.replace(/[‚‘’‛‹›❛❜'ʼ]/g, "'");
|
|
28810
|
+
return aiText.replace(/[“”„‟«»❝❞〝〞〟"]/g, '"').replace(/[‚‘’‛‹›❛❜'ʼ]/g, "'");
|
|
27936
28811
|
}
|
|
27937
28812
|
/**
|
|
27938
28813
|
* Note: [🏂] This function is not tested by itself but together with other cleanup functions with `humanizeAiText`
|
|
27939
28814
|
*/
|
|
27940
28815
|
|
|
28816
|
+
/**
|
|
28817
|
+
* Remove bracketed source citation artifacts like `\u30105:1\u2020source\u3011`.
|
|
28818
|
+
*
|
|
28819
|
+
* Note: [??] This function is idempotent.
|
|
28820
|
+
* Tip: If you want to do the full cleanup, look for `humanizeAiText` exported `@promptbook/markdown-utils`
|
|
28821
|
+
*
|
|
28822
|
+
* @public exported from `@promptbook/markdown-utils`
|
|
28823
|
+
*/
|
|
28824
|
+
function humanizeAiTextSources(aiText) {
|
|
28825
|
+
return aiText.replace(/[ \t]*\u3010\s*\d+(?:\s*:\s*\d+)?\s*\u2020source\s*\u3011/g, '');
|
|
28826
|
+
}
|
|
28827
|
+
/**
|
|
28828
|
+
* Note: [??] This function is not tested by itself but together with other cleanup functions with `humanizeAiText`
|
|
28829
|
+
*/
|
|
28830
|
+
|
|
27941
28831
|
/**
|
|
27942
28832
|
* Change unprintable hard spaces to regular spaces and drop zero-width spaces
|
|
27943
28833
|
*
|
|
@@ -27947,9 +28837,7 @@ function humanizeAiTextQuotes(aiText) {
|
|
|
27947
28837
|
* @public exported from `@promptbook/markdown-utils`
|
|
27948
28838
|
*/
|
|
27949
28839
|
function humanizeAiTextWhitespace(aiText) {
|
|
27950
|
-
return aiText
|
|
27951
|
-
.replace(/[\u00A0\u1680\u2000-\u200A\u202F\u205F\u3000]/g, ' ')
|
|
27952
|
-
.replace(/[\u200B\uFEFF\u2060]/g, '');
|
|
28840
|
+
return aiText.replace(/[\u00A0\u1680\u2000-\u200A\u202F\u205F\u3000]/g, ' ').replace(/[\u200B\uFEFF\u2060]/g, '');
|
|
27953
28841
|
}
|
|
27954
28842
|
/**
|
|
27955
28843
|
* Note: [🏂] This function is not tested by itself but together with other cleanup functions with `humanizeAiText`
|
|
@@ -27968,6 +28856,7 @@ function humanizeAiText(aiText) {
|
|
|
27968
28856
|
cleanedText = humanizeAiTextEllipsis(cleanedText);
|
|
27969
28857
|
cleanedText = humanizeAiTextEmdashed(cleanedText);
|
|
27970
28858
|
cleanedText = humanizeAiTextQuotes(cleanedText);
|
|
28859
|
+
cleanedText = humanizeAiTextSources(cleanedText);
|
|
27971
28860
|
cleanedText = humanizeAiTextWhitespace(cleanedText);
|
|
27972
28861
|
return cleanedText;
|
|
27973
28862
|
}
|
|
@@ -28228,6 +29117,33 @@ class OpenAiAgentExecutionTools extends OpenAiExecutionTools {
|
|
|
28228
29117
|
}
|
|
28229
29118
|
}
|
|
28230
29119
|
|
|
29120
|
+
/**
|
|
29121
|
+
* Emits a progress update to signal assistant preparation before long setup work.
|
|
29122
|
+
*/
|
|
29123
|
+
function emitAssistantPreparationProgress(options) {
|
|
29124
|
+
const startedAt = $getCurrentDate();
|
|
29125
|
+
options.onProgress({
|
|
29126
|
+
content: '',
|
|
29127
|
+
modelName: options.modelName,
|
|
29128
|
+
timing: {
|
|
29129
|
+
start: startedAt,
|
|
29130
|
+
complete: startedAt,
|
|
29131
|
+
},
|
|
29132
|
+
usage: UNCERTAIN_USAGE,
|
|
29133
|
+
rawPromptContent: options.prompt.content,
|
|
29134
|
+
rawRequest: null,
|
|
29135
|
+
rawResponse: {
|
|
29136
|
+
status: 'assistant_preparation',
|
|
29137
|
+
},
|
|
29138
|
+
toolCalls: [
|
|
29139
|
+
{
|
|
29140
|
+
name: ASSISTANT_PREPARATION_TOOL_CALL_NAME,
|
|
29141
|
+
arguments: options.phase ? { phase: options.phase } : {},
|
|
29142
|
+
createdAt: startedAt,
|
|
29143
|
+
},
|
|
29144
|
+
],
|
|
29145
|
+
});
|
|
29146
|
+
}
|
|
28231
29147
|
/**
|
|
28232
29148
|
* Execution Tools for calling LLM models with a predefined agent "soul"
|
|
28233
29149
|
* This wraps underlying LLM execution tools and applies agent-specific system prompts and requirements
|
|
@@ -28286,10 +29202,32 @@ class AgentLlmExecutionTools {
|
|
|
28286
29202
|
*/
|
|
28287
29203
|
async getModelRequirements() {
|
|
28288
29204
|
if (this._cachedModelRequirements === null) {
|
|
29205
|
+
const preparationStartedAtMs = Date.now();
|
|
29206
|
+
if (this.options.isVerbose) {
|
|
29207
|
+
console.info('[🤰]', 'Preparing agent model requirements', {
|
|
29208
|
+
agent: this.title,
|
|
29209
|
+
});
|
|
29210
|
+
}
|
|
28289
29211
|
// Get available models from underlying LLM tools for best model selection
|
|
29212
|
+
const availableModelsStartedAtMs = Date.now();
|
|
28290
29213
|
const availableModels = await this.options.llmTools.listModels();
|
|
29214
|
+
if (this.options.isVerbose) {
|
|
29215
|
+
console.info('[🤰]', 'Available models resolved for agent', {
|
|
29216
|
+
agent: this.title,
|
|
29217
|
+
modelCount: availableModels.length,
|
|
29218
|
+
elapsedMs: Date.now() - availableModelsStartedAtMs,
|
|
29219
|
+
});
|
|
29220
|
+
}
|
|
29221
|
+
const requirementsStartedAtMs = Date.now();
|
|
28291
29222
|
this._cachedModelRequirements = await createAgentModelRequirements(this.options.agentSource, undefined, // Let the function pick the best model
|
|
28292
29223
|
availableModels);
|
|
29224
|
+
if (this.options.isVerbose) {
|
|
29225
|
+
console.info('[🤰]', 'Agent model requirements ready', {
|
|
29226
|
+
agent: this.title,
|
|
29227
|
+
elapsedMs: Date.now() - requirementsStartedAtMs,
|
|
29228
|
+
totalElapsedMs: Date.now() - preparationStartedAtMs,
|
|
29229
|
+
});
|
|
29230
|
+
}
|
|
28293
29231
|
}
|
|
28294
29232
|
return this._cachedModelRequirements;
|
|
28295
29233
|
}
|
|
@@ -28443,14 +29381,26 @@ class AgentLlmExecutionTools {
|
|
|
28443
29381
|
if (cached) {
|
|
28444
29382
|
if (cached.requirementsHash === requirementsHash) {
|
|
28445
29383
|
if (this.options.isVerbose) {
|
|
28446
|
-
console.
|
|
29384
|
+
console.info('[🤰]', 'Using cached OpenAI Assistant', {
|
|
29385
|
+
agent: this.title,
|
|
29386
|
+
assistantId: cached.assistantId,
|
|
29387
|
+
});
|
|
28447
29388
|
}
|
|
28448
29389
|
assistant = this.options.llmTools.getAssistant(cached.assistantId);
|
|
28449
29390
|
}
|
|
28450
29391
|
else {
|
|
28451
29392
|
if (this.options.isVerbose) {
|
|
28452
|
-
console.
|
|
29393
|
+
console.info('[🤰]', 'Updating OpenAI Assistant', {
|
|
29394
|
+
agent: this.title,
|
|
29395
|
+
assistantId: cached.assistantId,
|
|
29396
|
+
});
|
|
28453
29397
|
}
|
|
29398
|
+
emitAssistantPreparationProgress({
|
|
29399
|
+
onProgress,
|
|
29400
|
+
prompt,
|
|
29401
|
+
modelName: this.modelName,
|
|
29402
|
+
phase: 'Updating assistant',
|
|
29403
|
+
});
|
|
28454
29404
|
assistant = await this.options.llmTools.updateAssistant({
|
|
28455
29405
|
assistantId: cached.assistantId,
|
|
28456
29406
|
name: this.title,
|
|
@@ -28466,9 +29416,17 @@ class AgentLlmExecutionTools {
|
|
|
28466
29416
|
}
|
|
28467
29417
|
else {
|
|
28468
29418
|
if (this.options.isVerbose) {
|
|
28469
|
-
console.
|
|
29419
|
+
console.info('[🤰]', 'Creating new OpenAI Assistant', {
|
|
29420
|
+
agent: this.title,
|
|
29421
|
+
});
|
|
28470
29422
|
}
|
|
28471
29423
|
// <- TODO: [🐱🚀] Check also `isCreatingNewAssistantsAllowed` and warn about it
|
|
29424
|
+
emitAssistantPreparationProgress({
|
|
29425
|
+
onProgress,
|
|
29426
|
+
prompt,
|
|
29427
|
+
modelName: this.modelName,
|
|
29428
|
+
phase: 'Creating assistant',
|
|
29429
|
+
});
|
|
28472
29430
|
assistant = await this.options.llmTools.createNewAssistant({
|
|
28473
29431
|
name: this.title,
|
|
28474
29432
|
instructions: modelRequirements.systemMessage,
|
|
@@ -28541,6 +29499,58 @@ AgentLlmExecutionTools.vectorStoreCache = new Map();
|
|
|
28541
29499
|
*/
|
|
28542
29500
|
|
|
28543
29501
|
var _Agent_instances, _Agent_selfLearnNonce, _Agent_selfLearnSamples, _Agent_selfLearnTeacher;
|
|
29502
|
+
/**
|
|
29503
|
+
* Creates an empty commitment breakdown for self-learning summaries.
|
|
29504
|
+
*/
|
|
29505
|
+
function createEmptySelfLearningCommitmentCounts() {
|
|
29506
|
+
return {
|
|
29507
|
+
total: 0,
|
|
29508
|
+
knowledge: 0,
|
|
29509
|
+
rule: 0,
|
|
29510
|
+
persona: 0,
|
|
29511
|
+
other: 0,
|
|
29512
|
+
};
|
|
29513
|
+
}
|
|
29514
|
+
/**
|
|
29515
|
+
* Summarizes teacher commitments into user-friendly counts for self-learning.
|
|
29516
|
+
*/
|
|
29517
|
+
function summarizeTeacherCommitments(commitments) {
|
|
29518
|
+
var _a, _b;
|
|
29519
|
+
const counts = createEmptySelfLearningCommitmentCounts();
|
|
29520
|
+
const lines = commitments
|
|
29521
|
+
.split(/\r?\n/)
|
|
29522
|
+
.map((line) => line.trim())
|
|
29523
|
+
.filter((line) => line.length > 0 && line !== '---' && !line.startsWith('```'));
|
|
29524
|
+
for (const line of lines) {
|
|
29525
|
+
const keyword = (_b = (_a = line.split(/\s+/)[0]) === null || _a === void 0 ? void 0 : _a.toUpperCase()) !== null && _b !== void 0 ? _b : '';
|
|
29526
|
+
if (!/^[A-Z][A-Z_-]*$/.test(keyword)) {
|
|
29527
|
+
continue;
|
|
29528
|
+
}
|
|
29529
|
+
counts.total += 1;
|
|
29530
|
+
if (keyword === 'KNOWLEDGE') {
|
|
29531
|
+
counts.knowledge += 1;
|
|
29532
|
+
}
|
|
29533
|
+
else if (keyword === 'RULE') {
|
|
29534
|
+
counts.rule += 1;
|
|
29535
|
+
}
|
|
29536
|
+
else if (keyword === 'PERSONA') {
|
|
29537
|
+
counts.persona += 1;
|
|
29538
|
+
}
|
|
29539
|
+
else {
|
|
29540
|
+
counts.other += 1;
|
|
29541
|
+
}
|
|
29542
|
+
}
|
|
29543
|
+
return counts;
|
|
29544
|
+
}
|
|
29545
|
+
/**
|
|
29546
|
+
* Builds the teacher summary payload for the self-learning tool call.
|
|
29547
|
+
*/
|
|
29548
|
+
function buildTeacherSummary(commitments, used) {
|
|
29549
|
+
return {
|
|
29550
|
+
used,
|
|
29551
|
+
commitmentTypes: summarizeTeacherCommitments(commitments),
|
|
29552
|
+
};
|
|
29553
|
+
}
|
|
28544
29554
|
/**
|
|
28545
29555
|
* Represents one AI Agent
|
|
28546
29556
|
*
|
|
@@ -28715,16 +29725,29 @@ class Agent extends AgentLlmExecutionTools {
|
|
|
28715
29725
|
// Note: [2] Do the append of the samples
|
|
28716
29726
|
await __classPrivateFieldGet(this, _Agent_instances, "m", _Agent_selfLearnSamples).call(this, prompt, result);
|
|
28717
29727
|
// Note: [3] Asynchronously call the teacher agent and invoke the silver link. When the teacher fails, keep just the samples
|
|
28718
|
-
|
|
29728
|
+
let teacherSummary = null;
|
|
29729
|
+
try {
|
|
29730
|
+
teacherSummary = await __classPrivateFieldGet(this, _Agent_instances, "m", _Agent_selfLearnTeacher).call(this, prompt, result);
|
|
29731
|
+
}
|
|
29732
|
+
catch (error) {
|
|
28719
29733
|
// !!!!! if (this.options.isVerbose) {
|
|
28720
29734
|
console.error(colors.bgCyan('[Self-learning]') + colors.red(' Failed to learn from teacher agent'));
|
|
28721
29735
|
console.error(error);
|
|
28722
29736
|
// }
|
|
28723
|
-
|
|
29737
|
+
teacherSummary = this.teacherAgent ? buildTeacherSummary('', true) : null;
|
|
29738
|
+
}
|
|
28724
29739
|
// Note: [4] Notify end of self-learning
|
|
29740
|
+
const completedAt = new Date().toISOString();
|
|
29741
|
+
const selfLearningResult = {
|
|
29742
|
+
success: true,
|
|
29743
|
+
startedAt: selfLearningToolCall.createdAt,
|
|
29744
|
+
completedAt,
|
|
29745
|
+
samplesAdded: 1,
|
|
29746
|
+
teacher: teacherSummary || undefined,
|
|
29747
|
+
};
|
|
28725
29748
|
const completedSelfLearningToolCall = {
|
|
28726
29749
|
...selfLearningToolCall,
|
|
28727
|
-
result:
|
|
29750
|
+
result: selfLearningResult,
|
|
28728
29751
|
};
|
|
28729
29752
|
const finalResult = {
|
|
28730
29753
|
...result,
|
|
@@ -28773,7 +29796,7 @@ async function _Agent_selfLearnNonce() {
|
|
|
28773
29796
|
async function _Agent_selfLearnTeacher(prompt, result) {
|
|
28774
29797
|
// [1] Call the teacher agent // <- !!!!! Emojis
|
|
28775
29798
|
if (this.teacherAgent === null) {
|
|
28776
|
-
return;
|
|
29799
|
+
return null;
|
|
28777
29800
|
}
|
|
28778
29801
|
console.info(colors.bgCyan('[Self-learning]') + colors.cyan(' Teacher'));
|
|
28779
29802
|
const teacherResult = await this.teacherAgent.callChatModel({
|
|
@@ -28828,7 +29851,7 @@ async function _Agent_selfLearnTeacher(prompt, result) {
|
|
|
28828
29851
|
if (teacherCommitments === '') {
|
|
28829
29852
|
console.info(colors.bgCyan('[Self-learning]') +
|
|
28830
29853
|
colors.cyan(' Teacher agent did not provide new commitments to learn'));
|
|
28831
|
-
return;
|
|
29854
|
+
return buildTeacherSummary('', true);
|
|
28832
29855
|
}
|
|
28833
29856
|
// [2] Append to the current source
|
|
28834
29857
|
const currentSource = this.agentSource.value;
|
|
@@ -28836,6 +29859,7 @@ async function _Agent_selfLearnTeacher(prompt, result) {
|
|
|
28836
29859
|
// <- TODO: [🈲] Use some object-based way how to append on book (with sections `---`)
|
|
28837
29860
|
// [3] Update the source
|
|
28838
29861
|
this.agentSource.next(newSource);
|
|
29862
|
+
return buildTeacherSummary(teacherCommitments, true);
|
|
28839
29863
|
};
|
|
28840
29864
|
/**
|
|
28841
29865
|
* TODO: [🧠][😰]Agent is not working with the parameters, should it be?
|
|
@@ -28999,6 +30023,8 @@ class RemoteAgent extends Agent {
|
|
|
28999
30023
|
// <- TODO: [🐱🚀] Maybe use promptbookFetch
|
|
29000
30024
|
let content = '';
|
|
29001
30025
|
const toolCalls = [];
|
|
30026
|
+
const preparationToolCalls = [];
|
|
30027
|
+
let hasReceivedModelOutput = false;
|
|
29002
30028
|
const normalizeToolCall = (toolCall) => {
|
|
29003
30029
|
if (toolCall.createdAt) {
|
|
29004
30030
|
return toolCall;
|
|
@@ -29045,6 +30071,17 @@ class RemoteAgent extends Agent {
|
|
|
29045
30071
|
const upsertToolCalls = (incomingToolCalls) => {
|
|
29046
30072
|
for (const toolCall of incomingToolCalls) {
|
|
29047
30073
|
const normalized = normalizeToolCall(toolCall);
|
|
30074
|
+
if (isAssistantPreparationToolCall(normalized)) {
|
|
30075
|
+
if (hasReceivedModelOutput) {
|
|
30076
|
+
continue;
|
|
30077
|
+
}
|
|
30078
|
+
preparationToolCalls.length = 0;
|
|
30079
|
+
preparationToolCalls.push(normalized);
|
|
30080
|
+
continue;
|
|
30081
|
+
}
|
|
30082
|
+
if (preparationToolCalls.length > 0) {
|
|
30083
|
+
preparationToolCalls.length = 0;
|
|
30084
|
+
}
|
|
29048
30085
|
const key = getToolCallKey(normalized);
|
|
29049
30086
|
const existingIndex = toolCalls.findIndex((existing) => getToolCallKey(existing) === key);
|
|
29050
30087
|
if (existingIndex === -1) {
|
|
@@ -29055,6 +30092,10 @@ class RemoteAgent extends Agent {
|
|
|
29055
30092
|
}
|
|
29056
30093
|
}
|
|
29057
30094
|
};
|
|
30095
|
+
/**
|
|
30096
|
+
* Builds the tool call list including any preparation marker still active.
|
|
30097
|
+
*/
|
|
30098
|
+
const getActiveToolCalls = () => preparationToolCalls.length > 0 ? [...preparationToolCalls, ...toolCalls] : toolCalls;
|
|
29058
30099
|
if (!bookResponse.body) {
|
|
29059
30100
|
content = await bookResponse.text();
|
|
29060
30101
|
}
|
|
@@ -29091,7 +30132,7 @@ class RemoteAgent extends Agent {
|
|
|
29091
30132
|
rawPromptContent: {},
|
|
29092
30133
|
rawRequest: {},
|
|
29093
30134
|
rawResponse: {},
|
|
29094
|
-
toolCalls:
|
|
30135
|
+
toolCalls: getActiveToolCalls(),
|
|
29095
30136
|
});
|
|
29096
30137
|
sawToolCalls = true;
|
|
29097
30138
|
isToolCallLine = true;
|
|
@@ -29119,6 +30160,10 @@ class RemoteAgent extends Agent {
|
|
|
29119
30160
|
// console.debug('RemoteAgent chunk:', textChunk);
|
|
29120
30161
|
content += textChunk;
|
|
29121
30162
|
}
|
|
30163
|
+
if (!hasReceivedModelOutput && content.trim().length > 0) {
|
|
30164
|
+
hasReceivedModelOutput = true;
|
|
30165
|
+
preparationToolCalls.length = 0;
|
|
30166
|
+
}
|
|
29122
30167
|
onProgress({
|
|
29123
30168
|
content,
|
|
29124
30169
|
modelName: this.modelName,
|
|
@@ -29127,7 +30172,7 @@ class RemoteAgent extends Agent {
|
|
|
29127
30172
|
rawPromptContent: {},
|
|
29128
30173
|
rawRequest: {},
|
|
29129
30174
|
rawResponse: {},
|
|
29130
|
-
toolCalls,
|
|
30175
|
+
toolCalls: getActiveToolCalls(),
|
|
29131
30176
|
});
|
|
29132
30177
|
}
|
|
29133
30178
|
}
|
|
@@ -29135,6 +30180,10 @@ class RemoteAgent extends Agent {
|
|
|
29135
30180
|
const lastChunk = decoder.decode();
|
|
29136
30181
|
if (lastChunk) {
|
|
29137
30182
|
content += lastChunk;
|
|
30183
|
+
if (!hasReceivedModelOutput && content.trim().length > 0) {
|
|
30184
|
+
hasReceivedModelOutput = true;
|
|
30185
|
+
preparationToolCalls.length = 0;
|
|
30186
|
+
}
|
|
29138
30187
|
onProgress({
|
|
29139
30188
|
content: lastChunk,
|
|
29140
30189
|
modelName: this.modelName,
|
|
@@ -29143,7 +30192,7 @@ class RemoteAgent extends Agent {
|
|
|
29143
30192
|
rawPromptContent: {},
|
|
29144
30193
|
rawRequest: {},
|
|
29145
30194
|
rawResponse: {},
|
|
29146
|
-
toolCalls,
|
|
30195
|
+
toolCalls: getActiveToolCalls(),
|
|
29147
30196
|
});
|
|
29148
30197
|
}
|
|
29149
30198
|
}
|