@promptbook/browser 0.86.10 → 0.86.22
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 -42
- package/esm/index.es.js +259 -347
- package/esm/index.es.js.map +1 -1
- package/esm/typings/src/_packages/types.index.d.ts +2 -0
- package/esm/typings/src/conversion/utils/extractVariablesFromScript.d.ts +5 -5
- package/esm/typings/src/execution/AbstractTaskResult.d.ts +3 -3
- package/esm/typings/src/execution/PipelineExecutorResult.d.ts +1 -1
- package/esm/typings/src/execution/utils/usageToHuman.d.ts +11 -1
- package/esm/typings/src/execution/utils/usageToWorktime.d.ts +9 -1
- package/esm/typings/src/formats/_common/FormatDefinition.d.ts +1 -1
- package/esm/typings/src/formats/text/TextFormatDefinition.d.ts +1 -1
- package/esm/typings/src/llm-providers/multiple/MultipleLlmExecutionTools.d.ts +1 -1
- package/esm/typings/src/types/typeAliases.d.ts +6 -0
- package/package.json +2 -2
- package/umd/index.umd.js +259 -347
- package/umd/index.umd.js.map +1 -1
package/umd/index.umd.js
CHANGED
|
@@ -15,143 +15,31 @@
|
|
|
15
15
|
* @generated
|
|
16
16
|
* @see https://github.com/webgptorg/book
|
|
17
17
|
*/
|
|
18
|
-
|
|
18
|
+
const BOOK_LANGUAGE_VERSION = '1.0.0';
|
|
19
19
|
/**
|
|
20
20
|
* The version of the Promptbook engine
|
|
21
21
|
*
|
|
22
22
|
* @generated
|
|
23
23
|
* @see https://github.com/webgptorg/promptbook
|
|
24
24
|
*/
|
|
25
|
-
|
|
25
|
+
const PROMPTBOOK_ENGINE_VERSION = '0.86.22';
|
|
26
26
|
/**
|
|
27
27
|
* TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
|
|
28
28
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
29
29
|
*/
|
|
30
30
|
|
|
31
|
-
/*! *****************************************************************************
|
|
32
|
-
Copyright (c) Microsoft Corporation.
|
|
33
|
-
|
|
34
|
-
Permission to use, copy, modify, and/or distribute this software for any
|
|
35
|
-
purpose with or without fee is hereby granted.
|
|
36
|
-
|
|
37
|
-
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
38
|
-
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
39
|
-
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
40
|
-
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
41
|
-
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
42
|
-
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
43
|
-
PERFORMANCE OF THIS SOFTWARE.
|
|
44
|
-
***************************************************************************** */
|
|
45
|
-
/* global Reflect, Promise */
|
|
46
|
-
|
|
47
|
-
var extendStatics = function(d, b) {
|
|
48
|
-
extendStatics = Object.setPrototypeOf ||
|
|
49
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
50
|
-
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
51
|
-
return extendStatics(d, b);
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
function __extends(d, b) {
|
|
55
|
-
if (typeof b !== "function" && b !== null)
|
|
56
|
-
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
57
|
-
extendStatics(d, b);
|
|
58
|
-
function __() { this.constructor = d; }
|
|
59
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
var __assign = function() {
|
|
63
|
-
__assign = Object.assign || function __assign(t) {
|
|
64
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
65
|
-
s = arguments[i];
|
|
66
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
|
|
67
|
-
}
|
|
68
|
-
return t;
|
|
69
|
-
};
|
|
70
|
-
return __assign.apply(this, arguments);
|
|
71
|
-
};
|
|
72
|
-
|
|
73
|
-
function __awaiter(thisArg, _arguments, P, generator) {
|
|
74
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
75
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
76
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
77
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
78
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
79
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
80
|
-
});
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
function __generator(thisArg, body) {
|
|
84
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
85
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
86
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
87
|
-
function step(op) {
|
|
88
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
89
|
-
while (_) try {
|
|
90
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
91
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
92
|
-
switch (op[0]) {
|
|
93
|
-
case 0: case 1: t = op; break;
|
|
94
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
95
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
96
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
97
|
-
default:
|
|
98
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
99
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
100
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
101
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
102
|
-
if (t[2]) _.ops.pop();
|
|
103
|
-
_.trys.pop(); continue;
|
|
104
|
-
}
|
|
105
|
-
op = body.call(thisArg, _);
|
|
106
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
107
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
function __values(o) {
|
|
112
|
-
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
113
|
-
if (m) return m.call(o);
|
|
114
|
-
if (o && typeof o.length === "number") return {
|
|
115
|
-
next: function () {
|
|
116
|
-
if (o && i >= o.length) o = void 0;
|
|
117
|
-
return { value: o && o[i++], done: !o };
|
|
118
|
-
}
|
|
119
|
-
};
|
|
120
|
-
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
function __read(o, n) {
|
|
124
|
-
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
125
|
-
if (!m) return o;
|
|
126
|
-
var i = m.call(o), r, ar = [], e;
|
|
127
|
-
try {
|
|
128
|
-
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
129
|
-
}
|
|
130
|
-
catch (error) { e = { error: error }; }
|
|
131
|
-
finally {
|
|
132
|
-
try {
|
|
133
|
-
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
134
|
-
}
|
|
135
|
-
finally { if (e) throw e.error; }
|
|
136
|
-
}
|
|
137
|
-
return ar;
|
|
138
|
-
}
|
|
139
|
-
|
|
140
31
|
/**
|
|
141
32
|
* This error indicates errors during the execution of the pipeline
|
|
142
33
|
*
|
|
143
34
|
* @public exported from `@promptbook/core`
|
|
144
35
|
*/
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
Object.setPrototypeOf(_this, PipelineExecutionError.prototype);
|
|
151
|
-
return _this;
|
|
36
|
+
class PipelineExecutionError extends Error {
|
|
37
|
+
constructor(message) {
|
|
38
|
+
super(message);
|
|
39
|
+
this.name = 'PipelineExecutionError';
|
|
40
|
+
Object.setPrototypeOf(this, PipelineExecutionError.prototype);
|
|
152
41
|
}
|
|
153
|
-
|
|
154
|
-
}(Error));
|
|
42
|
+
}
|
|
155
43
|
|
|
156
44
|
/**
|
|
157
45
|
* Wrapper around `window.prompt` synchronous function that interacts with the user via browser prompt
|
|
@@ -161,31 +49,31 @@
|
|
|
161
49
|
*
|
|
162
50
|
* @public exported from `@promptbook/browser`
|
|
163
51
|
*/
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
if (options === void 0) { options = {}; }
|
|
52
|
+
class SimplePromptInterfaceTools {
|
|
53
|
+
constructor(options = {}) {
|
|
167
54
|
this.options = options;
|
|
168
55
|
}
|
|
169
56
|
/**
|
|
170
57
|
* Trigger window.prompt dialog
|
|
171
58
|
*/
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
59
|
+
async promptDialog(options) {
|
|
60
|
+
const answer = window.prompt(spaceTrim.spaceTrim((block) => `
|
|
61
|
+
${block(options.promptTitle)}
|
|
62
|
+
|
|
63
|
+
${block(options.promptMessage)}
|
|
64
|
+
`));
|
|
65
|
+
if (this.options.isVerbose) {
|
|
66
|
+
console.info(spaceTrim.spaceTrim((block) => `
|
|
67
|
+
📖 ${block(options.promptTitle)}
|
|
68
|
+
👤 ${block(answer || '🚫 User cancelled prompt')}
|
|
69
|
+
`));
|
|
70
|
+
}
|
|
71
|
+
if (answer === null) {
|
|
72
|
+
throw new PipelineExecutionError('User cancelled prompt');
|
|
73
|
+
}
|
|
74
|
+
return answer;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
189
77
|
/**
|
|
190
78
|
* Note: [🔵] Code in this file should never be published outside of `@promptbook/browser`
|
|
191
79
|
*/
|
|
@@ -195,16 +83,13 @@
|
|
|
195
83
|
*
|
|
196
84
|
* @public exported from `@promptbook/core`
|
|
197
85
|
*/
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
Object.setPrototypeOf(_this, EnvironmentMismatchError.prototype);
|
|
204
|
-
return _this;
|
|
86
|
+
class EnvironmentMismatchError extends Error {
|
|
87
|
+
constructor(message) {
|
|
88
|
+
super(message);
|
|
89
|
+
this.name = 'EnvironmentMismatchError';
|
|
90
|
+
Object.setPrototypeOf(this, EnvironmentMismatchError.prototype);
|
|
205
91
|
}
|
|
206
|
-
|
|
207
|
-
}(Error));
|
|
92
|
+
}
|
|
208
93
|
|
|
209
94
|
/**
|
|
210
95
|
* Detects if the code is running in a browser environment in main thread (Not in a web worker)
|
|
@@ -213,7 +98,13 @@
|
|
|
213
98
|
*
|
|
214
99
|
* @public exported from `@promptbook/utils`
|
|
215
100
|
*/
|
|
216
|
-
|
|
101
|
+
const $isRunningInBrowser = new Function(`
|
|
102
|
+
try {
|
|
103
|
+
return this === window;
|
|
104
|
+
} catch (e) {
|
|
105
|
+
return false;
|
|
106
|
+
}
|
|
107
|
+
`);
|
|
217
108
|
/**
|
|
218
109
|
* TODO: [🎺]
|
|
219
110
|
*/
|
|
@@ -225,7 +116,17 @@
|
|
|
225
116
|
*
|
|
226
117
|
* @public exported from `@promptbook/utils`
|
|
227
118
|
*/
|
|
228
|
-
|
|
119
|
+
const $isRunningInWebWorker = new Function(`
|
|
120
|
+
try {
|
|
121
|
+
if (typeof WorkerGlobalScope !== 'undefined' && self instanceof WorkerGlobalScope) {
|
|
122
|
+
return true;
|
|
123
|
+
} else {
|
|
124
|
+
return false;
|
|
125
|
+
}
|
|
126
|
+
} catch (e) {
|
|
127
|
+
return false;
|
|
128
|
+
}
|
|
129
|
+
`);
|
|
229
130
|
/**
|
|
230
131
|
* TODO: [🎺]
|
|
231
132
|
*/
|
|
@@ -237,26 +138,26 @@
|
|
|
237
138
|
*
|
|
238
139
|
* @public exported from `@promptbook/core`
|
|
239
140
|
*/
|
|
240
|
-
|
|
141
|
+
const NAME = `Promptbook`;
|
|
241
142
|
/**
|
|
242
143
|
* Email of the responsible person
|
|
243
144
|
*
|
|
244
145
|
* @public exported from `@promptbook/core`
|
|
245
146
|
*/
|
|
246
|
-
|
|
147
|
+
const ADMIN_EMAIL = 'pavol@ptbk.io';
|
|
247
148
|
/**
|
|
248
149
|
* Name of the responsible person for the Promptbook on GitHub
|
|
249
150
|
*
|
|
250
151
|
* @public exported from `@promptbook/core`
|
|
251
152
|
*/
|
|
252
|
-
|
|
153
|
+
const ADMIN_GITHUB_NAME = 'hejny';
|
|
253
154
|
// <- TODO: [🧠] Better system for generator warnings - not always "code" and "by `@promptbook/cli`"
|
|
254
155
|
/**
|
|
255
156
|
* The maximum number of iterations for a loops
|
|
256
157
|
*
|
|
257
158
|
* @private within the repository - too low-level in comparison with other `MAX_...`
|
|
258
159
|
*/
|
|
259
|
-
|
|
160
|
+
const LOOP_LIMIT = 1000;
|
|
260
161
|
// <- TODO: [🧜♂️]
|
|
261
162
|
/**
|
|
262
163
|
* @@@
|
|
@@ -279,16 +180,23 @@
|
|
|
279
180
|
*
|
|
280
181
|
* @public exported from `@promptbook/core`
|
|
281
182
|
*/
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
183
|
+
class NotYetImplementedError extends Error {
|
|
184
|
+
constructor(message) {
|
|
185
|
+
super(spaceTrim.spaceTrim((block) => `
|
|
186
|
+
${block(message)}
|
|
187
|
+
|
|
188
|
+
Note: This feature is not implemented yet but it will be soon.
|
|
189
|
+
|
|
190
|
+
If you want speed up the implementation or just read more, look here:
|
|
191
|
+
https://github.com/webgptorg/promptbook
|
|
192
|
+
|
|
193
|
+
Or contact us on pavol@ptbk.io
|
|
194
|
+
|
|
195
|
+
`));
|
|
196
|
+
this.name = 'NotYetImplementedError';
|
|
197
|
+
Object.setPrototypeOf(this, NotYetImplementedError.prototype);
|
|
289
198
|
}
|
|
290
|
-
|
|
291
|
-
}(Error));
|
|
199
|
+
}
|
|
292
200
|
|
|
293
201
|
/**
|
|
294
202
|
* Make error report URL for the given error
|
|
@@ -296,11 +204,37 @@
|
|
|
296
204
|
* @private private within the repository
|
|
297
205
|
*/
|
|
298
206
|
function getErrorReportUrl(error) {
|
|
299
|
-
|
|
300
|
-
title:
|
|
301
|
-
body: spaceTrim__default["default"](
|
|
207
|
+
const report = {
|
|
208
|
+
title: `🐜 Error report from ${NAME}`,
|
|
209
|
+
body: spaceTrim__default["default"]((block) => `
|
|
210
|
+
|
|
211
|
+
|
|
212
|
+
\`${error.name || 'Error'}\` has occurred in the [${NAME}], please look into it @${ADMIN_GITHUB_NAME}.
|
|
213
|
+
|
|
214
|
+
\`\`\`
|
|
215
|
+
${block(error.message || '(no error message)')}
|
|
216
|
+
\`\`\`
|
|
217
|
+
|
|
218
|
+
|
|
219
|
+
## More info:
|
|
220
|
+
|
|
221
|
+
- **Promptbook engine version:** ${PROMPTBOOK_ENGINE_VERSION}
|
|
222
|
+
- **Book language version:** ${BOOK_LANGUAGE_VERSION}
|
|
223
|
+
- **Time:** ${new Date().toISOString()}
|
|
224
|
+
|
|
225
|
+
<details>
|
|
226
|
+
<summary>Stack trace:</summary>
|
|
227
|
+
|
|
228
|
+
## Stack trace:
|
|
229
|
+
|
|
230
|
+
\`\`\`stacktrace
|
|
231
|
+
${block(error.stack || '(empty)')}
|
|
232
|
+
\`\`\`
|
|
233
|
+
</details>
|
|
234
|
+
|
|
235
|
+
`),
|
|
302
236
|
};
|
|
303
|
-
|
|
237
|
+
const reportUrl = new URL(`https://github.com/webgptorg/promptbook/issues/new`);
|
|
304
238
|
reportUrl.searchParams.set('labels', 'bug');
|
|
305
239
|
reportUrl.searchParams.set('assignees', ADMIN_GITHUB_NAME);
|
|
306
240
|
reportUrl.searchParams.set('title', report.title);
|
|
@@ -313,16 +247,24 @@
|
|
|
313
247
|
*
|
|
314
248
|
* @public exported from `@promptbook/core`
|
|
315
249
|
*/
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
250
|
+
class UnexpectedError extends Error {
|
|
251
|
+
constructor(message) {
|
|
252
|
+
super(spaceTrim.spaceTrim((block) => `
|
|
253
|
+
${block(message)}
|
|
254
|
+
|
|
255
|
+
Note: This error should not happen.
|
|
256
|
+
It's probbably a bug in the pipeline collection
|
|
257
|
+
|
|
258
|
+
Please report issue:
|
|
259
|
+
${block(getErrorReportUrl(new Error(message)).href)}
|
|
260
|
+
|
|
261
|
+
Or contact us on ${ADMIN_EMAIL}
|
|
262
|
+
|
|
263
|
+
`));
|
|
264
|
+
this.name = 'UnexpectedError';
|
|
265
|
+
Object.setPrototypeOf(this, UnexpectedError.prototype);
|
|
323
266
|
}
|
|
324
|
-
|
|
325
|
-
}(Error));
|
|
267
|
+
}
|
|
326
268
|
|
|
327
269
|
/**
|
|
328
270
|
* @@@
|
|
@@ -345,46 +287,35 @@
|
|
|
345
287
|
* @public exported from `@promptbook/utils`
|
|
346
288
|
*/
|
|
347
289
|
function normalizeTo_SCREAMING_CASE(text) {
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
if (/^[a-z]$/.test(char)) {
|
|
357
|
-
charType = 'LOWERCASE';
|
|
358
|
-
normalizedChar = char.toUpperCase();
|
|
359
|
-
}
|
|
360
|
-
else if (/^[A-Z]$/.test(char)) {
|
|
361
|
-
charType = 'UPPERCASE';
|
|
362
|
-
normalizedChar = char;
|
|
363
|
-
}
|
|
364
|
-
else if (/^[0-9]$/.test(char)) {
|
|
365
|
-
charType = 'NUMBER';
|
|
366
|
-
normalizedChar = char;
|
|
367
|
-
}
|
|
368
|
-
else {
|
|
369
|
-
charType = 'OTHER';
|
|
370
|
-
normalizedChar = '_';
|
|
371
|
-
}
|
|
372
|
-
if (charType !== lastCharType &&
|
|
373
|
-
!(lastCharType === 'UPPERCASE' && charType === 'LOWERCASE') &&
|
|
374
|
-
!(lastCharType === 'NUMBER') &&
|
|
375
|
-
!(charType === 'NUMBER')) {
|
|
376
|
-
normalizedName += '_';
|
|
377
|
-
}
|
|
378
|
-
normalizedName += normalizedChar;
|
|
379
|
-
lastCharType = charType;
|
|
290
|
+
let charType;
|
|
291
|
+
let lastCharType = 'OTHER';
|
|
292
|
+
let normalizedName = '';
|
|
293
|
+
for (const char of text) {
|
|
294
|
+
let normalizedChar;
|
|
295
|
+
if (/^[a-z]$/.test(char)) {
|
|
296
|
+
charType = 'LOWERCASE';
|
|
297
|
+
normalizedChar = char.toUpperCase();
|
|
380
298
|
}
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
299
|
+
else if (/^[A-Z]$/.test(char)) {
|
|
300
|
+
charType = 'UPPERCASE';
|
|
301
|
+
normalizedChar = char;
|
|
302
|
+
}
|
|
303
|
+
else if (/^[0-9]$/.test(char)) {
|
|
304
|
+
charType = 'NUMBER';
|
|
305
|
+
normalizedChar = char;
|
|
386
306
|
}
|
|
387
|
-
|
|
307
|
+
else {
|
|
308
|
+
charType = 'OTHER';
|
|
309
|
+
normalizedChar = '_';
|
|
310
|
+
}
|
|
311
|
+
if (charType !== lastCharType &&
|
|
312
|
+
!(lastCharType === 'UPPERCASE' && charType === 'LOWERCASE') &&
|
|
313
|
+
!(lastCharType === 'NUMBER') &&
|
|
314
|
+
!(charType === 'NUMBER')) {
|
|
315
|
+
normalizedName += '_';
|
|
316
|
+
}
|
|
317
|
+
normalizedName += normalizedChar;
|
|
318
|
+
lastCharType = charType;
|
|
388
319
|
}
|
|
389
320
|
normalizedName = normalizedName.replace(/_+/g, '_');
|
|
390
321
|
normalizedName = normalizedName.replace(/_?\/_?/g, '/');
|
|
@@ -421,27 +352,27 @@
|
|
|
421
352
|
*
|
|
422
353
|
* @private internal utility, exported are only signleton instances of this class
|
|
423
354
|
*/
|
|
424
|
-
|
|
425
|
-
|
|
355
|
+
class $Register {
|
|
356
|
+
constructor(registerName) {
|
|
426
357
|
this.registerName = registerName;
|
|
427
|
-
|
|
428
|
-
|
|
358
|
+
const storageName = `_promptbook_${normalizeTo_snake_case(registerName)}`;
|
|
359
|
+
const globalScope = $getGlobalScope();
|
|
429
360
|
if (globalScope[storageName] === undefined) {
|
|
430
361
|
globalScope[storageName] = [];
|
|
431
362
|
}
|
|
432
363
|
else if (!Array.isArray(globalScope[storageName])) {
|
|
433
|
-
throw new UnexpectedError(
|
|
364
|
+
throw new UnexpectedError(`Expected (global) ${storageName} to be an array, but got ${typeof globalScope[storageName]}`);
|
|
434
365
|
}
|
|
435
366
|
this.storage = globalScope[storageName];
|
|
436
367
|
}
|
|
437
|
-
|
|
368
|
+
list() {
|
|
438
369
|
// <- TODO: ReadonlyDeep<ReadonlyArray<TRegistered>>
|
|
439
370
|
return this.storage;
|
|
440
|
-
}
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
371
|
+
}
|
|
372
|
+
register(registered) {
|
|
373
|
+
const { packageName, className } = registered;
|
|
374
|
+
const existingRegistrationIndex = this.storage.findIndex((item) => item.packageName === packageName && item.className === className);
|
|
375
|
+
const existingRegistration = this.storage[existingRegistrationIndex];
|
|
445
376
|
if (!existingRegistration) {
|
|
446
377
|
this.storage.push(registered);
|
|
447
378
|
}
|
|
@@ -450,18 +381,17 @@
|
|
|
450
381
|
}
|
|
451
382
|
return {
|
|
452
383
|
registerName: this.registerName,
|
|
453
|
-
packageName
|
|
454
|
-
className
|
|
384
|
+
packageName,
|
|
385
|
+
className,
|
|
455
386
|
get isDestroyed() {
|
|
456
387
|
return false;
|
|
457
388
|
},
|
|
458
|
-
destroy
|
|
459
|
-
throw new NotYetImplementedError(
|
|
389
|
+
destroy() {
|
|
390
|
+
throw new NotYetImplementedError(`Registration to ${this.registerName} is permanent in this version of Promptbook`);
|
|
460
391
|
},
|
|
461
392
|
};
|
|
462
|
-
}
|
|
463
|
-
|
|
464
|
-
}());
|
|
393
|
+
}
|
|
394
|
+
}
|
|
465
395
|
|
|
466
396
|
/**
|
|
467
397
|
* @@@
|
|
@@ -470,7 +400,7 @@
|
|
|
470
400
|
* @singleton Only one instance of each register is created per build, but thare can be more @@@
|
|
471
401
|
* @public exported from `@promptbook/core`
|
|
472
402
|
*/
|
|
473
|
-
|
|
403
|
+
const $scrapersRegister = new $Register('scraper_constructors');
|
|
474
404
|
/**
|
|
475
405
|
* TODO: [®] DRY Register logic
|
|
476
406
|
*/
|
|
@@ -483,52 +413,20 @@
|
|
|
483
413
|
*
|
|
484
414
|
* @public exported from `@promptbook/browser`
|
|
485
415
|
*/
|
|
486
|
-
function $provideScrapersForBrowser(tools, options) {
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
scrapers = [];
|
|
501
|
-
_d.label = 1;
|
|
502
|
-
case 1:
|
|
503
|
-
_d.trys.push([1, 6, 7, 8]);
|
|
504
|
-
_a = __values($scrapersRegister.list()), _b = _a.next();
|
|
505
|
-
_d.label = 2;
|
|
506
|
-
case 2:
|
|
507
|
-
if (!!_b.done) return [3 /*break*/, 5];
|
|
508
|
-
scraperFactory = _b.value;
|
|
509
|
-
return [4 /*yield*/, scraperFactory(tools, options || {})];
|
|
510
|
-
case 3:
|
|
511
|
-
scraper = _d.sent();
|
|
512
|
-
scrapers.push(scraper);
|
|
513
|
-
_d.label = 4;
|
|
514
|
-
case 4:
|
|
515
|
-
_b = _a.next();
|
|
516
|
-
return [3 /*break*/, 2];
|
|
517
|
-
case 5: return [3 /*break*/, 8];
|
|
518
|
-
case 6:
|
|
519
|
-
e_1_1 = _d.sent();
|
|
520
|
-
e_1 = { error: e_1_1 };
|
|
521
|
-
return [3 /*break*/, 8];
|
|
522
|
-
case 7:
|
|
523
|
-
try {
|
|
524
|
-
if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
|
|
525
|
-
}
|
|
526
|
-
finally { if (e_1) throw e_1.error; }
|
|
527
|
-
return [7 /*endfinally*/];
|
|
528
|
-
case 8: return [2 /*return*/, scrapers];
|
|
529
|
-
}
|
|
530
|
-
});
|
|
531
|
-
});
|
|
416
|
+
async function $provideScrapersForBrowser(tools, options) {
|
|
417
|
+
if (!$isRunningInBrowser() || $isRunningInWebWorker()) {
|
|
418
|
+
throw new EnvironmentMismatchError('Function `$provideScrapersForBrowser` works only in browser environment');
|
|
419
|
+
}
|
|
420
|
+
const { isAutoInstalled /* Note: [0] Intentionally not assigning a default value = IS_AUTO_INSTALLED */ } = options || {};
|
|
421
|
+
if (isAutoInstalled === true /* <- Note: [0] Ignoring undefined, just checking EXPLICIT requirement for install */) {
|
|
422
|
+
throw new EnvironmentMismatchError('Auto-installing is not supported in browser environment');
|
|
423
|
+
}
|
|
424
|
+
const scrapers = [];
|
|
425
|
+
for (const scraperFactory of $scrapersRegister.list()) {
|
|
426
|
+
const scraper = await scraperFactory(tools, options || {});
|
|
427
|
+
scrapers.push(scraper);
|
|
428
|
+
}
|
|
429
|
+
return scrapers;
|
|
532
430
|
}
|
|
533
431
|
|
|
534
432
|
/**
|
|
@@ -538,8 +436,11 @@
|
|
|
538
436
|
* @public exported from `@promptbook/utils`
|
|
539
437
|
*/
|
|
540
438
|
function orderJson(options) {
|
|
541
|
-
|
|
542
|
-
|
|
439
|
+
const { value, order } = options;
|
|
440
|
+
const orderedValue = {
|
|
441
|
+
...(order === undefined ? {} : Object.fromEntries(order.map((key) => [key, undefined]))),
|
|
442
|
+
...value,
|
|
443
|
+
};
|
|
543
444
|
return orderedValue;
|
|
544
445
|
}
|
|
545
446
|
|
|
@@ -553,26 +454,15 @@
|
|
|
553
454
|
* @public exported from `@promptbook/utils`
|
|
554
455
|
*/
|
|
555
456
|
function $deepFreeze(objectValue) {
|
|
556
|
-
var e_1, _a;
|
|
557
457
|
if (Array.isArray(objectValue)) {
|
|
558
|
-
return Object.freeze(objectValue.map(
|
|
559
|
-
}
|
|
560
|
-
var propertyNames = Object.getOwnPropertyNames(objectValue);
|
|
561
|
-
try {
|
|
562
|
-
for (var propertyNames_1 = __values(propertyNames), propertyNames_1_1 = propertyNames_1.next(); !propertyNames_1_1.done; propertyNames_1_1 = propertyNames_1.next()) {
|
|
563
|
-
var propertyName = propertyNames_1_1.value;
|
|
564
|
-
var value = objectValue[propertyName];
|
|
565
|
-
if (value && typeof value === 'object') {
|
|
566
|
-
$deepFreeze(value);
|
|
567
|
-
}
|
|
568
|
-
}
|
|
458
|
+
return Object.freeze(objectValue.map((item) => $deepFreeze(item)));
|
|
569
459
|
}
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
460
|
+
const propertyNames = Object.getOwnPropertyNames(objectValue);
|
|
461
|
+
for (const propertyName of propertyNames) {
|
|
462
|
+
const value = objectValue[propertyName];
|
|
463
|
+
if (value && typeof value === 'object') {
|
|
464
|
+
$deepFreeze(value);
|
|
574
465
|
}
|
|
575
|
-
finally { if (e_1) throw e_1.error; }
|
|
576
466
|
}
|
|
577
467
|
Object.freeze(objectValue);
|
|
578
468
|
return objectValue;
|
|
@@ -602,10 +492,9 @@
|
|
|
602
492
|
* @public exported from `@promptbook/utils`
|
|
603
493
|
*/
|
|
604
494
|
function checkSerializableAsJson(options) {
|
|
605
|
-
|
|
606
|
-
var value = options.value, name = options.name, message = options.message;
|
|
495
|
+
const { value, name, message } = options;
|
|
607
496
|
if (value === undefined) {
|
|
608
|
-
throw new UnexpectedError(
|
|
497
|
+
throw new UnexpectedError(`${name} is undefined`);
|
|
609
498
|
}
|
|
610
499
|
else if (value === null) {
|
|
611
500
|
return;
|
|
@@ -620,49 +509,54 @@
|
|
|
620
509
|
return;
|
|
621
510
|
}
|
|
622
511
|
else if (typeof value === 'symbol') {
|
|
623
|
-
throw new UnexpectedError(
|
|
512
|
+
throw new UnexpectedError(`${name} is symbol`);
|
|
624
513
|
}
|
|
625
514
|
else if (typeof value === 'function') {
|
|
626
|
-
throw new UnexpectedError(
|
|
515
|
+
throw new UnexpectedError(`${name} is function`);
|
|
627
516
|
}
|
|
628
517
|
else if (typeof value === 'object' && Array.isArray(value)) {
|
|
629
|
-
for (
|
|
630
|
-
checkSerializableAsJson({ name:
|
|
518
|
+
for (let i = 0; i < value.length; i++) {
|
|
519
|
+
checkSerializableAsJson({ name: `${name}[${i}]`, value: value[i], message });
|
|
631
520
|
}
|
|
632
521
|
}
|
|
633
522
|
else if (typeof value === 'object') {
|
|
634
523
|
if (value instanceof Date) {
|
|
635
|
-
throw new UnexpectedError(spaceTrim__default["default"](
|
|
524
|
+
throw new UnexpectedError(spaceTrim__default["default"]((block) => `
|
|
525
|
+
\`${name}\` is Date
|
|
526
|
+
|
|
527
|
+
Use \`string_date_iso8601\` instead
|
|
528
|
+
|
|
529
|
+
Additional message for \`${name}\`:
|
|
530
|
+
${block(message || '(nothing)')}
|
|
531
|
+
`));
|
|
636
532
|
}
|
|
637
533
|
else if (value instanceof Map) {
|
|
638
|
-
throw new UnexpectedError(
|
|
534
|
+
throw new UnexpectedError(`${name} is Map`);
|
|
639
535
|
}
|
|
640
536
|
else if (value instanceof Set) {
|
|
641
|
-
throw new UnexpectedError(
|
|
537
|
+
throw new UnexpectedError(`${name} is Set`);
|
|
642
538
|
}
|
|
643
539
|
else if (value instanceof RegExp) {
|
|
644
|
-
throw new UnexpectedError(
|
|
540
|
+
throw new UnexpectedError(`${name} is RegExp`);
|
|
645
541
|
}
|
|
646
542
|
else if (value instanceof Error) {
|
|
647
|
-
throw new UnexpectedError(spaceTrim__default["default"](
|
|
543
|
+
throw new UnexpectedError(spaceTrim__default["default"]((block) => `
|
|
544
|
+
\`${name}\` is unserialized Error
|
|
545
|
+
|
|
546
|
+
Use function \`serializeError\`
|
|
547
|
+
|
|
548
|
+
Additional message for \`${name}\`:
|
|
549
|
+
${block(message || '(nothing)')}
|
|
550
|
+
|
|
551
|
+
`));
|
|
648
552
|
}
|
|
649
553
|
else {
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
// Note: undefined in object is serializable - it is just omited
|
|
655
|
-
continue;
|
|
656
|
-
}
|
|
657
|
-
checkSerializableAsJson({ name: "".concat(name, ".").concat(subName), value: subValue, message: message });
|
|
658
|
-
}
|
|
659
|
-
}
|
|
660
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
661
|
-
finally {
|
|
662
|
-
try {
|
|
663
|
-
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
554
|
+
for (const [subName, subValue] of Object.entries(value)) {
|
|
555
|
+
if (subValue === undefined) {
|
|
556
|
+
// Note: undefined in object is serializable - it is just omited
|
|
557
|
+
continue;
|
|
664
558
|
}
|
|
665
|
-
|
|
559
|
+
checkSerializableAsJson({ name: `${name}.${subName}`, value: subValue, message });
|
|
666
560
|
}
|
|
667
561
|
try {
|
|
668
562
|
JSON.stringify(value); // <- TODO: [0]
|
|
@@ -671,7 +565,14 @@
|
|
|
671
565
|
if (!(error instanceof Error)) {
|
|
672
566
|
throw error;
|
|
673
567
|
}
|
|
674
|
-
throw new UnexpectedError(spaceTrim__default["default"](
|
|
568
|
+
throw new UnexpectedError(spaceTrim__default["default"]((block) => `
|
|
569
|
+
\`${name}\` is not serializable
|
|
570
|
+
|
|
571
|
+
${block(error.stack || error.message)}
|
|
572
|
+
|
|
573
|
+
Additional message for \`${name}\`:
|
|
574
|
+
${block(message || '(nothing)')}
|
|
575
|
+
`));
|
|
675
576
|
}
|
|
676
577
|
/*
|
|
677
578
|
TODO: [0] Is there some more elegant way to check circular references?
|
|
@@ -696,7 +597,12 @@
|
|
|
696
597
|
}
|
|
697
598
|
}
|
|
698
599
|
else {
|
|
699
|
-
throw new UnexpectedError(spaceTrim__default["default"](
|
|
600
|
+
throw new UnexpectedError(spaceTrim__default["default"]((block) => `
|
|
601
|
+
\`${name}\` is unknown type
|
|
602
|
+
|
|
603
|
+
Additional message for \`${name}\`:
|
|
604
|
+
${block(message || '(nothing)')}
|
|
605
|
+
`));
|
|
700
606
|
}
|
|
701
607
|
}
|
|
702
608
|
/**
|
|
@@ -742,9 +648,9 @@
|
|
|
742
648
|
* @public exported from `@promptbook/utils`
|
|
743
649
|
*/
|
|
744
650
|
function exportJson(options) {
|
|
745
|
-
|
|
746
|
-
checkSerializableAsJson({ name
|
|
747
|
-
|
|
651
|
+
const { name, value, order, message } = options;
|
|
652
|
+
checkSerializableAsJson({ name, value, message });
|
|
653
|
+
const orderedValue =
|
|
748
654
|
// TODO: Fix error "Type instantiation is excessively deep and possibly infinite."
|
|
749
655
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
750
656
|
// @ts-ignore
|
|
@@ -767,7 +673,7 @@
|
|
|
767
673
|
*
|
|
768
674
|
* @private within the repository
|
|
769
675
|
*/
|
|
770
|
-
|
|
676
|
+
const REPLACING_NONCE = 'ptbkauk42kV2dzao34faw7FudQUHYPtW';
|
|
771
677
|
/**
|
|
772
678
|
* The names of the parameters that are reserved for special purposes
|
|
773
679
|
*
|
|
@@ -775,7 +681,7 @@
|
|
|
775
681
|
*/
|
|
776
682
|
exportJson({
|
|
777
683
|
name: 'RESERVED_PARAMETER_NAMES',
|
|
778
|
-
message:
|
|
684
|
+
message: `The names of the parameters that are reserved for special purposes`,
|
|
779
685
|
value: [
|
|
780
686
|
'content',
|
|
781
687
|
'context',
|
|
@@ -814,7 +720,7 @@
|
|
|
814
720
|
*/
|
|
815
721
|
function isSerializableAsJson(value) {
|
|
816
722
|
try {
|
|
817
|
-
checkSerializableAsJson({ value
|
|
723
|
+
checkSerializableAsJson({ value });
|
|
818
724
|
return true;
|
|
819
725
|
}
|
|
820
726
|
catch (error) {
|
|
@@ -836,11 +742,17 @@
|
|
|
836
742
|
*/
|
|
837
743
|
function stringifyPipelineJson(pipeline) {
|
|
838
744
|
if (!isSerializableAsJson(pipeline)) {
|
|
839
|
-
throw new UnexpectedError(spaceTrim__default["default"](
|
|
745
|
+
throw new UnexpectedError(spaceTrim__default["default"](`
|
|
746
|
+
Cannot stringify the pipeline, because it is not serializable as JSON
|
|
747
|
+
|
|
748
|
+
There can be multiple reasons:
|
|
749
|
+
1) The pipeline contains circular references
|
|
750
|
+
2) It is not a valid PipelineJson
|
|
751
|
+
`));
|
|
840
752
|
}
|
|
841
|
-
|
|
842
|
-
for (
|
|
843
|
-
pipelineJsonStringified = pipelineJsonStringified.replace(/(-?0\.\d+),[\n\s]+(-?0\.\d+)/gms,
|
|
753
|
+
let pipelineJsonStringified = JSON.stringify(pipeline, null, 4);
|
|
754
|
+
for (let i = 0; i < LOOP_LIMIT; i++) {
|
|
755
|
+
pipelineJsonStringified = pipelineJsonStringified.replace(/(-?0\.\d+),[\n\s]+(-?0\.\d+)/gms, `$1${REPLACING_NONCE}$2`);
|
|
844
756
|
}
|
|
845
757
|
pipelineJsonStringified = pipelineJsonStringified.split(REPLACING_NONCE).join(', ');
|
|
846
758
|
pipelineJsonStringified += '\n';
|
|
@@ -860,23 +772,23 @@
|
|
|
860
772
|
*/
|
|
861
773
|
function makePromptbookStorageFromWebStorage(webStorage) {
|
|
862
774
|
return {
|
|
863
|
-
getItem
|
|
864
|
-
|
|
775
|
+
getItem(key) {
|
|
776
|
+
const stringValue = webStorage.getItem(key);
|
|
865
777
|
if (stringValue === null) {
|
|
866
778
|
return null;
|
|
867
779
|
}
|
|
868
|
-
|
|
780
|
+
const value = JSON.parse(stringValue);
|
|
869
781
|
// TODO: [🌗]
|
|
870
782
|
return value;
|
|
871
783
|
},
|
|
872
|
-
setItem
|
|
784
|
+
setItem(key, value) {
|
|
873
785
|
if (!isSerializableAsJson(value)) {
|
|
874
|
-
throw new UnexpectedError(
|
|
786
|
+
throw new UnexpectedError(`The "${key}" you want to store in web storage is not serializable as JSON`);
|
|
875
787
|
}
|
|
876
|
-
|
|
788
|
+
const stringValue = stringifyPipelineJson(value);
|
|
877
789
|
webStorage.setItem(key, stringValue);
|
|
878
790
|
},
|
|
879
|
-
removeItem
|
|
791
|
+
removeItem(key) {
|
|
880
792
|
webStorage.removeItem(key);
|
|
881
793
|
},
|
|
882
794
|
};
|
|
@@ -893,7 +805,7 @@
|
|
|
893
805
|
*/
|
|
894
806
|
function getLocalStorage() {
|
|
895
807
|
if (!core.isRunningInBrowser()) {
|
|
896
|
-
throw new EnvironmentMismatchError(
|
|
808
|
+
throw new EnvironmentMismatchError(`You can get localStorage works only in browser environment`);
|
|
897
809
|
}
|
|
898
810
|
return makePromptbookStorageFromWebStorage(localStorage);
|
|
899
811
|
}
|
|
@@ -908,7 +820,7 @@
|
|
|
908
820
|
*/
|
|
909
821
|
function getSessionStorage() {
|
|
910
822
|
if (!core.isRunningInBrowser()) {
|
|
911
|
-
throw new EnvironmentMismatchError(
|
|
823
|
+
throw new EnvironmentMismatchError(`You can get sessionStorage works only in browser environment`);
|
|
912
824
|
}
|
|
913
825
|
return makePromptbookStorageFromWebStorage(sessionStorage);
|
|
914
826
|
}
|