@promptbook/utils 0.103.0-55 → 0.103.0-66
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 +80 -39
- package/esm/index.es.js.map +1 -1
- package/esm/typings/src/_packages/components.index.d.ts +2 -2
- package/esm/typings/src/_packages/core.index.d.ts +6 -8
- package/esm/typings/src/_packages/types.index.d.ts +7 -1
- package/esm/typings/src/book-2.0/agent-source/AgentBasicInformation.d.ts +2 -1
- package/esm/typings/src/book-2.0/agent-source/createCommitmentRegex.d.ts +1 -1
- package/esm/typings/src/book-components/Chat/AgentChat/AgentChat.d.ts +3 -0
- package/esm/typings/src/book-components/Chat/Chat/ChatProps.d.ts +6 -0
- package/esm/typings/src/book-components/Chat/LlmChat/LlmChatProps.d.ts +5 -0
- package/esm/typings/src/book-components/PromptbookAgent/PromptbookAgentIntegration.d.ts +52 -0
- package/esm/typings/src/book-components/PromptbookAgent/PromptbookAgentSeamlessIntegration.d.ts +14 -0
- package/esm/typings/src/book-components/icons/SendIcon.d.ts +3 -0
- package/esm/typings/src/commitments/CLOSED/CLOSED.d.ts +4 -0
- package/esm/typings/src/commitments/CLOSED/CLOSED.test.d.ts +4 -0
- package/esm/typings/src/commitments/META_COLOR/META_COLOR.d.ts +6 -0
- package/esm/typings/src/commitments/META_FONT/META_FONT.d.ts +42 -0
- package/esm/typings/src/commitments/USE/USE.d.ts +53 -0
- package/esm/typings/src/commitments/USE_BROWSER/USE_BROWSER.d.ts +42 -0
- package/esm/typings/src/commitments/USE_BROWSER/USE_BROWSER.test.d.ts +1 -0
- package/esm/typings/src/commitments/{IMPORTANT/IMPORTANT.d.ts → USE_MCP/USE_MCP.d.ts} +16 -5
- package/esm/typings/src/commitments/USE_SEARCH_ENGINE/USE_SEARCH_ENGINE.d.ts +38 -0
- package/esm/typings/src/commitments/_base/BaseCommitmentDefinition.d.ts +6 -0
- package/esm/typings/src/commitments/index.d.ts +93 -1
- package/esm/typings/src/llm-providers/agent/Agent.d.ts +3 -1
- package/esm/typings/src/other/templates/getTemplatesPipelineCollection.d.ts +1 -1
- package/esm/typings/src/playground/playground.d.ts +3 -0
- package/esm/typings/src/types/typeAliases.d.ts +6 -0
- package/esm/typings/src/utils/color/Color.d.ts +9 -1
- package/esm/typings/src/utils/color/css-colors.d.ts +1 -0
- package/esm/typings/src/utils/random/$generateBookBoilerplate.d.ts +6 -0
- package/esm/typings/src/utils/random/CzechNamePool.d.ts +7 -0
- package/esm/typings/src/utils/random/EnglishNamePool.d.ts +7 -0
- package/esm/typings/src/utils/random/NamePool.d.ts +17 -0
- package/esm/typings/src/utils/random/getNamePool.d.ts +10 -0
- package/esm/typings/src/version.d.ts +1 -1
- package/package.json +2 -2
- package/umd/index.umd.js +57 -16
- package/umd/index.umd.js.map +1 -1
- package/esm/typings/src/book-components/PromptbookAgent/PromptbookAgent.d.ts +0 -29
- package/esm/typings/src/commitments/registry.d.ts +0 -68
- package/esm/typings/src/playground/playground1.d.ts +0 -2
package/esm/index.es.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import spaceTrim$
|
|
1
|
+
import spaceTrim$2, { spaceTrim as spaceTrim$1 } from 'spacetrim';
|
|
2
2
|
import { basename } from 'path';
|
|
3
3
|
import { randomBytes } from 'crypto';
|
|
4
4
|
import { SHA256 } from 'crypto-js';
|
|
@@ -18,12 +18,23 @@ const BOOK_LANGUAGE_VERSION = '2.0.0';
|
|
|
18
18
|
* @generated
|
|
19
19
|
* @see https://github.com/webgptorg/promptbook
|
|
20
20
|
*/
|
|
21
|
-
const PROMPTBOOK_ENGINE_VERSION = '0.103.0-
|
|
21
|
+
const PROMPTBOOK_ENGINE_VERSION = '0.103.0-66';
|
|
22
22
|
/**
|
|
23
23
|
* TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
|
|
24
24
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
25
25
|
*/
|
|
26
26
|
|
|
27
|
+
/**
|
|
28
|
+
* Trims string from all 4 sides
|
|
29
|
+
*
|
|
30
|
+
* Note: This is a re-exported function from the `spacetrim` package which is
|
|
31
|
+
* Developed by same author @hejny as this package
|
|
32
|
+
*
|
|
33
|
+
* @public exported from `@promptbook/utils`
|
|
34
|
+
* @see https://github.com/hejny/spacetrim#usage
|
|
35
|
+
*/
|
|
36
|
+
const spaceTrim = spaceTrim$1;
|
|
37
|
+
|
|
27
38
|
/**
|
|
28
39
|
* @private util of `@promptbook/color`
|
|
29
40
|
* @de
|
|
@@ -72,6 +83,7 @@ function take(initialValue) {
|
|
|
72
83
|
* @public exported from `@promptbook/color`
|
|
73
84
|
*/
|
|
74
85
|
const CSS_COLORS = {
|
|
86
|
+
promptbook: '#79EAFD',
|
|
75
87
|
transparent: 'rgba(0,0,0,0)',
|
|
76
88
|
aliceblue: '#f0f8ff',
|
|
77
89
|
antiquewhite: '#faebd7',
|
|
@@ -272,21 +284,61 @@ class Color {
|
|
|
272
284
|
* @param color
|
|
273
285
|
* @returns Color object
|
|
274
286
|
*/
|
|
275
|
-
static from(color) {
|
|
276
|
-
if (color
|
|
287
|
+
static from(color, _isSingleValue = false) {
|
|
288
|
+
if (color === '') {
|
|
289
|
+
throw new Error(`Can not create color from empty string`);
|
|
290
|
+
}
|
|
291
|
+
else if (color instanceof Color) {
|
|
277
292
|
return take(color);
|
|
278
293
|
}
|
|
279
294
|
else if (Color.isColor(color)) {
|
|
280
295
|
return take(color);
|
|
281
296
|
}
|
|
282
297
|
else if (typeof color === 'string') {
|
|
283
|
-
|
|
298
|
+
try {
|
|
299
|
+
return Color.fromString(color);
|
|
300
|
+
}
|
|
301
|
+
catch (error) {
|
|
302
|
+
// <- Note: Can not use `assertsError(error)` here because it causes circular dependency
|
|
303
|
+
if (_isSingleValue) {
|
|
304
|
+
throw error;
|
|
305
|
+
}
|
|
306
|
+
const parts = color.split(/[\s+,;|]/);
|
|
307
|
+
if (parts.length > 0) {
|
|
308
|
+
return Color.from(parts[0].trim(), true);
|
|
309
|
+
}
|
|
310
|
+
else {
|
|
311
|
+
throw new Error(`Can not create color from given string "${color}"`);
|
|
312
|
+
}
|
|
313
|
+
}
|
|
284
314
|
}
|
|
285
315
|
else {
|
|
286
316
|
console.error({ color });
|
|
287
317
|
throw new Error(`Can not create color from given object`);
|
|
288
318
|
}
|
|
289
319
|
}
|
|
320
|
+
/**
|
|
321
|
+
* Creates a new Color instance from miscellaneous formats
|
|
322
|
+
* It just does not throw error when it fails, it returns PROMPTBOOK_COLOR instead
|
|
323
|
+
*
|
|
324
|
+
* @param color
|
|
325
|
+
* @returns Color object
|
|
326
|
+
*/
|
|
327
|
+
static fromSafe(color) {
|
|
328
|
+
try {
|
|
329
|
+
return Color.from(color);
|
|
330
|
+
}
|
|
331
|
+
catch (error) {
|
|
332
|
+
// <- Note: Can not use `assertsError(error)` here because it causes circular dependency
|
|
333
|
+
console.warn(spaceTrim((block) => `
|
|
334
|
+
Color.fromSafe error:
|
|
335
|
+
${block(error.message)}
|
|
336
|
+
|
|
337
|
+
Returning default PROMPTBOOK_COLOR.
|
|
338
|
+
`));
|
|
339
|
+
return Color.fromString('promptbook');
|
|
340
|
+
}
|
|
341
|
+
}
|
|
290
342
|
/**
|
|
291
343
|
* Creates a new Color instance from miscellaneous string formats
|
|
292
344
|
*
|
|
@@ -876,7 +928,7 @@ const ADMIN_GITHUB_NAME = 'hejny';
|
|
|
876
928
|
*
|
|
877
929
|
* @public exported from `@promptbook/core`
|
|
878
930
|
*/
|
|
879
|
-
const PROMPTBOOK_COLOR = Color.
|
|
931
|
+
const PROMPTBOOK_COLOR = Color.fromString('promptbook');
|
|
880
932
|
// <- TODO: [🧠][🈵] Using `Color` here increases the package size approx 3kb, maybe remove it
|
|
881
933
|
/**
|
|
882
934
|
* Colors for syntax highlighting in the `<BookEditor/>`
|
|
@@ -1012,7 +1064,7 @@ function $deepFreeze(objectValue) {
|
|
|
1012
1064
|
function getErrorReportUrl(error) {
|
|
1013
1065
|
const report = {
|
|
1014
1066
|
title: `🐜 Error report from ${NAME}`,
|
|
1015
|
-
body: spaceTrim$
|
|
1067
|
+
body: spaceTrim$2((block) => `
|
|
1016
1068
|
|
|
1017
1069
|
|
|
1018
1070
|
\`${error.name || 'Error'}\` has occurred in the [${NAME}], please look into it @${ADMIN_GITHUB_NAME}.
|
|
@@ -1055,7 +1107,7 @@ function getErrorReportUrl(error) {
|
|
|
1055
1107
|
*/
|
|
1056
1108
|
class UnexpectedError extends Error {
|
|
1057
1109
|
constructor(message) {
|
|
1058
|
-
super(spaceTrim$
|
|
1110
|
+
super(spaceTrim$1((block) => `
|
|
1059
1111
|
${block(message)}
|
|
1060
1112
|
|
|
1061
1113
|
Note: This error should not happen.
|
|
@@ -1081,7 +1133,7 @@ class WrappedError extends Error {
|
|
|
1081
1133
|
constructor(whatWasThrown) {
|
|
1082
1134
|
const tag = `[🤮]`;
|
|
1083
1135
|
console.error(tag, whatWasThrown);
|
|
1084
|
-
super(spaceTrim$
|
|
1136
|
+
super(spaceTrim$1(`
|
|
1085
1137
|
Non-Error object was thrown
|
|
1086
1138
|
|
|
1087
1139
|
Note: Look for ${tag} in the console for more details
|
|
@@ -1170,7 +1222,7 @@ function checkSerializableAsJson(options) {
|
|
|
1170
1222
|
}
|
|
1171
1223
|
else if (typeof value === 'object') {
|
|
1172
1224
|
if (value instanceof Date) {
|
|
1173
|
-
throw new UnexpectedError(spaceTrim$
|
|
1225
|
+
throw new UnexpectedError(spaceTrim$2((block) => `
|
|
1174
1226
|
\`${name}\` is Date
|
|
1175
1227
|
|
|
1176
1228
|
Use \`string_date_iso8601\` instead
|
|
@@ -1189,7 +1241,7 @@ function checkSerializableAsJson(options) {
|
|
|
1189
1241
|
throw new UnexpectedError(`${name} is RegExp`);
|
|
1190
1242
|
}
|
|
1191
1243
|
else if (value instanceof Error) {
|
|
1192
|
-
throw new UnexpectedError(spaceTrim$
|
|
1244
|
+
throw new UnexpectedError(spaceTrim$2((block) => `
|
|
1193
1245
|
\`${name}\` is unserialized Error
|
|
1194
1246
|
|
|
1195
1247
|
Use function \`serializeError\`
|
|
@@ -1212,7 +1264,7 @@ function checkSerializableAsJson(options) {
|
|
|
1212
1264
|
}
|
|
1213
1265
|
catch (error) {
|
|
1214
1266
|
assertsError(error);
|
|
1215
|
-
throw new UnexpectedError(spaceTrim$
|
|
1267
|
+
throw new UnexpectedError(spaceTrim$2((block) => `
|
|
1216
1268
|
\`${name}\` is not serializable
|
|
1217
1269
|
|
|
1218
1270
|
${block(error.stack || error.message)}
|
|
@@ -1244,7 +1296,7 @@ function checkSerializableAsJson(options) {
|
|
|
1244
1296
|
}
|
|
1245
1297
|
}
|
|
1246
1298
|
else {
|
|
1247
|
-
throw new UnexpectedError(spaceTrim$
|
|
1299
|
+
throw new UnexpectedError(spaceTrim$2((block) => `
|
|
1248
1300
|
\`${name}\` is unknown type
|
|
1249
1301
|
|
|
1250
1302
|
Additional message for \`${name}\`:
|
|
@@ -1928,7 +1980,7 @@ function renderPromptbookMermaid(pipelineJson, options) {
|
|
|
1928
1980
|
.filter(([MERMAID_NAME]) => (inputAndIntermediateParametersMermaid + outputParametersMermaid).includes(MERMAID_NAME))
|
|
1929
1981
|
.map(([MERMAID_NAME, title]) => `${MERMAID_NAME}((${title})):::${MERMAID_NAME}`)
|
|
1930
1982
|
.join('\n');
|
|
1931
|
-
const promptbookMermaid = spaceTrim$
|
|
1983
|
+
const promptbookMermaid = spaceTrim$1((block) => `
|
|
1932
1984
|
|
|
1933
1985
|
%% 🔮 Tip: Open this on GitHub or in the VSCode website to see the Mermaid graph visually
|
|
1934
1986
|
|
|
@@ -2104,7 +2156,7 @@ class LimitReachedError extends Error {
|
|
|
2104
2156
|
*/
|
|
2105
2157
|
class MissingToolsError extends Error {
|
|
2106
2158
|
constructor(message) {
|
|
2107
|
-
super(spaceTrim$
|
|
2159
|
+
super(spaceTrim$1((block) => `
|
|
2108
2160
|
${block(message)}
|
|
2109
2161
|
|
|
2110
2162
|
Note: You have probably forgot to provide some tools for pipeline execution or preparation
|
|
@@ -2148,7 +2200,7 @@ class NotFoundError extends Error {
|
|
|
2148
2200
|
*/
|
|
2149
2201
|
class NotYetImplementedError extends Error {
|
|
2150
2202
|
constructor(message) {
|
|
2151
|
-
super(spaceTrim$
|
|
2203
|
+
super(spaceTrim$1((block) => `
|
|
2152
2204
|
${block(message)}
|
|
2153
2205
|
|
|
2154
2206
|
Note: This feature is not implemented yet but it will be soon.
|
|
@@ -2333,7 +2385,7 @@ function deserializeError(error) {
|
|
|
2333
2385
|
message = `${name}: ${message}`;
|
|
2334
2386
|
}
|
|
2335
2387
|
if (stack !== undefined && stack !== '') {
|
|
2336
|
-
message = spaceTrim$
|
|
2388
|
+
message = spaceTrim$2((block) => `
|
|
2337
2389
|
${block(message)}
|
|
2338
2390
|
|
|
2339
2391
|
Original stack trace:
|
|
@@ -2354,7 +2406,7 @@ function serializeError(error) {
|
|
|
2354
2406
|
const { name, message, stack } = error;
|
|
2355
2407
|
const { id } = error;
|
|
2356
2408
|
if (!Object.keys(ALL_ERRORS).includes(name)) {
|
|
2357
|
-
console.error(spaceTrim$
|
|
2409
|
+
console.error(spaceTrim$2((block) => `
|
|
2358
2410
|
|
|
2359
2411
|
Cannot serialize error with name "${name}"
|
|
2360
2412
|
|
|
@@ -2460,7 +2512,7 @@ function jsonParse(value) {
|
|
|
2460
2512
|
}
|
|
2461
2513
|
else if (typeof value !== 'string') {
|
|
2462
2514
|
console.error('Can not parse JSON from non-string value.', { text: value });
|
|
2463
|
-
throw new Error(spaceTrim$
|
|
2515
|
+
throw new Error(spaceTrim$2(`
|
|
2464
2516
|
Can not parse JSON from non-string value.
|
|
2465
2517
|
|
|
2466
2518
|
The value type: ${typeof value}
|
|
@@ -2474,7 +2526,7 @@ function jsonParse(value) {
|
|
|
2474
2526
|
if (!(error instanceof Error)) {
|
|
2475
2527
|
throw error;
|
|
2476
2528
|
}
|
|
2477
|
-
throw new Error(spaceTrim$
|
|
2529
|
+
throw new Error(spaceTrim$2((block) => `
|
|
2478
2530
|
${block(error.message)}
|
|
2479
2531
|
|
|
2480
2532
|
The expected JSON text:
|
|
@@ -2674,7 +2726,7 @@ function templateParameters(template, parameters) {
|
|
|
2674
2726
|
*/
|
|
2675
2727
|
function prompt(strings, ...values) {
|
|
2676
2728
|
if (values.length === 0) {
|
|
2677
|
-
return spaceTrim$
|
|
2729
|
+
return spaceTrim$2(strings.join(''));
|
|
2678
2730
|
}
|
|
2679
2731
|
const stringsWithHiddenParameters = strings.map((stringsItem) =>
|
|
2680
2732
|
// TODO: [0] DRY
|
|
@@ -2685,7 +2737,7 @@ function prompt(strings, ...values) {
|
|
|
2685
2737
|
let pipelineString = stringsWithHiddenParameters.reduce((result, stringsItem, i) => placeholderParameterNames[i] === undefined
|
|
2686
2738
|
? `${result}${stringsItem}`
|
|
2687
2739
|
: `${result}${stringsItem}{${placeholderParameterNames[i]}}`, '');
|
|
2688
|
-
pipelineString = spaceTrim$
|
|
2740
|
+
pipelineString = spaceTrim$2(pipelineString);
|
|
2689
2741
|
try {
|
|
2690
2742
|
pipelineString = templateParameters(pipelineString, parameters);
|
|
2691
2743
|
}
|
|
@@ -2694,7 +2746,7 @@ function prompt(strings, ...values) {
|
|
|
2694
2746
|
throw error;
|
|
2695
2747
|
}
|
|
2696
2748
|
console.error({ pipelineString, parameters, placeholderParameterNames, error });
|
|
2697
|
-
throw new UnexpectedError(spaceTrim$
|
|
2749
|
+
throw new UnexpectedError(spaceTrim$2((block) => `
|
|
2698
2750
|
Internal error in prompt template literal
|
|
2699
2751
|
|
|
2700
2752
|
${block(JSON.stringify({ strings, values }, null, 4))}}
|
|
@@ -2981,7 +3033,7 @@ function $getCurrentDate() {
|
|
|
2981
3033
|
* @public exported from `@promptbook/utils`
|
|
2982
3034
|
*/
|
|
2983
3035
|
function computeHash(value) {
|
|
2984
|
-
return SHA256(hexEncoder.parse(spaceTrim$
|
|
3036
|
+
return SHA256(hexEncoder.parse(spaceTrim$2(valueToString(value)))).toString( /* hex */);
|
|
2985
3037
|
}
|
|
2986
3038
|
/**
|
|
2987
3039
|
* TODO: [🥬][🥬] Use this ACRY
|
|
@@ -3221,7 +3273,7 @@ function nameToUriParts(name) {
|
|
|
3221
3273
|
* @public exported from `@promptbook/utils`
|
|
3222
3274
|
*/
|
|
3223
3275
|
function normalizeMessageText(text) {
|
|
3224
|
-
return spaceTrim$
|
|
3276
|
+
return spaceTrim$1(text);
|
|
3225
3277
|
}
|
|
3226
3278
|
|
|
3227
3279
|
/**
|
|
@@ -3371,7 +3423,7 @@ function unwrapResult(text, options) {
|
|
|
3371
3423
|
let trimmedText = text;
|
|
3372
3424
|
// Remove leading and trailing spaces and newlines
|
|
3373
3425
|
if (isTrimmed) {
|
|
3374
|
-
trimmedText = spaceTrim$
|
|
3426
|
+
trimmedText = spaceTrim$1(trimmedText);
|
|
3375
3427
|
}
|
|
3376
3428
|
let processedText = trimmedText;
|
|
3377
3429
|
if (isIntroduceSentenceRemoved) {
|
|
@@ -3380,7 +3432,7 @@ function unwrapResult(text, options) {
|
|
|
3380
3432
|
// Remove the introduce sentence and quotes by replacing it with an empty string
|
|
3381
3433
|
processedText = processedText.replace(introduceSentenceRegex, '');
|
|
3382
3434
|
}
|
|
3383
|
-
processedText = spaceTrim$
|
|
3435
|
+
processedText = spaceTrim$1(processedText);
|
|
3384
3436
|
}
|
|
3385
3437
|
if (processedText.length < 3) {
|
|
3386
3438
|
return trimmedText;
|
|
@@ -3424,17 +3476,6 @@ function unwrapResult(text, options) {
|
|
|
3424
3476
|
* TODO: [🧠] Should this also unwrap the (parenthesis)
|
|
3425
3477
|
*/
|
|
3426
3478
|
|
|
3427
|
-
/**
|
|
3428
|
-
* Trims string from all 4 sides
|
|
3429
|
-
*
|
|
3430
|
-
* Note: This is a re-exported function from the `spacetrim` package which is
|
|
3431
|
-
* Developed by same author @hejny as this package
|
|
3432
|
-
*
|
|
3433
|
-
* @public exported from `@promptbook/utils`
|
|
3434
|
-
* @see https://github.com/hejny/spacetrim#usage
|
|
3435
|
-
*/
|
|
3436
|
-
const spaceTrim = spaceTrim$2;
|
|
3437
|
-
|
|
3438
3479
|
/**
|
|
3439
3480
|
* Parses the task and returns the list of all parameter names
|
|
3440
3481
|
*
|
|
@@ -3572,7 +3613,7 @@ function serializeToPromptbookJavascript(value) {
|
|
|
3572
3613
|
imports.push(`import { Color } from '@promptbook/color';`);
|
|
3573
3614
|
}
|
|
3574
3615
|
else if (typeof value === 'string') {
|
|
3575
|
-
const trimmed = spaceTrim$
|
|
3616
|
+
const trimmed = spaceTrim$2(value);
|
|
3576
3617
|
if (trimmed.includes('\n')) {
|
|
3577
3618
|
// Multiline string -> use `spaceTrim`
|
|
3578
3619
|
serializedValue = `spaceTrim(\`\n${value.replace(/`/g, '\\`')}\n\`)`;
|