@promptbook/node 0.88.0-9 → 0.89.0-1
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/README.md +35 -14
- package/esm/index.es.js +46 -10
- package/esm/index.es.js.map +1 -1
- package/esm/typings/src/_packages/core.index.d.ts +2 -2
- package/esm/typings/src/_packages/types.index.d.ts +10 -0
- package/esm/typings/src/config.d.ts +1 -1
- package/esm/typings/src/errors/PipelineExecutionError.d.ts +5 -0
- package/esm/typings/src/errors/utils/ErrorJson.d.ts +5 -0
- package/esm/typings/src/llm-providers/_common/utils/count-total-usage/LlmExecutionToolsWithTotalUsage.d.ts +7 -0
- package/esm/typings/src/llm-providers/_common/utils/count-total-usage/{countTotalUsage.d.ts → countUsage.d.ts} +1 -1
- package/esm/typings/src/playground/BrjappConnector.d.ts +64 -0
- package/esm/typings/src/playground/brjapp-api-schema.d.ts +12879 -0
- package/esm/typings/src/playground/playground.d.ts +5 -0
- package/esm/typings/src/remote-server/socket-types/_subtypes/PromptbookServer_Identification.d.ts +2 -1
- package/esm/typings/src/remote-server/types/RemoteServerOptions.d.ts +15 -3
- package/esm/typings/src/types/typeAliases.d.ts +2 -2
- package/esm/typings/src/utils/expectation-counters/countCharacters.d.ts +3 -0
- package/esm/typings/src/utils/expectation-counters/countLines.d.ts +3 -0
- package/esm/typings/src/utils/expectation-counters/countPages.d.ts +3 -0
- package/esm/typings/src/utils/expectation-counters/countParagraphs.d.ts +3 -0
- package/esm/typings/src/utils/expectation-counters/countSentences.d.ts +3 -0
- package/esm/typings/src/utils/expectation-counters/countWords.d.ts +3 -0
- package/package.json +2 -2
- package/umd/index.umd.js +46 -10
- package/umd/index.umd.js.map +1 -1
package/esm/typings/src/remote-server/socket-types/_subtypes/PromptbookServer_Identification.d.ts
CHANGED
|
@@ -37,7 +37,8 @@ export type PromptbookServer_AnonymousIdentification = {
|
|
|
37
37
|
/**
|
|
38
38
|
* Identifier of the end user
|
|
39
39
|
*
|
|
40
|
-
* Note:
|
|
40
|
+
* Note: This can be either some id or email or any other identifier
|
|
41
|
+
* Note: In anonymous mode, this is passed to the certain model providers to identify misuse
|
|
41
42
|
* Note: In anonymous mode, there is no need to identify yourself, nor does it change the actual configuration of LLM Tools (unlike in application mode)
|
|
42
43
|
*/
|
|
43
44
|
readonly userId?: string_user_id;
|
|
@@ -58,15 +58,27 @@ export type ApplicationRemoteServerOptions<TCustomOptions> = {
|
|
|
58
58
|
};
|
|
59
59
|
export type ApplicationRemoteServerClientOptions<TCustomOptions> = {
|
|
60
60
|
/**
|
|
61
|
-
*
|
|
61
|
+
* Identifier of the application
|
|
62
|
+
*
|
|
63
|
+
* Note: This is usefull when you use Promptbook remote server for multiple apps/frontends, if its used just for single app, use here just "app" or "your-app-name"
|
|
64
|
+
* Note: This can be some id or some semantic name like "email-agent"
|
|
62
65
|
*/
|
|
63
66
|
readonly appId: string_app_id | null;
|
|
64
67
|
/**
|
|
65
|
-
*
|
|
68
|
+
* Identifier of the end user
|
|
69
|
+
*
|
|
70
|
+
* Note: This can be either some id or email or any other identifier
|
|
71
|
+
* Note: This is also passed to the certain model providers to identify misuse
|
|
66
72
|
*/
|
|
67
73
|
readonly userId?: string_user_id;
|
|
68
74
|
/**
|
|
69
|
-
*
|
|
75
|
+
* Token of the user to verify its identity
|
|
76
|
+
*
|
|
77
|
+
* Note: This is passed for example to `createLlmExecutionTools`
|
|
78
|
+
*/
|
|
79
|
+
readonly userToken?: string_user_id;
|
|
80
|
+
/**
|
|
81
|
+
* Additional arbitrary options to identify the client or to pass custom metadata
|
|
70
82
|
*/
|
|
71
83
|
readonly customOptions?: TCustomOptions;
|
|
72
84
|
};
|
|
@@ -433,13 +433,13 @@ export type string_uuid = string & {
|
|
|
433
433
|
*
|
|
434
434
|
* @@@
|
|
435
435
|
*/
|
|
436
|
-
export type string_app_id = id;
|
|
436
|
+
export type string_app_id = id | 'app';
|
|
437
437
|
/**
|
|
438
438
|
* End user identifier
|
|
439
439
|
*
|
|
440
440
|
* @@@
|
|
441
441
|
*/
|
|
442
|
-
export type string_user_id = id;
|
|
442
|
+
export type string_user_id = id | string_email;
|
|
443
443
|
/**
|
|
444
444
|
* Semantic helper
|
|
445
445
|
*
|
|
@@ -5,3 +5,6 @@ import type { ExpectationAmount } from '../../pipeline/PipelineJson/Expectations
|
|
|
5
5
|
* @public exported from `@promptbook/utils`
|
|
6
6
|
*/
|
|
7
7
|
export declare function countCharacters(text: string): ExpectationAmount;
|
|
8
|
+
/**
|
|
9
|
+
* TODO: [🥴] Implement counting in formats - like JSON, CSV, XML,...
|
|
10
|
+
*/
|
|
@@ -7,3 +7,6 @@ import type { ExpectationAmount } from '../../pipeline/PipelineJson/Expectations
|
|
|
7
7
|
* @public exported from `@promptbook/utils`
|
|
8
8
|
*/
|
|
9
9
|
export declare function countLines(text: string): ExpectationAmount;
|
|
10
|
+
/**
|
|
11
|
+
* TODO: [🥴] Implement counting in formats - like JSON, CSV, XML,...
|
|
12
|
+
*/
|
|
@@ -7,3 +7,6 @@ import type { ExpectationAmount } from '../../pipeline/PipelineJson/Expectations
|
|
|
7
7
|
* @public exported from `@promptbook/utils`
|
|
8
8
|
*/
|
|
9
9
|
export declare function countPages(text: string): ExpectationAmount;
|
|
10
|
+
/**
|
|
11
|
+
* TODO: [🥴] Implement counting in formats - like JSON, CSV, XML,...
|
|
12
|
+
*/
|
|
@@ -5,3 +5,6 @@ import type { ExpectationAmount } from '../../pipeline/PipelineJson/Expectations
|
|
|
5
5
|
* @public exported from `@promptbook/utils`
|
|
6
6
|
*/
|
|
7
7
|
export declare function countParagraphs(text: string): ExpectationAmount;
|
|
8
|
+
/**
|
|
9
|
+
* TODO: [🥴] Implement counting in formats - like JSON, CSV, XML,...
|
|
10
|
+
*/
|
|
@@ -11,3 +11,6 @@ export declare function splitIntoSentences(text: string): ReadonlyArray<string>;
|
|
|
11
11
|
* @public exported from `@promptbook/utils`
|
|
12
12
|
*/
|
|
13
13
|
export declare function countSentences(text: string): ExpectationAmount;
|
|
14
|
+
/**
|
|
15
|
+
* TODO: [🥴] Implement counting in formats - like JSON, CSV, XML,...
|
|
16
|
+
*/
|
|
@@ -5,3 +5,6 @@ import type { ExpectationAmount } from '../../pipeline/PipelineJson/Expectations
|
|
|
5
5
|
* @public exported from `@promptbook/utils`
|
|
6
6
|
*/
|
|
7
7
|
export declare function countWords(text: string): ExpectationAmount;
|
|
8
|
+
/**
|
|
9
|
+
* TODO: [🥴] Implement counting in formats - like JSON, CSV, XML,...
|
|
10
|
+
*/
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@promptbook/node",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.89.0-1",
|
|
4
4
|
"description": "It's time for a paradigm shift. The future of software in plain English, French or Latin",
|
|
5
5
|
"private": false,
|
|
6
6
|
"sideEffects": false,
|
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
"module": "./esm/index.es.js",
|
|
48
48
|
"typings": "./esm/typings/src/_packages/node.index.d.ts",
|
|
49
49
|
"peerDependencies": {
|
|
50
|
-
"@promptbook/core": "0.
|
|
50
|
+
"@promptbook/core": "0.89.0-1"
|
|
51
51
|
},
|
|
52
52
|
"dependencies": {
|
|
53
53
|
"colors": "1.4.0",
|
package/umd/index.umd.js
CHANGED
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
* @generated
|
|
47
47
|
* @see https://github.com/webgptorg/promptbook
|
|
48
48
|
*/
|
|
49
|
-
const PROMPTBOOK_ENGINE_VERSION = '0.
|
|
49
|
+
const PROMPTBOOK_ENGINE_VERSION = '0.89.0-1';
|
|
50
50
|
/**
|
|
51
51
|
* TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
|
|
52
52
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
@@ -173,7 +173,7 @@
|
|
|
173
173
|
*
|
|
174
174
|
* @public exported from `@promptbook/core`
|
|
175
175
|
*/
|
|
176
|
-
const DEFAULT_MAX_EXECUTION_ATTEMPTS =
|
|
176
|
+
const DEFAULT_MAX_EXECUTION_ATTEMPTS = 10; // <- TODO: [🤹♂️]
|
|
177
177
|
// <- TODO: [🕝] Make also `BOOKS_DIRNAME_ALTERNATIVES`
|
|
178
178
|
/**
|
|
179
179
|
* Where to store the temporary downloads
|
|
@@ -1658,11 +1658,17 @@
|
|
|
1658
1658
|
*/
|
|
1659
1659
|
class PipelineExecutionError extends Error {
|
|
1660
1660
|
constructor(message) {
|
|
1661
|
+
// Added id parameter
|
|
1661
1662
|
super(message);
|
|
1662
1663
|
this.name = 'PipelineExecutionError';
|
|
1664
|
+
// TODO: [🐙] DRY - Maybe $randomId
|
|
1665
|
+
this.id = `error-${$randomToken(8 /* <- TODO: To global config + Use Base58 to avoid simmilar char conflicts */)}`;
|
|
1663
1666
|
Object.setPrototypeOf(this, PipelineExecutionError.prototype);
|
|
1664
1667
|
}
|
|
1665
1668
|
}
|
|
1669
|
+
/**
|
|
1670
|
+
* TODO: !!!!!! Add id to all errors
|
|
1671
|
+
*/
|
|
1666
1672
|
|
|
1667
1673
|
/**
|
|
1668
1674
|
* This error indicates problems parsing the format value
|
|
@@ -1850,7 +1856,7 @@
|
|
|
1850
1856
|
* @public exported from `@promptbook/utils`
|
|
1851
1857
|
*/
|
|
1852
1858
|
function deserializeError(error) {
|
|
1853
|
-
const { name, stack } = error;
|
|
1859
|
+
const { name, stack, id } = error; // Added id
|
|
1854
1860
|
let { message } = error;
|
|
1855
1861
|
let ErrorClass = ALL_ERRORS[error.name];
|
|
1856
1862
|
if (ErrorClass === undefined) {
|
|
@@ -1865,7 +1871,9 @@
|
|
|
1865
1871
|
${block(stack || '')}
|
|
1866
1872
|
`);
|
|
1867
1873
|
}
|
|
1868
|
-
|
|
1874
|
+
const deserializedError = new ErrorClass(message);
|
|
1875
|
+
deserializedError.id = id; // Assign id to the error object
|
|
1876
|
+
return deserializedError;
|
|
1869
1877
|
}
|
|
1870
1878
|
|
|
1871
1879
|
/**
|
|
@@ -1915,6 +1923,7 @@
|
|
|
1915
1923
|
*/
|
|
1916
1924
|
function createTask(options) {
|
|
1917
1925
|
const { taskType, taskProcessCallback } = options;
|
|
1926
|
+
// TODO: [🐙] DRY
|
|
1918
1927
|
const taskId = `${taskType.toLowerCase().substring(0, 4)}-${$randomToken(8 /* <- TODO: To global config + Use Base58 to avoid simmilar char conflicts */)}`;
|
|
1919
1928
|
let status = 'RUNNING';
|
|
1920
1929
|
const createdAt = new Date();
|
|
@@ -1947,7 +1956,7 @@
|
|
|
1947
1956
|
assertsTaskSuccessful(executionResult);
|
|
1948
1957
|
status = 'FINISHED';
|
|
1949
1958
|
currentValue = jsonStringsToJsons(executionResult);
|
|
1950
|
-
// <- TODO:
|
|
1959
|
+
// <- TODO: [🧠] Is this a good idea to convert JSON strins to JSONs?
|
|
1951
1960
|
partialResultSubject.next(executionResult);
|
|
1952
1961
|
}
|
|
1953
1962
|
catch (error) {
|
|
@@ -2011,19 +2020,21 @@
|
|
|
2011
2020
|
*/
|
|
2012
2021
|
function serializeError(error) {
|
|
2013
2022
|
const { name, message, stack } = error;
|
|
2023
|
+
const { id } = error;
|
|
2014
2024
|
if (!Object.keys(ALL_ERRORS).includes(name)) {
|
|
2015
2025
|
console.error(spaceTrim__default["default"]((block) => `
|
|
2016
|
-
|
|
2026
|
+
|
|
2017
2027
|
Cannot serialize error with name "${name}"
|
|
2018
2028
|
|
|
2019
2029
|
${block(stack || message)}
|
|
2020
|
-
|
|
2030
|
+
|
|
2021
2031
|
`));
|
|
2022
2032
|
}
|
|
2023
2033
|
return {
|
|
2024
2034
|
name: name,
|
|
2025
2035
|
message,
|
|
2026
2036
|
stack,
|
|
2037
|
+
id, // Include id in the serialized object
|
|
2027
2038
|
};
|
|
2028
2039
|
}
|
|
2029
2040
|
|
|
@@ -3066,6 +3077,9 @@
|
|
|
3066
3077
|
text = text.replace(/\p{Extended_Pictographic}(\u{200D}\p{Extended_Pictographic})*/gu, '-');
|
|
3067
3078
|
return text.length;
|
|
3068
3079
|
}
|
|
3080
|
+
/**
|
|
3081
|
+
* TODO: [🥴] Implement counting in formats - like JSON, CSV, XML,...
|
|
3082
|
+
*/
|
|
3069
3083
|
|
|
3070
3084
|
/**
|
|
3071
3085
|
* Number of characters per standard line with 11pt Arial font size.
|
|
@@ -3097,6 +3111,9 @@
|
|
|
3097
3111
|
const lines = text.split('\n');
|
|
3098
3112
|
return lines.reduce((count, line) => count + Math.ceil(line.length / CHARACTERS_PER_STANDARD_LINE), 0);
|
|
3099
3113
|
}
|
|
3114
|
+
/**
|
|
3115
|
+
* TODO: [🥴] Implement counting in formats - like JSON, CSV, XML,...
|
|
3116
|
+
*/
|
|
3100
3117
|
|
|
3101
3118
|
/**
|
|
3102
3119
|
* Counts number of pages in the text
|
|
@@ -3108,6 +3125,9 @@
|
|
|
3108
3125
|
function countPages(text) {
|
|
3109
3126
|
return Math.ceil(countLines(text) / LINES_PER_STANDARD_PAGE);
|
|
3110
3127
|
}
|
|
3128
|
+
/**
|
|
3129
|
+
* TODO: [🥴] Implement counting in formats - like JSON, CSV, XML,...
|
|
3130
|
+
*/
|
|
3111
3131
|
|
|
3112
3132
|
/**
|
|
3113
3133
|
* Counts number of paragraphs in the text
|
|
@@ -3117,6 +3137,9 @@
|
|
|
3117
3137
|
function countParagraphs(text) {
|
|
3118
3138
|
return text.split(/\n\s*\n/).filter((paragraph) => paragraph.trim() !== '').length;
|
|
3119
3139
|
}
|
|
3140
|
+
/**
|
|
3141
|
+
* TODO: [🥴] Implement counting in formats - like JSON, CSV, XML,...
|
|
3142
|
+
*/
|
|
3120
3143
|
|
|
3121
3144
|
/**
|
|
3122
3145
|
* Split text into sentences
|
|
@@ -3134,6 +3157,9 @@
|
|
|
3134
3157
|
function countSentences(text) {
|
|
3135
3158
|
return splitIntoSentences(text).length;
|
|
3136
3159
|
}
|
|
3160
|
+
/**
|
|
3161
|
+
* TODO: [🥴] Implement counting in formats - like JSON, CSV, XML,...
|
|
3162
|
+
*/
|
|
3137
3163
|
|
|
3138
3164
|
const defaultDiacriticsRemovalMap = [
|
|
3139
3165
|
{
|
|
@@ -3408,6 +3434,9 @@
|
|
|
3408
3434
|
text = text.replace(/([a-z])([A-Z])/g, '$1 $2');
|
|
3409
3435
|
return text.split(/[^a-zа-я0-9]+/i).filter((word) => word.length > 0).length;
|
|
3410
3436
|
}
|
|
3437
|
+
/**
|
|
3438
|
+
* TODO: [🥴] Implement counting in formats - like JSON, CSV, XML,...
|
|
3439
|
+
*/
|
|
3411
3440
|
|
|
3412
3441
|
/**
|
|
3413
3442
|
* Index of all counter functions
|
|
@@ -4463,8 +4492,9 @@
|
|
|
4463
4492
|
* @returns LLM tools with same functionality with added total cost counting
|
|
4464
4493
|
* @public exported from `@promptbook/core`
|
|
4465
4494
|
*/
|
|
4466
|
-
function
|
|
4495
|
+
function countUsage(llmTools) {
|
|
4467
4496
|
let totalUsage = ZERO_USAGE;
|
|
4497
|
+
const spending = new rxjs.Subject();
|
|
4468
4498
|
const proxyTools = {
|
|
4469
4499
|
get title() {
|
|
4470
4500
|
// TODO: [🧠] Maybe put here some suffix
|
|
@@ -4474,12 +4504,15 @@
|
|
|
4474
4504
|
// TODO: [🧠] Maybe put here some suffix
|
|
4475
4505
|
return llmTools.description;
|
|
4476
4506
|
},
|
|
4477
|
-
|
|
4507
|
+
checkConfiguration() {
|
|
4478
4508
|
return /* not await */ llmTools.checkConfiguration();
|
|
4479
4509
|
},
|
|
4480
4510
|
listModels() {
|
|
4481
4511
|
return /* not await */ llmTools.listModels();
|
|
4482
4512
|
},
|
|
4513
|
+
spending() {
|
|
4514
|
+
return spending.asObservable();
|
|
4515
|
+
},
|
|
4483
4516
|
getTotalUsage() {
|
|
4484
4517
|
// <- Note: [🥫] Not using getter `get totalUsage` but `getTotalUsage` to allow this object to be proxied
|
|
4485
4518
|
return totalUsage;
|
|
@@ -4490,6 +4523,7 @@
|
|
|
4490
4523
|
// console.info('[🚕] callChatModel through countTotalUsage');
|
|
4491
4524
|
const promptResult = await llmTools.callChatModel(prompt);
|
|
4492
4525
|
totalUsage = addUsage(totalUsage, promptResult.usage);
|
|
4526
|
+
spending.next(promptResult.usage);
|
|
4493
4527
|
return promptResult;
|
|
4494
4528
|
};
|
|
4495
4529
|
}
|
|
@@ -4498,6 +4532,7 @@
|
|
|
4498
4532
|
// console.info('[🚕] callCompletionModel through countTotalUsage');
|
|
4499
4533
|
const promptResult = await llmTools.callCompletionModel(prompt);
|
|
4500
4534
|
totalUsage = addUsage(totalUsage, promptResult.usage);
|
|
4535
|
+
spending.next(promptResult.usage);
|
|
4501
4536
|
return promptResult;
|
|
4502
4537
|
};
|
|
4503
4538
|
}
|
|
@@ -4506,6 +4541,7 @@
|
|
|
4506
4541
|
// console.info('[🚕] callEmbeddingModel through countTotalUsage');
|
|
4507
4542
|
const promptResult = await llmTools.callEmbeddingModel(prompt);
|
|
4508
4543
|
totalUsage = addUsage(totalUsage, promptResult.usage);
|
|
4544
|
+
spending.next(promptResult.usage);
|
|
4509
4545
|
return promptResult;
|
|
4510
4546
|
};
|
|
4511
4547
|
}
|
|
@@ -5318,7 +5354,7 @@
|
|
|
5318
5354
|
// TODO: [🚐] Make arrayable LLMs -> single LLM DRY
|
|
5319
5355
|
const _llms = arrayableToArray(tools.llm);
|
|
5320
5356
|
const llmTools = _llms.length === 1 ? _llms[0] : joinLlmExecutionTools(..._llms);
|
|
5321
|
-
const llmToolsWithUsage =
|
|
5357
|
+
const llmToolsWithUsage = countUsage(llmTools);
|
|
5322
5358
|
// <- TODO: [🌯]
|
|
5323
5359
|
/*
|
|
5324
5360
|
TODO: [🧠][🪑][🔃] Should this be done or not
|