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