@promptbook/deepseek 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 +339 -437
- 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 +339 -437
- package/umd/index.umd.js.map +1 -1
package/umd/index.umd.js
CHANGED
|
@@ -16,138 +16,19 @@
|
|
|
16
16
|
* @generated
|
|
17
17
|
* @see https://github.com/webgptorg/book
|
|
18
18
|
*/
|
|
19
|
-
|
|
19
|
+
const BOOK_LANGUAGE_VERSION = '1.0.0';
|
|
20
20
|
/**
|
|
21
21
|
* The version of the Promptbook engine
|
|
22
22
|
*
|
|
23
23
|
* @generated
|
|
24
24
|
* @see https://github.com/webgptorg/promptbook
|
|
25
25
|
*/
|
|
26
|
-
|
|
26
|
+
const PROMPTBOOK_ENGINE_VERSION = '0.86.22';
|
|
27
27
|
/**
|
|
28
28
|
* TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
|
|
29
29
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
30
30
|
*/
|
|
31
31
|
|
|
32
|
-
/*! *****************************************************************************
|
|
33
|
-
Copyright (c) Microsoft Corporation.
|
|
34
|
-
|
|
35
|
-
Permission to use, copy, modify, and/or distribute this software for any
|
|
36
|
-
purpose with or without fee is hereby granted.
|
|
37
|
-
|
|
38
|
-
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
39
|
-
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
40
|
-
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
41
|
-
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
42
|
-
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
43
|
-
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
44
|
-
PERFORMANCE OF THIS SOFTWARE.
|
|
45
|
-
***************************************************************************** */
|
|
46
|
-
/* global Reflect, Promise */
|
|
47
|
-
|
|
48
|
-
var extendStatics = function(d, b) {
|
|
49
|
-
extendStatics = Object.setPrototypeOf ||
|
|
50
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
51
|
-
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
52
|
-
return extendStatics(d, b);
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
function __extends(d, b) {
|
|
56
|
-
if (typeof b !== "function" && b !== null)
|
|
57
|
-
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
58
|
-
extendStatics(d, b);
|
|
59
|
-
function __() { this.constructor = d; }
|
|
60
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
var __assign = function() {
|
|
64
|
-
__assign = Object.assign || function __assign(t) {
|
|
65
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
66
|
-
s = arguments[i];
|
|
67
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
|
|
68
|
-
}
|
|
69
|
-
return t;
|
|
70
|
-
};
|
|
71
|
-
return __assign.apply(this, arguments);
|
|
72
|
-
};
|
|
73
|
-
|
|
74
|
-
function __awaiter(thisArg, _arguments, P, generator) {
|
|
75
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
76
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
77
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
78
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
79
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
80
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
81
|
-
});
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
function __generator(thisArg, body) {
|
|
85
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
86
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
87
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
88
|
-
function step(op) {
|
|
89
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
90
|
-
while (_) try {
|
|
91
|
-
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;
|
|
92
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
93
|
-
switch (op[0]) {
|
|
94
|
-
case 0: case 1: t = op; break;
|
|
95
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
96
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
97
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
98
|
-
default:
|
|
99
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
100
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
101
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
102
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
103
|
-
if (t[2]) _.ops.pop();
|
|
104
|
-
_.trys.pop(); continue;
|
|
105
|
-
}
|
|
106
|
-
op = body.call(thisArg, _);
|
|
107
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
108
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
function __values(o) {
|
|
113
|
-
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
114
|
-
if (m) return m.call(o);
|
|
115
|
-
if (o && typeof o.length === "number") return {
|
|
116
|
-
next: function () {
|
|
117
|
-
if (o && i >= o.length) o = void 0;
|
|
118
|
-
return { value: o && o[i++], done: !o };
|
|
119
|
-
}
|
|
120
|
-
};
|
|
121
|
-
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
function __read(o, n) {
|
|
125
|
-
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
126
|
-
if (!m) return o;
|
|
127
|
-
var i = m.call(o), r, ar = [], e;
|
|
128
|
-
try {
|
|
129
|
-
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
130
|
-
}
|
|
131
|
-
catch (error) { e = { error: error }; }
|
|
132
|
-
finally {
|
|
133
|
-
try {
|
|
134
|
-
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
135
|
-
}
|
|
136
|
-
finally { if (e) throw e.error; }
|
|
137
|
-
}
|
|
138
|
-
return ar;
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
function __spreadArray(to, from, pack) {
|
|
142
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
143
|
-
if (ar || !(i in from)) {
|
|
144
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
145
|
-
ar[i] = from[i];
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
149
|
-
}
|
|
150
|
-
|
|
151
32
|
/**
|
|
152
33
|
* Detects if the code is running in jest environment
|
|
153
34
|
*
|
|
@@ -155,7 +36,13 @@
|
|
|
155
36
|
*
|
|
156
37
|
* @public exported from `@promptbook/utils`
|
|
157
38
|
*/
|
|
158
|
-
|
|
39
|
+
const $isRunningInJest = new Function(`
|
|
40
|
+
try {
|
|
41
|
+
return process.env.JEST_WORKER_ID !== undefined;
|
|
42
|
+
} catch (e) {
|
|
43
|
+
return false;
|
|
44
|
+
}
|
|
45
|
+
`);
|
|
159
46
|
/**
|
|
160
47
|
* TODO: [🎺]
|
|
161
48
|
*/
|
|
@@ -165,16 +52,13 @@
|
|
|
165
52
|
*
|
|
166
53
|
* @public exported from `@promptbook/core`
|
|
167
54
|
*/
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
Object.setPrototypeOf(_this, PipelineExecutionError.prototype);
|
|
174
|
-
return _this;
|
|
55
|
+
class PipelineExecutionError extends Error {
|
|
56
|
+
constructor(message) {
|
|
57
|
+
super(message);
|
|
58
|
+
this.name = 'PipelineExecutionError';
|
|
59
|
+
Object.setPrototypeOf(this, PipelineExecutionError.prototype);
|
|
175
60
|
}
|
|
176
|
-
|
|
177
|
-
}(Error));
|
|
61
|
+
}
|
|
178
62
|
|
|
179
63
|
/**
|
|
180
64
|
* Freezes the given object and all its nested objects recursively
|
|
@@ -186,27 +70,16 @@
|
|
|
186
70
|
* @public exported from `@promptbook/utils`
|
|
187
71
|
*/
|
|
188
72
|
function $deepFreeze(objectValue) {
|
|
189
|
-
var e_1, _a;
|
|
190
73
|
if (Array.isArray(objectValue)) {
|
|
191
|
-
return Object.freeze(objectValue.map(
|
|
74
|
+
return Object.freeze(objectValue.map((item) => $deepFreeze(item)));
|
|
192
75
|
}
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
if (value && typeof value === 'object') {
|
|
199
|
-
$deepFreeze(value);
|
|
200
|
-
}
|
|
76
|
+
const propertyNames = Object.getOwnPropertyNames(objectValue);
|
|
77
|
+
for (const propertyName of propertyNames) {
|
|
78
|
+
const value = objectValue[propertyName];
|
|
79
|
+
if (value && typeof value === 'object') {
|
|
80
|
+
$deepFreeze(value);
|
|
201
81
|
}
|
|
202
82
|
}
|
|
203
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
204
|
-
finally {
|
|
205
|
-
try {
|
|
206
|
-
if (propertyNames_1_1 && !propertyNames_1_1.done && (_a = propertyNames_1.return)) _a.call(propertyNames_1);
|
|
207
|
-
}
|
|
208
|
-
finally { if (e_1) throw e_1.error; }
|
|
209
|
-
}
|
|
210
83
|
Object.freeze(objectValue);
|
|
211
84
|
return objectValue;
|
|
212
85
|
}
|
|
@@ -245,7 +118,7 @@
|
|
|
245
118
|
*
|
|
246
119
|
* @public exported from `@promptbook/core`
|
|
247
120
|
*/
|
|
248
|
-
|
|
121
|
+
const UNCERTAIN_USAGE = $deepFreeze({
|
|
249
122
|
price: { value: 0, isUncertain: true },
|
|
250
123
|
input: {
|
|
251
124
|
tokensCount: { value: 0, isUncertain: true },
|
|
@@ -289,32 +162,32 @@
|
|
|
289
162
|
*
|
|
290
163
|
* @public exported from `@promptbook/core`
|
|
291
164
|
*/
|
|
292
|
-
|
|
165
|
+
const NAME = `Promptbook`;
|
|
293
166
|
/**
|
|
294
167
|
* Email of the responsible person
|
|
295
168
|
*
|
|
296
169
|
* @public exported from `@promptbook/core`
|
|
297
170
|
*/
|
|
298
|
-
|
|
171
|
+
const ADMIN_EMAIL = 'pavol@ptbk.io';
|
|
299
172
|
/**
|
|
300
173
|
* Name of the responsible person for the Promptbook on GitHub
|
|
301
174
|
*
|
|
302
175
|
* @public exported from `@promptbook/core`
|
|
303
176
|
*/
|
|
304
|
-
|
|
177
|
+
const ADMIN_GITHUB_NAME = 'hejny';
|
|
305
178
|
// <- TODO: [🧠] Better system for generator warnings - not always "code" and "by `@promptbook/cli`"
|
|
306
179
|
/**
|
|
307
180
|
* The maximum number of iterations for a loops
|
|
308
181
|
*
|
|
309
182
|
* @private within the repository - too low-level in comparison with other `MAX_...`
|
|
310
183
|
*/
|
|
311
|
-
|
|
184
|
+
const LOOP_LIMIT = 1000;
|
|
312
185
|
/**
|
|
313
186
|
* Strings to represent various values in the context of parameter values
|
|
314
187
|
*
|
|
315
188
|
* @public exported from `@promptbook/utils`
|
|
316
189
|
*/
|
|
317
|
-
|
|
190
|
+
const VALUE_STRINGS = {
|
|
318
191
|
empty: '(nothing; empty string)',
|
|
319
192
|
null: '(no value; null)',
|
|
320
193
|
undefined: '(unknown value; undefined)',
|
|
@@ -328,7 +201,7 @@
|
|
|
328
201
|
*
|
|
329
202
|
* @public exported from `@promptbook/utils`
|
|
330
203
|
*/
|
|
331
|
-
|
|
204
|
+
const SMALL_NUMBER = 0.001;
|
|
332
205
|
// <- TODO: [🧜♂️]
|
|
333
206
|
/**
|
|
334
207
|
* @@@
|
|
@@ -353,8 +226,11 @@
|
|
|
353
226
|
* @public exported from `@promptbook/utils`
|
|
354
227
|
*/
|
|
355
228
|
function orderJson(options) {
|
|
356
|
-
|
|
357
|
-
|
|
229
|
+
const { value, order } = options;
|
|
230
|
+
const orderedValue = {
|
|
231
|
+
...(order === undefined ? {} : Object.fromEntries(order.map((key) => [key, undefined]))),
|
|
232
|
+
...value,
|
|
233
|
+
};
|
|
358
234
|
return orderedValue;
|
|
359
235
|
}
|
|
360
236
|
|
|
@@ -364,11 +240,37 @@
|
|
|
364
240
|
* @private private within the repository
|
|
365
241
|
*/
|
|
366
242
|
function getErrorReportUrl(error) {
|
|
367
|
-
|
|
368
|
-
title:
|
|
369
|
-
body: spaceTrim__default["default"](
|
|
243
|
+
const report = {
|
|
244
|
+
title: `🐜 Error report from ${NAME}`,
|
|
245
|
+
body: spaceTrim__default["default"]((block) => `
|
|
246
|
+
|
|
247
|
+
|
|
248
|
+
\`${error.name || 'Error'}\` has occurred in the [${NAME}], please look into it @${ADMIN_GITHUB_NAME}.
|
|
249
|
+
|
|
250
|
+
\`\`\`
|
|
251
|
+
${block(error.message || '(no error message)')}
|
|
252
|
+
\`\`\`
|
|
253
|
+
|
|
254
|
+
|
|
255
|
+
## More info:
|
|
256
|
+
|
|
257
|
+
- **Promptbook engine version:** ${PROMPTBOOK_ENGINE_VERSION}
|
|
258
|
+
- **Book language version:** ${BOOK_LANGUAGE_VERSION}
|
|
259
|
+
- **Time:** ${new Date().toISOString()}
|
|
260
|
+
|
|
261
|
+
<details>
|
|
262
|
+
<summary>Stack trace:</summary>
|
|
263
|
+
|
|
264
|
+
## Stack trace:
|
|
265
|
+
|
|
266
|
+
\`\`\`stacktrace
|
|
267
|
+
${block(error.stack || '(empty)')}
|
|
268
|
+
\`\`\`
|
|
269
|
+
</details>
|
|
270
|
+
|
|
271
|
+
`),
|
|
370
272
|
};
|
|
371
|
-
|
|
273
|
+
const reportUrl = new URL(`https://github.com/webgptorg/promptbook/issues/new`);
|
|
372
274
|
reportUrl.searchParams.set('labels', 'bug');
|
|
373
275
|
reportUrl.searchParams.set('assignees', ADMIN_GITHUB_NAME);
|
|
374
276
|
reportUrl.searchParams.set('title', report.title);
|
|
@@ -381,16 +283,24 @@
|
|
|
381
283
|
*
|
|
382
284
|
* @public exported from `@promptbook/core`
|
|
383
285
|
*/
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
286
|
+
class UnexpectedError extends Error {
|
|
287
|
+
constructor(message) {
|
|
288
|
+
super(spaceTrim.spaceTrim((block) => `
|
|
289
|
+
${block(message)}
|
|
290
|
+
|
|
291
|
+
Note: This error should not happen.
|
|
292
|
+
It's probbably a bug in the pipeline collection
|
|
293
|
+
|
|
294
|
+
Please report issue:
|
|
295
|
+
${block(getErrorReportUrl(new Error(message)).href)}
|
|
296
|
+
|
|
297
|
+
Or contact us on ${ADMIN_EMAIL}
|
|
298
|
+
|
|
299
|
+
`));
|
|
300
|
+
this.name = 'UnexpectedError';
|
|
301
|
+
Object.setPrototypeOf(this, UnexpectedError.prototype);
|
|
391
302
|
}
|
|
392
|
-
|
|
393
|
-
}(Error));
|
|
303
|
+
}
|
|
394
304
|
|
|
395
305
|
/**
|
|
396
306
|
* Checks if the value is [🚉] serializable as JSON
|
|
@@ -413,10 +323,9 @@
|
|
|
413
323
|
* @public exported from `@promptbook/utils`
|
|
414
324
|
*/
|
|
415
325
|
function checkSerializableAsJson(options) {
|
|
416
|
-
|
|
417
|
-
var value = options.value, name = options.name, message = options.message;
|
|
326
|
+
const { value, name, message } = options;
|
|
418
327
|
if (value === undefined) {
|
|
419
|
-
throw new UnexpectedError(
|
|
328
|
+
throw new UnexpectedError(`${name} is undefined`);
|
|
420
329
|
}
|
|
421
330
|
else if (value === null) {
|
|
422
331
|
return;
|
|
@@ -431,49 +340,54 @@
|
|
|
431
340
|
return;
|
|
432
341
|
}
|
|
433
342
|
else if (typeof value === 'symbol') {
|
|
434
|
-
throw new UnexpectedError(
|
|
343
|
+
throw new UnexpectedError(`${name} is symbol`);
|
|
435
344
|
}
|
|
436
345
|
else if (typeof value === 'function') {
|
|
437
|
-
throw new UnexpectedError(
|
|
346
|
+
throw new UnexpectedError(`${name} is function`);
|
|
438
347
|
}
|
|
439
348
|
else if (typeof value === 'object' && Array.isArray(value)) {
|
|
440
|
-
for (
|
|
441
|
-
checkSerializableAsJson({ name:
|
|
349
|
+
for (let i = 0; i < value.length; i++) {
|
|
350
|
+
checkSerializableAsJson({ name: `${name}[${i}]`, value: value[i], message });
|
|
442
351
|
}
|
|
443
352
|
}
|
|
444
353
|
else if (typeof value === 'object') {
|
|
445
354
|
if (value instanceof Date) {
|
|
446
|
-
throw new UnexpectedError(spaceTrim__default["default"](
|
|
355
|
+
throw new UnexpectedError(spaceTrim__default["default"]((block) => `
|
|
356
|
+
\`${name}\` is Date
|
|
357
|
+
|
|
358
|
+
Use \`string_date_iso8601\` instead
|
|
359
|
+
|
|
360
|
+
Additional message for \`${name}\`:
|
|
361
|
+
${block(message || '(nothing)')}
|
|
362
|
+
`));
|
|
447
363
|
}
|
|
448
364
|
else if (value instanceof Map) {
|
|
449
|
-
throw new UnexpectedError(
|
|
365
|
+
throw new UnexpectedError(`${name} is Map`);
|
|
450
366
|
}
|
|
451
367
|
else if (value instanceof Set) {
|
|
452
|
-
throw new UnexpectedError(
|
|
368
|
+
throw new UnexpectedError(`${name} is Set`);
|
|
453
369
|
}
|
|
454
370
|
else if (value instanceof RegExp) {
|
|
455
|
-
throw new UnexpectedError(
|
|
371
|
+
throw new UnexpectedError(`${name} is RegExp`);
|
|
456
372
|
}
|
|
457
373
|
else if (value instanceof Error) {
|
|
458
|
-
throw new UnexpectedError(spaceTrim__default["default"](
|
|
374
|
+
throw new UnexpectedError(spaceTrim__default["default"]((block) => `
|
|
375
|
+
\`${name}\` is unserialized Error
|
|
376
|
+
|
|
377
|
+
Use function \`serializeError\`
|
|
378
|
+
|
|
379
|
+
Additional message for \`${name}\`:
|
|
380
|
+
${block(message || '(nothing)')}
|
|
381
|
+
|
|
382
|
+
`));
|
|
459
383
|
}
|
|
460
384
|
else {
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
// Note: undefined in object is serializable - it is just omited
|
|
466
|
-
continue;
|
|
467
|
-
}
|
|
468
|
-
checkSerializableAsJson({ name: "".concat(name, ".").concat(subName), value: subValue, message: message });
|
|
385
|
+
for (const [subName, subValue] of Object.entries(value)) {
|
|
386
|
+
if (subValue === undefined) {
|
|
387
|
+
// Note: undefined in object is serializable - it is just omited
|
|
388
|
+
continue;
|
|
469
389
|
}
|
|
470
|
-
|
|
471
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
472
|
-
finally {
|
|
473
|
-
try {
|
|
474
|
-
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
475
|
-
}
|
|
476
|
-
finally { if (e_1) throw e_1.error; }
|
|
390
|
+
checkSerializableAsJson({ name: `${name}.${subName}`, value: subValue, message });
|
|
477
391
|
}
|
|
478
392
|
try {
|
|
479
393
|
JSON.stringify(value); // <- TODO: [0]
|
|
@@ -482,7 +396,14 @@
|
|
|
482
396
|
if (!(error instanceof Error)) {
|
|
483
397
|
throw error;
|
|
484
398
|
}
|
|
485
|
-
throw new UnexpectedError(spaceTrim__default["default"](
|
|
399
|
+
throw new UnexpectedError(spaceTrim__default["default"]((block) => `
|
|
400
|
+
\`${name}\` is not serializable
|
|
401
|
+
|
|
402
|
+
${block(error.stack || error.message)}
|
|
403
|
+
|
|
404
|
+
Additional message for \`${name}\`:
|
|
405
|
+
${block(message || '(nothing)')}
|
|
406
|
+
`));
|
|
486
407
|
}
|
|
487
408
|
/*
|
|
488
409
|
TODO: [0] Is there some more elegant way to check circular references?
|
|
@@ -507,7 +428,12 @@
|
|
|
507
428
|
}
|
|
508
429
|
}
|
|
509
430
|
else {
|
|
510
|
-
throw new UnexpectedError(spaceTrim__default["default"](
|
|
431
|
+
throw new UnexpectedError(spaceTrim__default["default"]((block) => `
|
|
432
|
+
\`${name}\` is unknown type
|
|
433
|
+
|
|
434
|
+
Additional message for \`${name}\`:
|
|
435
|
+
${block(message || '(nothing)')}
|
|
436
|
+
`));
|
|
511
437
|
}
|
|
512
438
|
}
|
|
513
439
|
/**
|
|
@@ -553,9 +479,9 @@
|
|
|
553
479
|
* @public exported from `@promptbook/utils`
|
|
554
480
|
*/
|
|
555
481
|
function exportJson(options) {
|
|
556
|
-
|
|
557
|
-
checkSerializableAsJson({ name
|
|
558
|
-
|
|
482
|
+
const { name, value, order, message } = options;
|
|
483
|
+
checkSerializableAsJson({ name, value, message });
|
|
484
|
+
const orderedValue =
|
|
559
485
|
// TODO: Fix error "Type instantiation is excessively deep and possibly infinite."
|
|
560
486
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
561
487
|
// @ts-ignore
|
|
@@ -578,19 +504,19 @@
|
|
|
578
504
|
*
|
|
579
505
|
* @private within the repository
|
|
580
506
|
*/
|
|
581
|
-
|
|
507
|
+
const REPLACING_NONCE = 'ptbkauk42kV2dzao34faw7FudQUHYPtW';
|
|
582
508
|
/**
|
|
583
509
|
* @@@
|
|
584
510
|
*
|
|
585
511
|
* @private within the repository
|
|
586
512
|
*/
|
|
587
|
-
|
|
513
|
+
const RESERVED_PARAMETER_MISSING_VALUE = 'MISSING-' + REPLACING_NONCE;
|
|
588
514
|
/**
|
|
589
515
|
* @@@
|
|
590
516
|
*
|
|
591
517
|
* @private within the repository
|
|
592
518
|
*/
|
|
593
|
-
|
|
519
|
+
const RESERVED_PARAMETER_RESTRICTED = 'RESTRICTED-' + REPLACING_NONCE;
|
|
594
520
|
/**
|
|
595
521
|
* The names of the parameters that are reserved for special purposes
|
|
596
522
|
*
|
|
@@ -598,7 +524,7 @@
|
|
|
598
524
|
*/
|
|
599
525
|
exportJson({
|
|
600
526
|
name: 'RESERVED_PARAMETER_NAMES',
|
|
601
|
-
message:
|
|
527
|
+
message: `The names of the parameters that are reserved for special purposes`,
|
|
602
528
|
value: [
|
|
603
529
|
'content',
|
|
604
530
|
'context',
|
|
@@ -620,16 +546,13 @@
|
|
|
620
546
|
*
|
|
621
547
|
* @public exported from `@promptbook/core`
|
|
622
548
|
*/
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
Object.setPrototypeOf(_this, LimitReachedError.prototype);
|
|
629
|
-
return _this;
|
|
549
|
+
class LimitReachedError extends Error {
|
|
550
|
+
constructor(message) {
|
|
551
|
+
super(message);
|
|
552
|
+
this.name = 'LimitReachedError';
|
|
553
|
+
Object.setPrototypeOf(this, LimitReachedError.prototype);
|
|
630
554
|
}
|
|
631
|
-
|
|
632
|
-
}(Error));
|
|
555
|
+
}
|
|
633
556
|
|
|
634
557
|
/**
|
|
635
558
|
* Format either small or big number
|
|
@@ -649,9 +572,9 @@
|
|
|
649
572
|
else if (value === -Infinity) {
|
|
650
573
|
return VALUE_STRINGS.negativeInfinity;
|
|
651
574
|
}
|
|
652
|
-
for (
|
|
653
|
-
|
|
654
|
-
|
|
575
|
+
for (let exponent = 0; exponent < 15; exponent++) {
|
|
576
|
+
const factor = 10 ** exponent;
|
|
577
|
+
const valueRounded = Math.round(value * factor) / factor;
|
|
655
578
|
if (Math.abs(value - valueRounded) / value < SMALL_NUMBER) {
|
|
656
579
|
return valueRounded.toFixed(exponent);
|
|
657
580
|
}
|
|
@@ -719,47 +642,38 @@
|
|
|
719
642
|
* @public exported from `@promptbook/utils`
|
|
720
643
|
*/
|
|
721
644
|
function templateParameters(template, parameters) {
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
var _d = __read(_c.value, 2), parameterName = _d[0], parameterValue = _d[1];
|
|
726
|
-
if (parameterValue === RESERVED_PARAMETER_MISSING_VALUE) {
|
|
727
|
-
throw new UnexpectedError("Parameter `{".concat(parameterName, "}` has missing value"));
|
|
728
|
-
}
|
|
729
|
-
else if (parameterValue === RESERVED_PARAMETER_RESTRICTED) {
|
|
730
|
-
// TODO: [🍵]
|
|
731
|
-
throw new UnexpectedError("Parameter `{".concat(parameterName, "}` is restricted to use"));
|
|
732
|
-
}
|
|
645
|
+
for (const [parameterName, parameterValue] of Object.entries(parameters)) {
|
|
646
|
+
if (parameterValue === RESERVED_PARAMETER_MISSING_VALUE) {
|
|
647
|
+
throw new UnexpectedError(`Parameter \`{${parameterName}}\` has missing value`);
|
|
733
648
|
}
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
try {
|
|
738
|
-
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
649
|
+
else if (parameterValue === RESERVED_PARAMETER_RESTRICTED) {
|
|
650
|
+
// TODO: [🍵]
|
|
651
|
+
throw new UnexpectedError(`Parameter \`{${parameterName}}\` is restricted to use`);
|
|
739
652
|
}
|
|
740
|
-
finally { if (e_1) throw e_1.error; }
|
|
741
653
|
}
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
654
|
+
let replacedTemplates = template;
|
|
655
|
+
let match;
|
|
656
|
+
let loopLimit = LOOP_LIMIT;
|
|
657
|
+
while ((match = /^(?<precol>.*){(?<parameterName>\w+)}(.*)/m /* <- Not global */
|
|
658
|
+
.exec(replacedTemplates))) {
|
|
746
659
|
if (loopLimit-- < 0) {
|
|
747
660
|
throw new LimitReachedError('Loop limit reached during parameters replacement in `templateParameters`');
|
|
748
661
|
}
|
|
749
|
-
|
|
750
|
-
|
|
662
|
+
const precol = match.groups.precol;
|
|
663
|
+
const parameterName = match.groups.parameterName;
|
|
751
664
|
if (parameterName === '') {
|
|
752
|
-
|
|
665
|
+
// Note: Skip empty placeholders. It's used to avoid confusion with JSON-like strings
|
|
666
|
+
continue;
|
|
753
667
|
}
|
|
754
668
|
if (parameterName.indexOf('{') !== -1 || parameterName.indexOf('}') !== -1) {
|
|
755
669
|
throw new PipelineExecutionError('Parameter is already opened or not closed');
|
|
756
670
|
}
|
|
757
671
|
if (parameters[parameterName] === undefined) {
|
|
758
|
-
throw new PipelineExecutionError(
|
|
672
|
+
throw new PipelineExecutionError(`Parameter \`{${parameterName}}\` is not defined`);
|
|
759
673
|
}
|
|
760
|
-
|
|
674
|
+
let parameterValue = parameters[parameterName];
|
|
761
675
|
if (parameterValue === undefined) {
|
|
762
|
-
throw new PipelineExecutionError(
|
|
676
|
+
throw new PipelineExecutionError(`Parameter \`{${parameterName}}\` is not defined`);
|
|
763
677
|
}
|
|
764
678
|
parameterValue = valueToString(parameterValue);
|
|
765
679
|
// Escape curly braces in parameter values to prevent prompt-injection
|
|
@@ -767,17 +681,13 @@
|
|
|
767
681
|
if (parameterValue.includes('\n') && /^\s*\W{0,3}\s*$/.test(precol)) {
|
|
768
682
|
parameterValue = parameterValue
|
|
769
683
|
.split('\n')
|
|
770
|
-
.map(
|
|
684
|
+
.map((line, index) => (index === 0 ? line : `${precol}${line}`))
|
|
771
685
|
.join('\n');
|
|
772
686
|
}
|
|
773
687
|
replacedTemplates =
|
|
774
688
|
replacedTemplates.substring(0, match.index + precol.length) +
|
|
775
689
|
parameterValue +
|
|
776
690
|
replacedTemplates.substring(match.index + precol.length + parameterName.length + 2);
|
|
777
|
-
};
|
|
778
|
-
while ((match = /^(?<precol>.*){(?<parameterName>\w+)}(.*)/m /* <- Not global */
|
|
779
|
-
.exec(replacedTemplates))) {
|
|
780
|
-
_loop_1();
|
|
781
691
|
}
|
|
782
692
|
// [💫] Check if there are parameters that are not closed properly
|
|
783
693
|
if (/{\w+$/.test(replacedTemplates)) {
|
|
@@ -811,8 +721,8 @@
|
|
|
811
721
|
return value.map(asSerializable);
|
|
812
722
|
}
|
|
813
723
|
else if (value !== null && typeof value === 'object') {
|
|
814
|
-
|
|
815
|
-
for (
|
|
724
|
+
const result = {};
|
|
725
|
+
for (const key in value) {
|
|
816
726
|
if (Object.prototype.hasOwnProperty.call(value, key)) {
|
|
817
727
|
result[key] = asSerializable(value[key]);
|
|
818
728
|
}
|
|
@@ -830,131 +740,119 @@
|
|
|
830
740
|
* @public exported from `@promptbook/vercel`
|
|
831
741
|
*/
|
|
832
742
|
function createExecutionToolsFromVercelProvider(options) {
|
|
833
|
-
|
|
834
|
-
|
|
743
|
+
let { title, description } = options;
|
|
744
|
+
const { vercelProvider, availableModels, userId, additionalChatSettings = {} } = options;
|
|
835
745
|
if (!/Vercel/i.test(title)) {
|
|
836
|
-
title =
|
|
746
|
+
title = `${title} (through Vercel)`;
|
|
837
747
|
} /* not else */
|
|
838
748
|
if (description === undefined) {
|
|
839
|
-
description =
|
|
749
|
+
description = `Implementation of ${title} through Vercel`;
|
|
840
750
|
} /* not else */
|
|
841
751
|
if (!/Vercel/i.test(description)) {
|
|
842
|
-
description =
|
|
752
|
+
description = `${description} (through Vercel)`;
|
|
843
753
|
} /* not else */
|
|
844
754
|
return {
|
|
845
|
-
title
|
|
846
|
-
description
|
|
847
|
-
checkConfiguration
|
|
755
|
+
title,
|
|
756
|
+
description,
|
|
757
|
+
checkConfiguration() {
|
|
848
758
|
// Note: There is no way how to check configuration of Vercel provider
|
|
849
759
|
return Promise.resolve();
|
|
850
760
|
},
|
|
851
|
-
listModels
|
|
852
|
-
return
|
|
853
|
-
return __generator(this, function (_a) {
|
|
854
|
-
return [2 /*return*/, availableModels];
|
|
855
|
-
});
|
|
856
|
-
});
|
|
761
|
+
async listModels() {
|
|
762
|
+
return availableModels;
|
|
857
763
|
},
|
|
858
|
-
callChatModel
|
|
764
|
+
async callChatModel(prompt) {
|
|
859
765
|
var _a;
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
rawPromptContent: rawPromptContent,
|
|
951
|
-
rawRequest: rawRequest,
|
|
952
|
-
rawResponse: asSerializable(rawResponse),
|
|
953
|
-
// <- [🗯]
|
|
954
|
-
},
|
|
955
|
-
})];
|
|
956
|
-
}
|
|
957
|
-
});
|
|
766
|
+
const { content, parameters, modelRequirements } = prompt;
|
|
767
|
+
if (modelRequirements.modelVariant !== 'CHAT') {
|
|
768
|
+
throw new PipelineExecutionError('Use callChatModel only for CHAT variant');
|
|
769
|
+
}
|
|
770
|
+
const modelName = modelRequirements.modelName ||
|
|
771
|
+
((_a = availableModels.find(({ modelVariant }) => modelVariant === 'CHAT')) === null || _a === void 0 ? void 0 : _a.modelName);
|
|
772
|
+
if (!modelName) {
|
|
773
|
+
throw new PipelineExecutionError(spaceTrim__default["default"](`
|
|
774
|
+
Can not determine which model to use.
|
|
775
|
+
|
|
776
|
+
You need to provide at least one of:
|
|
777
|
+
1) In \`createExecutionToolsFromVercelProvider\` options, provide \`availableModels\` with at least one model
|
|
778
|
+
2) In \`prompt.modelRequirements\`, provide \`modelName\` with the name of the model to use
|
|
779
|
+
|
|
780
|
+
`));
|
|
781
|
+
}
|
|
782
|
+
const model = await vercelProvider.chat(modelName, {
|
|
783
|
+
user: (userId === null || userId === void 0 ? void 0 : userId.toString()) || undefined,
|
|
784
|
+
...additionalChatSettings,
|
|
785
|
+
});
|
|
786
|
+
const rawPromptContent = templateParameters(content, { ...parameters, modelName });
|
|
787
|
+
const rawRequest = {
|
|
788
|
+
// <- TODO: [☂]
|
|
789
|
+
inputFormat: 'messages',
|
|
790
|
+
mode: {
|
|
791
|
+
type: 'regular',
|
|
792
|
+
tools: [
|
|
793
|
+
/* <- TODO: Pass the tools */
|
|
794
|
+
],
|
|
795
|
+
},
|
|
796
|
+
prompt: [
|
|
797
|
+
...(modelRequirements.systemMessage === undefined
|
|
798
|
+
? []
|
|
799
|
+
: [
|
|
800
|
+
{
|
|
801
|
+
role: 'system',
|
|
802
|
+
content: modelRequirements.systemMessage,
|
|
803
|
+
},
|
|
804
|
+
]),
|
|
805
|
+
{
|
|
806
|
+
role: 'user',
|
|
807
|
+
content: [
|
|
808
|
+
{
|
|
809
|
+
type: 'text',
|
|
810
|
+
text: rawPromptContent,
|
|
811
|
+
},
|
|
812
|
+
],
|
|
813
|
+
},
|
|
814
|
+
],
|
|
815
|
+
};
|
|
816
|
+
const start = $getCurrentDate();
|
|
817
|
+
if (options.isVerbose) {
|
|
818
|
+
console.info(colors__default["default"].bgWhite('rawRequest'), JSON.stringify(rawRequest, null, 4));
|
|
819
|
+
}
|
|
820
|
+
const rawResponse = await (async () => await model.doGenerate(rawRequest))().catch((error) => {
|
|
821
|
+
// <- Note: This weird structure is here to catch errors in both sync and async `doGenerate`
|
|
822
|
+
if (options.isVerbose) {
|
|
823
|
+
console.info(colors__default["default"].bgRed('error'), error);
|
|
824
|
+
}
|
|
825
|
+
throw error;
|
|
826
|
+
});
|
|
827
|
+
await model.doGenerate(rawRequest);
|
|
828
|
+
if (options.isVerbose) {
|
|
829
|
+
console.info(colors__default["default"].bgWhite('rawResponse'), JSON.stringify(rawResponse, null, 4));
|
|
830
|
+
}
|
|
831
|
+
if (rawResponse.text === undefined) {
|
|
832
|
+
throw new PipelineExecutionError('No response message');
|
|
833
|
+
}
|
|
834
|
+
const complete = $getCurrentDate();
|
|
835
|
+
/*
|
|
836
|
+
TODO: [🕘] Usage count
|
|
837
|
+
const usage = computeOpenAiUsage(content || '', resultContent || '', rawResponse);
|
|
838
|
+
*/
|
|
839
|
+
const usage = UNCERTAIN_USAGE;
|
|
840
|
+
return exportJson({
|
|
841
|
+
name: 'promptResult',
|
|
842
|
+
message: `Result of \`createExecutionToolsFromVercelProvider.callChatModel\``,
|
|
843
|
+
value: {
|
|
844
|
+
content: rawResponse.text,
|
|
845
|
+
modelName,
|
|
846
|
+
timing: {
|
|
847
|
+
start,
|
|
848
|
+
complete,
|
|
849
|
+
},
|
|
850
|
+
usage,
|
|
851
|
+
rawPromptContent,
|
|
852
|
+
rawRequest,
|
|
853
|
+
rawResponse: asSerializable(rawResponse),
|
|
854
|
+
// <- [🗯]
|
|
855
|
+
},
|
|
958
856
|
});
|
|
959
857
|
},
|
|
960
858
|
};
|
|
@@ -965,21 +863,30 @@
|
|
|
965
863
|
*
|
|
966
864
|
* @public exported from `@promptbook/deepseek`
|
|
967
865
|
*/
|
|
968
|
-
|
|
866
|
+
const createDeepseekExecutionTools = Object.assign((options) => {
|
|
969
867
|
if ($isRunningInJest()) {
|
|
970
868
|
// Note: [🔘]
|
|
971
869
|
throw new Error('DeepseekExecutionTools are not supported in Jest environment');
|
|
972
870
|
}
|
|
973
871
|
// Note: [🔘] Maybe there is same compatibility problem as in '@ai-sdk/deepseek'
|
|
974
872
|
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
873
|
+
const { createDeepSeek } = require('@ai-sdk/deepseek');
|
|
874
|
+
const deepseekVercelProvider = createDeepSeek({
|
|
875
|
+
...options,
|
|
876
|
+
// apiKey: process.env.DEEPSEEK_GENERATIVE_AI_API_KEY,
|
|
877
|
+
});
|
|
878
|
+
return createExecutionToolsFromVercelProvider({
|
|
879
|
+
title: 'Deepseek',
|
|
880
|
+
description: 'Implementation of Deepseek models',
|
|
881
|
+
vercelProvider: deepseekVercelProvider,
|
|
882
|
+
availableModels: [
|
|
978
883
|
// TODO: [🕘] Maybe list models in same way as in other providers - in separate file with metadata
|
|
979
884
|
'deepseek-chat',
|
|
980
885
|
'deepseek-reasoner',
|
|
981
886
|
// <- TODO: How picking of the default model looks like in `createExecutionToolsFromVercelProvider`
|
|
982
|
-
].map(
|
|
887
|
+
].map((modelName) => ({ modelName, modelVariant: 'CHAT' })),
|
|
888
|
+
...options,
|
|
889
|
+
});
|
|
983
890
|
}, {
|
|
984
891
|
packageName: '@promptbook/deepseek',
|
|
985
892
|
className: 'DeepseekExecutionTools',
|
|
@@ -993,16 +900,23 @@
|
|
|
993
900
|
*
|
|
994
901
|
* @public exported from `@promptbook/core`
|
|
995
902
|
*/
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
903
|
+
class NotYetImplementedError extends Error {
|
|
904
|
+
constructor(message) {
|
|
905
|
+
super(spaceTrim.spaceTrim((block) => `
|
|
906
|
+
${block(message)}
|
|
907
|
+
|
|
908
|
+
Note: This feature is not implemented yet but it will be soon.
|
|
909
|
+
|
|
910
|
+
If you want speed up the implementation or just read more, look here:
|
|
911
|
+
https://github.com/webgptorg/promptbook
|
|
912
|
+
|
|
913
|
+
Or contact us on pavol@ptbk.io
|
|
914
|
+
|
|
915
|
+
`));
|
|
916
|
+
this.name = 'NotYetImplementedError';
|
|
917
|
+
Object.setPrototypeOf(this, NotYetImplementedError.prototype);
|
|
1003
918
|
}
|
|
1004
|
-
|
|
1005
|
-
}(Error));
|
|
919
|
+
}
|
|
1006
920
|
|
|
1007
921
|
/**
|
|
1008
922
|
* @@@
|
|
@@ -1025,46 +939,35 @@
|
|
|
1025
939
|
* @public exported from `@promptbook/utils`
|
|
1026
940
|
*/
|
|
1027
941
|
function normalizeTo_SCREAMING_CASE(text) {
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
if (/^[a-z]$/.test(char)) {
|
|
1037
|
-
charType = 'LOWERCASE';
|
|
1038
|
-
normalizedChar = char.toUpperCase();
|
|
1039
|
-
}
|
|
1040
|
-
else if (/^[A-Z]$/.test(char)) {
|
|
1041
|
-
charType = 'UPPERCASE';
|
|
1042
|
-
normalizedChar = char;
|
|
1043
|
-
}
|
|
1044
|
-
else if (/^[0-9]$/.test(char)) {
|
|
1045
|
-
charType = 'NUMBER';
|
|
1046
|
-
normalizedChar = char;
|
|
1047
|
-
}
|
|
1048
|
-
else {
|
|
1049
|
-
charType = 'OTHER';
|
|
1050
|
-
normalizedChar = '_';
|
|
1051
|
-
}
|
|
1052
|
-
if (charType !== lastCharType &&
|
|
1053
|
-
!(lastCharType === 'UPPERCASE' && charType === 'LOWERCASE') &&
|
|
1054
|
-
!(lastCharType === 'NUMBER') &&
|
|
1055
|
-
!(charType === 'NUMBER')) {
|
|
1056
|
-
normalizedName += '_';
|
|
1057
|
-
}
|
|
1058
|
-
normalizedName += normalizedChar;
|
|
1059
|
-
lastCharType = charType;
|
|
942
|
+
let charType;
|
|
943
|
+
let lastCharType = 'OTHER';
|
|
944
|
+
let normalizedName = '';
|
|
945
|
+
for (const char of text) {
|
|
946
|
+
let normalizedChar;
|
|
947
|
+
if (/^[a-z]$/.test(char)) {
|
|
948
|
+
charType = 'LOWERCASE';
|
|
949
|
+
normalizedChar = char.toUpperCase();
|
|
1060
950
|
}
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
951
|
+
else if (/^[A-Z]$/.test(char)) {
|
|
952
|
+
charType = 'UPPERCASE';
|
|
953
|
+
normalizedChar = char;
|
|
954
|
+
}
|
|
955
|
+
else if (/^[0-9]$/.test(char)) {
|
|
956
|
+
charType = 'NUMBER';
|
|
957
|
+
normalizedChar = char;
|
|
958
|
+
}
|
|
959
|
+
else {
|
|
960
|
+
charType = 'OTHER';
|
|
961
|
+
normalizedChar = '_';
|
|
962
|
+
}
|
|
963
|
+
if (charType !== lastCharType &&
|
|
964
|
+
!(lastCharType === 'UPPERCASE' && charType === 'LOWERCASE') &&
|
|
965
|
+
!(lastCharType === 'NUMBER') &&
|
|
966
|
+
!(charType === 'NUMBER')) {
|
|
967
|
+
normalizedName += '_';
|
|
1066
968
|
}
|
|
1067
|
-
|
|
969
|
+
normalizedName += normalizedChar;
|
|
970
|
+
lastCharType = charType;
|
|
1068
971
|
}
|
|
1069
972
|
normalizedName = normalizedName.replace(/_+/g, '_');
|
|
1070
973
|
normalizedName = normalizedName.replace(/_?\/_?/g, '/');
|
|
@@ -1101,27 +1004,27 @@
|
|
|
1101
1004
|
*
|
|
1102
1005
|
* @private internal utility, exported are only signleton instances of this class
|
|
1103
1006
|
*/
|
|
1104
|
-
|
|
1105
|
-
|
|
1007
|
+
class $Register {
|
|
1008
|
+
constructor(registerName) {
|
|
1106
1009
|
this.registerName = registerName;
|
|
1107
|
-
|
|
1108
|
-
|
|
1010
|
+
const storageName = `_promptbook_${normalizeTo_snake_case(registerName)}`;
|
|
1011
|
+
const globalScope = $getGlobalScope();
|
|
1109
1012
|
if (globalScope[storageName] === undefined) {
|
|
1110
1013
|
globalScope[storageName] = [];
|
|
1111
1014
|
}
|
|
1112
1015
|
else if (!Array.isArray(globalScope[storageName])) {
|
|
1113
|
-
throw new UnexpectedError(
|
|
1016
|
+
throw new UnexpectedError(`Expected (global) ${storageName} to be an array, but got ${typeof globalScope[storageName]}`);
|
|
1114
1017
|
}
|
|
1115
1018
|
this.storage = globalScope[storageName];
|
|
1116
1019
|
}
|
|
1117
|
-
|
|
1020
|
+
list() {
|
|
1118
1021
|
// <- TODO: ReadonlyDeep<ReadonlyArray<TRegistered>>
|
|
1119
1022
|
return this.storage;
|
|
1120
|
-
}
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1023
|
+
}
|
|
1024
|
+
register(registered) {
|
|
1025
|
+
const { packageName, className } = registered;
|
|
1026
|
+
const existingRegistrationIndex = this.storage.findIndex((item) => item.packageName === packageName && item.className === className);
|
|
1027
|
+
const existingRegistration = this.storage[existingRegistrationIndex];
|
|
1125
1028
|
if (!existingRegistration) {
|
|
1126
1029
|
this.storage.push(registered);
|
|
1127
1030
|
}
|
|
@@ -1130,18 +1033,17 @@
|
|
|
1130
1033
|
}
|
|
1131
1034
|
return {
|
|
1132
1035
|
registerName: this.registerName,
|
|
1133
|
-
packageName
|
|
1134
|
-
className
|
|
1036
|
+
packageName,
|
|
1037
|
+
className,
|
|
1135
1038
|
get isDestroyed() {
|
|
1136
1039
|
return false;
|
|
1137
1040
|
},
|
|
1138
|
-
destroy
|
|
1139
|
-
throw new NotYetImplementedError(
|
|
1041
|
+
destroy() {
|
|
1042
|
+
throw new NotYetImplementedError(`Registration to ${this.registerName} is permanent in this version of Promptbook`);
|
|
1140
1043
|
},
|
|
1141
1044
|
};
|
|
1142
|
-
}
|
|
1143
|
-
|
|
1144
|
-
}());
|
|
1045
|
+
}
|
|
1046
|
+
}
|
|
1145
1047
|
|
|
1146
1048
|
/**
|
|
1147
1049
|
* @@@
|
|
@@ -1150,7 +1052,7 @@
|
|
|
1150
1052
|
* @singleton Only one instance of each register is created per build, but thare can be more @@@
|
|
1151
1053
|
* @public exported from `@promptbook/core`
|
|
1152
1054
|
*/
|
|
1153
|
-
|
|
1055
|
+
const $llmToolsRegister = new $Register('llm_execution_tools_constructors');
|
|
1154
1056
|
/**
|
|
1155
1057
|
* TODO: [®] DRY Register logic
|
|
1156
1058
|
*/
|
|
@@ -1164,7 +1066,7 @@
|
|
|
1164
1066
|
* @public exported from `@promptbook/wizzard`
|
|
1165
1067
|
* @public exported from `@promptbook/cli`
|
|
1166
1068
|
*/
|
|
1167
|
-
|
|
1069
|
+
const _DeepseekRegistration = $llmToolsRegister.register(createDeepseekExecutionTools);
|
|
1168
1070
|
/**
|
|
1169
1071
|
* TODO: [🎶] Naming "constructor" vs "creator" vs "factory"
|
|
1170
1072
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|