@promptbook/editable 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 +975 -1063
- 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 +978 -1066
- package/umd/index.umd.js.map +1 -1
package/esm/index.es.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import spaceTrim, { spaceTrim as spaceTrim$1 } from 'spacetrim';
|
|
2
|
-
import {
|
|
2
|
+
import { parse, unparse } from 'papaparse';
|
|
3
3
|
import { SHA256 } from 'crypto-js';
|
|
4
4
|
import hexEncoder from 'crypto-js/enc-hex';
|
|
5
5
|
|
|
@@ -10,138 +10,19 @@ import hexEncoder from 'crypto-js/enc-hex';
|
|
|
10
10
|
* @generated
|
|
11
11
|
* @see https://github.com/webgptorg/book
|
|
12
12
|
*/
|
|
13
|
-
|
|
13
|
+
const BOOK_LANGUAGE_VERSION = '1.0.0';
|
|
14
14
|
/**
|
|
15
15
|
* The version of the Promptbook engine
|
|
16
16
|
*
|
|
17
17
|
* @generated
|
|
18
18
|
* @see https://github.com/webgptorg/promptbook
|
|
19
19
|
*/
|
|
20
|
-
|
|
20
|
+
const PROMPTBOOK_ENGINE_VERSION = '0.86.22';
|
|
21
21
|
/**
|
|
22
22
|
* TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
|
|
23
23
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
24
24
|
*/
|
|
25
25
|
|
|
26
|
-
/*! *****************************************************************************
|
|
27
|
-
Copyright (c) Microsoft Corporation.
|
|
28
|
-
|
|
29
|
-
Permission to use, copy, modify, and/or distribute this software for any
|
|
30
|
-
purpose with or without fee is hereby granted.
|
|
31
|
-
|
|
32
|
-
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
33
|
-
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
34
|
-
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
35
|
-
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
36
|
-
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
37
|
-
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
38
|
-
PERFORMANCE OF THIS SOFTWARE.
|
|
39
|
-
***************************************************************************** */
|
|
40
|
-
/* global Reflect, Promise */
|
|
41
|
-
|
|
42
|
-
var extendStatics = function(d, b) {
|
|
43
|
-
extendStatics = Object.setPrototypeOf ||
|
|
44
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
45
|
-
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
46
|
-
return extendStatics(d, b);
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
function __extends(d, b) {
|
|
50
|
-
if (typeof b !== "function" && b !== null)
|
|
51
|
-
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
52
|
-
extendStatics(d, b);
|
|
53
|
-
function __() { this.constructor = d; }
|
|
54
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
var __assign = function() {
|
|
58
|
-
__assign = Object.assign || function __assign(t) {
|
|
59
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
60
|
-
s = arguments[i];
|
|
61
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
|
|
62
|
-
}
|
|
63
|
-
return t;
|
|
64
|
-
};
|
|
65
|
-
return __assign.apply(this, arguments);
|
|
66
|
-
};
|
|
67
|
-
|
|
68
|
-
function __awaiter(thisArg, _arguments, P, generator) {
|
|
69
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
70
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
71
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
72
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
73
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
74
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
75
|
-
});
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
function __generator(thisArg, body) {
|
|
79
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
80
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
81
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
82
|
-
function step(op) {
|
|
83
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
84
|
-
while (_) try {
|
|
85
|
-
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;
|
|
86
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
87
|
-
switch (op[0]) {
|
|
88
|
-
case 0: case 1: t = op; break;
|
|
89
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
90
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
91
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
92
|
-
default:
|
|
93
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
94
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
95
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
96
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
97
|
-
if (t[2]) _.ops.pop();
|
|
98
|
-
_.trys.pop(); continue;
|
|
99
|
-
}
|
|
100
|
-
op = body.call(thisArg, _);
|
|
101
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
102
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
function __values(o) {
|
|
107
|
-
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
108
|
-
if (m) return m.call(o);
|
|
109
|
-
if (o && typeof o.length === "number") return {
|
|
110
|
-
next: function () {
|
|
111
|
-
if (o && i >= o.length) o = void 0;
|
|
112
|
-
return { value: o && o[i++], done: !o };
|
|
113
|
-
}
|
|
114
|
-
};
|
|
115
|
-
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
function __read(o, n) {
|
|
119
|
-
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
120
|
-
if (!m) return o;
|
|
121
|
-
var i = m.call(o), r, ar = [], e;
|
|
122
|
-
try {
|
|
123
|
-
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
124
|
-
}
|
|
125
|
-
catch (error) { e = { error: error }; }
|
|
126
|
-
finally {
|
|
127
|
-
try {
|
|
128
|
-
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
129
|
-
}
|
|
130
|
-
finally { if (e) throw e.error; }
|
|
131
|
-
}
|
|
132
|
-
return ar;
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
function __spreadArray(to, from, pack) {
|
|
136
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
137
|
-
if (ar || !(i in from)) {
|
|
138
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
139
|
-
ar[i] = from[i];
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
143
|
-
}
|
|
144
|
-
|
|
145
26
|
/**
|
|
146
27
|
* Returns the same value that is passed as argument.
|
|
147
28
|
* No side effects.
|
|
@@ -169,38 +50,38 @@ function just(value) {
|
|
|
169
50
|
*
|
|
170
51
|
* @public exported from `@promptbook/core`
|
|
171
52
|
*/
|
|
172
|
-
|
|
53
|
+
const NAME = `Promptbook`;
|
|
173
54
|
/**
|
|
174
55
|
* Email of the responsible person
|
|
175
56
|
*
|
|
176
57
|
* @public exported from `@promptbook/core`
|
|
177
58
|
*/
|
|
178
|
-
|
|
59
|
+
const ADMIN_EMAIL = 'pavol@ptbk.io';
|
|
179
60
|
/**
|
|
180
61
|
* Name of the responsible person for the Promptbook on GitHub
|
|
181
62
|
*
|
|
182
63
|
* @public exported from `@promptbook/core`
|
|
183
64
|
*/
|
|
184
|
-
|
|
65
|
+
const ADMIN_GITHUB_NAME = 'hejny';
|
|
185
66
|
/**
|
|
186
67
|
* When the title is not provided, the default title is used
|
|
187
68
|
*
|
|
188
69
|
* @public exported from `@promptbook/core`
|
|
189
70
|
*/
|
|
190
|
-
|
|
71
|
+
const DEFAULT_BOOK_TITLE = `✨ Untitled Book`;
|
|
191
72
|
/**
|
|
192
73
|
* When the pipeline is flat and no name of return parameter is provided, this name is used
|
|
193
74
|
*
|
|
194
75
|
* @public exported from `@promptbook/core`
|
|
195
76
|
*/
|
|
196
|
-
|
|
77
|
+
const DEFAULT_BOOK_OUTPUT_PARAMETER_NAME = 'result';
|
|
197
78
|
// <- TODO: [🧠] Better system for generator warnings - not always "code" and "by `@promptbook/cli`"
|
|
198
79
|
/**
|
|
199
80
|
* The maximum number of iterations for a loops
|
|
200
81
|
*
|
|
201
82
|
* @private within the repository - too low-level in comparison with other `MAX_...`
|
|
202
83
|
*/
|
|
203
|
-
|
|
84
|
+
const LOOP_LIMIT = 1000;
|
|
204
85
|
// <- TODO: [🧜♂️]
|
|
205
86
|
/**
|
|
206
87
|
* @@@
|
|
@@ -224,11 +105,37 @@ Object.freeze({
|
|
|
224
105
|
* @private private within the repository
|
|
225
106
|
*/
|
|
226
107
|
function getErrorReportUrl(error) {
|
|
227
|
-
|
|
228
|
-
title:
|
|
229
|
-
body: spaceTrim(
|
|
108
|
+
const report = {
|
|
109
|
+
title: `🐜 Error report from ${NAME}`,
|
|
110
|
+
body: spaceTrim((block) => `
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
\`${error.name || 'Error'}\` has occurred in the [${NAME}], please look into it @${ADMIN_GITHUB_NAME}.
|
|
114
|
+
|
|
115
|
+
\`\`\`
|
|
116
|
+
${block(error.message || '(no error message)')}
|
|
117
|
+
\`\`\`
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
## More info:
|
|
121
|
+
|
|
122
|
+
- **Promptbook engine version:** ${PROMPTBOOK_ENGINE_VERSION}
|
|
123
|
+
- **Book language version:** ${BOOK_LANGUAGE_VERSION}
|
|
124
|
+
- **Time:** ${new Date().toISOString()}
|
|
125
|
+
|
|
126
|
+
<details>
|
|
127
|
+
<summary>Stack trace:</summary>
|
|
128
|
+
|
|
129
|
+
## Stack trace:
|
|
130
|
+
|
|
131
|
+
\`\`\`stacktrace
|
|
132
|
+
${block(error.stack || '(empty)')}
|
|
133
|
+
\`\`\`
|
|
134
|
+
</details>
|
|
135
|
+
|
|
136
|
+
`),
|
|
230
137
|
};
|
|
231
|
-
|
|
138
|
+
const reportUrl = new URL(`https://github.com/webgptorg/promptbook/issues/new`);
|
|
232
139
|
reportUrl.searchParams.set('labels', 'bug');
|
|
233
140
|
reportUrl.searchParams.set('assignees', ADMIN_GITHUB_NAME);
|
|
234
141
|
reportUrl.searchParams.set('title', report.title);
|
|
@@ -241,32 +148,37 @@ function getErrorReportUrl(error) {
|
|
|
241
148
|
*
|
|
242
149
|
* @public exported from `@promptbook/core`
|
|
243
150
|
*/
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
151
|
+
class UnexpectedError extends Error {
|
|
152
|
+
constructor(message) {
|
|
153
|
+
super(spaceTrim$1((block) => `
|
|
154
|
+
${block(message)}
|
|
155
|
+
|
|
156
|
+
Note: This error should not happen.
|
|
157
|
+
It's probbably a bug in the pipeline collection
|
|
158
|
+
|
|
159
|
+
Please report issue:
|
|
160
|
+
${block(getErrorReportUrl(new Error(message)).href)}
|
|
161
|
+
|
|
162
|
+
Or contact us on ${ADMIN_EMAIL}
|
|
163
|
+
|
|
164
|
+
`));
|
|
165
|
+
this.name = 'UnexpectedError';
|
|
166
|
+
Object.setPrototypeOf(this, UnexpectedError.prototype);
|
|
251
167
|
}
|
|
252
|
-
|
|
253
|
-
}(Error));
|
|
168
|
+
}
|
|
254
169
|
|
|
255
170
|
/**
|
|
256
171
|
* This error indicates that the promptbook in a markdown format cannot be parsed into a valid promptbook object
|
|
257
172
|
*
|
|
258
173
|
* @public exported from `@promptbook/core`
|
|
259
174
|
*/
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
Object.setPrototypeOf(_this, ParseError.prototype);
|
|
266
|
-
return _this;
|
|
175
|
+
class ParseError extends Error {
|
|
176
|
+
constructor(message) {
|
|
177
|
+
super(message);
|
|
178
|
+
this.name = 'ParseError';
|
|
179
|
+
Object.setPrototypeOf(this, ParseError.prototype);
|
|
267
180
|
}
|
|
268
|
-
|
|
269
|
-
}(Error));
|
|
181
|
+
}
|
|
270
182
|
/**
|
|
271
183
|
* TODO: Maybe split `ParseError` and `ApplyError`
|
|
272
184
|
*/
|
|
@@ -279,7 +191,7 @@ var ParseError = /** @class */ (function (_super) {
|
|
|
279
191
|
* @see `documentationUrl` for more details
|
|
280
192
|
* @private within the commands folder
|
|
281
193
|
*/
|
|
282
|
-
|
|
194
|
+
const boilerplateCommandParser = {
|
|
283
195
|
/**
|
|
284
196
|
* Name of the command
|
|
285
197
|
*/
|
|
@@ -296,7 +208,7 @@ var boilerplateCommandParser = {
|
|
|
296
208
|
/**
|
|
297
209
|
* Description of the BOILERPLATE command
|
|
298
210
|
*/
|
|
299
|
-
description:
|
|
211
|
+
description: `@@`,
|
|
300
212
|
/**
|
|
301
213
|
* Link to documentation
|
|
302
214
|
*/
|
|
@@ -308,18 +220,18 @@ var boilerplateCommandParser = {
|
|
|
308
220
|
/**
|
|
309
221
|
* Parses the BOILERPLATE command
|
|
310
222
|
*/
|
|
311
|
-
parse
|
|
312
|
-
|
|
223
|
+
parse(input) {
|
|
224
|
+
const { args } = input;
|
|
313
225
|
if (args.length !== 1) {
|
|
314
|
-
throw new ParseError(
|
|
226
|
+
throw new ParseError(`BOILERPLATE command requires exactly one argument`);
|
|
315
227
|
}
|
|
316
|
-
|
|
228
|
+
const value = args[0].toLowerCase();
|
|
317
229
|
if (value.includes('brr')) {
|
|
318
|
-
throw new ParseError(
|
|
230
|
+
throw new ParseError(`BOILERPLATE value can not contain brr`);
|
|
319
231
|
}
|
|
320
232
|
return {
|
|
321
233
|
type: 'BOILERPLATE',
|
|
322
|
-
value
|
|
234
|
+
value,
|
|
323
235
|
};
|
|
324
236
|
},
|
|
325
237
|
/**
|
|
@@ -327,40 +239,40 @@ var boilerplateCommandParser = {
|
|
|
327
239
|
*
|
|
328
240
|
* Note: `$` is used to indicate that this function mutates given `pipelineJson`
|
|
329
241
|
*/
|
|
330
|
-
$applyToPipelineJson
|
|
331
|
-
throw new ParseError(
|
|
242
|
+
$applyToPipelineJson(command, $pipelineJson) {
|
|
243
|
+
throw new ParseError(`BOILERPLATE command is only for testing purposes and should not be used in the .book.md file`);
|
|
332
244
|
},
|
|
333
245
|
/**
|
|
334
246
|
* Apply the BOILERPLATE command to the `pipelineJson`
|
|
335
247
|
*
|
|
336
248
|
* Note: `$` is used to indicate that this function mutates given `taskJson`
|
|
337
249
|
*/
|
|
338
|
-
$applyToTaskJson
|
|
339
|
-
throw new ParseError(
|
|
250
|
+
$applyToTaskJson(command, $taskJson, $pipelineJson) {
|
|
251
|
+
throw new ParseError(`BOILERPLATE command is only for testing purposes and should not be used in the .book.md file`);
|
|
340
252
|
},
|
|
341
253
|
/**
|
|
342
254
|
* Converts the BOILERPLATE command back to string
|
|
343
255
|
*
|
|
344
256
|
* Note: This is used in `pipelineJsonToString` utility
|
|
345
257
|
*/
|
|
346
|
-
stringify
|
|
347
|
-
return
|
|
258
|
+
stringify(command) {
|
|
259
|
+
return `---`; // <- TODO: [🛋] Implement
|
|
348
260
|
},
|
|
349
261
|
/**
|
|
350
262
|
* Reads the BOILERPLATE command from the `PipelineJson`
|
|
351
263
|
*
|
|
352
264
|
* Note: This is used in `pipelineJsonToString` utility
|
|
353
265
|
*/
|
|
354
|
-
takeFromPipelineJson
|
|
355
|
-
throw new ParseError(
|
|
266
|
+
takeFromPipelineJson(pipelineJson) {
|
|
267
|
+
throw new ParseError(`BOILERPLATE command is only for testing purposes and should not be used in the .book.md file`);
|
|
356
268
|
},
|
|
357
269
|
/**
|
|
358
270
|
* Reads the BOILERPLATE command from the `TaskJson`
|
|
359
271
|
*
|
|
360
272
|
* Note: This is used in `pipelineJsonToString` utility
|
|
361
273
|
*/
|
|
362
|
-
takeFromTaskJson
|
|
363
|
-
throw new ParseError(
|
|
274
|
+
takeFromTaskJson($taskJson) {
|
|
275
|
+
throw new ParseError(`BOILERPLATE command is only for testing purposes and should not be used in the .book.md file`);
|
|
364
276
|
},
|
|
365
277
|
};
|
|
366
278
|
|
|
@@ -369,16 +281,23 @@ var boilerplateCommandParser = {
|
|
|
369
281
|
*
|
|
370
282
|
* @public exported from `@promptbook/core`
|
|
371
283
|
*/
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
284
|
+
class NotYetImplementedError extends Error {
|
|
285
|
+
constructor(message) {
|
|
286
|
+
super(spaceTrim$1((block) => `
|
|
287
|
+
${block(message)}
|
|
288
|
+
|
|
289
|
+
Note: This feature is not implemented yet but it will be soon.
|
|
290
|
+
|
|
291
|
+
If you want speed up the implementation or just read more, look here:
|
|
292
|
+
https://github.com/webgptorg/promptbook
|
|
293
|
+
|
|
294
|
+
Or contact us on pavol@ptbk.io
|
|
295
|
+
|
|
296
|
+
`));
|
|
297
|
+
this.name = 'NotYetImplementedError';
|
|
298
|
+
Object.setPrototypeOf(this, NotYetImplementedError.prototype);
|
|
379
299
|
}
|
|
380
|
-
|
|
381
|
-
}(Error));
|
|
300
|
+
}
|
|
382
301
|
|
|
383
302
|
/**
|
|
384
303
|
* Tests if given string is valid semantic version
|
|
@@ -428,7 +347,7 @@ function isValidPromptbookVersion(version) {
|
|
|
428
347
|
* @see `documentationUrl` for more details
|
|
429
348
|
* @public exported from `@promptbook/editable`
|
|
430
349
|
*/
|
|
431
|
-
|
|
350
|
+
const bookVersionCommandParser = {
|
|
432
351
|
/**
|
|
433
352
|
* Name of the command
|
|
434
353
|
*/
|
|
@@ -442,7 +361,7 @@ var bookVersionCommandParser = {
|
|
|
442
361
|
/**
|
|
443
362
|
* Description of the BOOK_VERSION command
|
|
444
363
|
*/
|
|
445
|
-
description:
|
|
364
|
+
description: `Which version of the Book language is the .book.md using`,
|
|
446
365
|
/**
|
|
447
366
|
* Link to documentation
|
|
448
367
|
*/
|
|
@@ -450,21 +369,21 @@ var bookVersionCommandParser = {
|
|
|
450
369
|
/**
|
|
451
370
|
* Example usages of the BOOK_VERSION command
|
|
452
371
|
*/
|
|
453
|
-
examples: [
|
|
372
|
+
examples: [`BOOK VERSION ${BOOK_LANGUAGE_VERSION}`, `BOOK ${BOOK_LANGUAGE_VERSION}`],
|
|
454
373
|
/**
|
|
455
374
|
* Parses the BOOK_VERSION command
|
|
456
375
|
*/
|
|
457
|
-
parse
|
|
458
|
-
|
|
459
|
-
|
|
376
|
+
parse(input) {
|
|
377
|
+
const { args } = input;
|
|
378
|
+
const bookVersion = args.pop();
|
|
460
379
|
if (bookVersion === undefined) {
|
|
461
|
-
throw new ParseError(
|
|
380
|
+
throw new ParseError(`Version is required`);
|
|
462
381
|
}
|
|
463
382
|
if (!isValidPromptbookVersion(bookVersion)) {
|
|
464
|
-
throw new ParseError(
|
|
383
|
+
throw new ParseError(`Invalid Promptbook version "${bookVersion}"`);
|
|
465
384
|
}
|
|
466
385
|
if (args.length > 0 && !(((args.length === 1 && args[0]) || '').toUpperCase() === 'VERSION')) {
|
|
467
|
-
throw new ParseError(
|
|
386
|
+
throw new ParseError(`Can not have more than one Promptbook version`);
|
|
468
387
|
}
|
|
469
388
|
return {
|
|
470
389
|
type: 'BOOK_VERSION',
|
|
@@ -476,7 +395,7 @@ var bookVersionCommandParser = {
|
|
|
476
395
|
*
|
|
477
396
|
* Note: `$` is used to indicate that this function mutates given `pipelineJson`
|
|
478
397
|
*/
|
|
479
|
-
$applyToPipelineJson
|
|
398
|
+
$applyToPipelineJson(command, $pipelineJson) {
|
|
480
399
|
// TODO: Warn if the version is overridden
|
|
481
400
|
$pipelineJson.bookVersion = command.bookVersion;
|
|
482
401
|
},
|
|
@@ -485,16 +404,16 @@ var bookVersionCommandParser = {
|
|
|
485
404
|
*
|
|
486
405
|
* Note: This is used in `pipelineJsonToString` utility
|
|
487
406
|
*/
|
|
488
|
-
stringify
|
|
489
|
-
return
|
|
407
|
+
stringify(command) {
|
|
408
|
+
return `---`; // <- TODO: [🛋] Implement
|
|
490
409
|
},
|
|
491
410
|
/**
|
|
492
411
|
* Reads the BOOK_VERSION command from the `PipelineJson`
|
|
493
412
|
*
|
|
494
413
|
* Note: This is used in `pipelineJsonToString` utility
|
|
495
414
|
*/
|
|
496
|
-
takeFromPipelineJson
|
|
497
|
-
throw new NotYetImplementedError(
|
|
415
|
+
takeFromPipelineJson(pipelineJson) {
|
|
416
|
+
throw new NotYetImplementedError(`[🛋] Not implemented yet`); // <- TODO: [🛋] Implement
|
|
498
417
|
},
|
|
499
418
|
};
|
|
500
419
|
|
|
@@ -504,7 +423,7 @@ var bookVersionCommandParser = {
|
|
|
504
423
|
* @see https://github.com/webgptorg/promptbook/discussions/30
|
|
505
424
|
* @public exported from `@promptbook/core`
|
|
506
425
|
*/
|
|
507
|
-
|
|
426
|
+
const EXPECTATION_UNITS = ['CHARACTERS', 'WORDS', 'SENTENCES', 'LINES', 'PARAGRAPHS', 'PAGES'];
|
|
508
427
|
/**
|
|
509
428
|
* TODO: [💝] Unite object for expecting amount and format - remove format
|
|
510
429
|
*/
|
|
@@ -521,7 +440,7 @@ var EXPECTATION_UNITS = ['CHARACTERS', 'WORDS', 'SENTENCES', 'LINES', 'PARAGRAPH
|
|
|
521
440
|
* @public exported from `@promptbook/utils`
|
|
522
441
|
*/
|
|
523
442
|
function parseNumber(value) {
|
|
524
|
-
|
|
443
|
+
const originalValue = value;
|
|
525
444
|
if (typeof value === 'number') {
|
|
526
445
|
value = value.toString(); // <- TODO: Maybe more efficient way to do this
|
|
527
446
|
}
|
|
@@ -533,7 +452,7 @@ function parseNumber(value) {
|
|
|
533
452
|
return parseNumber(value.substring(1));
|
|
534
453
|
}
|
|
535
454
|
if (value.startsWith('-')) {
|
|
536
|
-
|
|
455
|
+
const number = parseNumber(value.substring(1));
|
|
537
456
|
if (number === 0) {
|
|
538
457
|
return 0; // <- Note: To prevent -0
|
|
539
458
|
}
|
|
@@ -548,11 +467,11 @@ function parseNumber(value) {
|
|
|
548
467
|
return Infinity;
|
|
549
468
|
}
|
|
550
469
|
if (value.includes('/')) {
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
470
|
+
const [numerator_, denominator_] = value.split('/');
|
|
471
|
+
const numerator = parseNumber(numerator_);
|
|
472
|
+
const denominator = parseNumber(denominator_);
|
|
554
473
|
if (denominator === 0) {
|
|
555
|
-
throw new ParseError(
|
|
474
|
+
throw new ParseError(`Unable to parse number from "${originalValue}" because denominator is zero`);
|
|
556
475
|
}
|
|
557
476
|
return numerator / denominator;
|
|
558
477
|
}
|
|
@@ -560,15 +479,15 @@ function parseNumber(value) {
|
|
|
560
479
|
return 0;
|
|
561
480
|
}
|
|
562
481
|
if (value.includes('E')) {
|
|
563
|
-
|
|
564
|
-
return parseNumber(significand) *
|
|
482
|
+
const [significand, exponent] = value.split('E');
|
|
483
|
+
return parseNumber(significand) * 10 ** parseNumber(exponent);
|
|
565
484
|
}
|
|
566
485
|
if (!/^[0-9.]+$/.test(value) || value.split('.').length > 2) {
|
|
567
|
-
throw new ParseError(
|
|
486
|
+
throw new ParseError(`Unable to parse number from "${originalValue}"`);
|
|
568
487
|
}
|
|
569
|
-
|
|
488
|
+
const num = parseFloat(value);
|
|
570
489
|
if (isNaN(num)) {
|
|
571
|
-
throw new ParseError(
|
|
490
|
+
throw new ParseError(`Unexpected NaN when parsing number from "${originalValue}"`);
|
|
572
491
|
}
|
|
573
492
|
return num;
|
|
574
493
|
}
|
|
@@ -583,7 +502,7 @@ function parseNumber(value) {
|
|
|
583
502
|
* @see `documentationUrl` for more details
|
|
584
503
|
* @public exported from `@promptbook/editable`
|
|
585
504
|
*/
|
|
586
|
-
|
|
505
|
+
const expectCommandParser = {
|
|
587
506
|
/**
|
|
588
507
|
* Name of the command
|
|
589
508
|
*/
|
|
@@ -596,7 +515,10 @@ var expectCommandParser = {
|
|
|
596
515
|
/**
|
|
597
516
|
* Description of the FORMAT command
|
|
598
517
|
*/
|
|
599
|
-
description: spaceTrim(
|
|
518
|
+
description: spaceTrim(`
|
|
519
|
+
Expect command describes the desired output of the task *(after post-processing)*
|
|
520
|
+
It can set limits for the maximum/minimum length of the output, measured in characters, words, sentences, paragraphs or some other shape of the output.
|
|
521
|
+
`),
|
|
600
522
|
/**
|
|
601
523
|
* Link to documentation
|
|
602
524
|
*/
|
|
@@ -614,12 +536,11 @@ var expectCommandParser = {
|
|
|
614
536
|
/**
|
|
615
537
|
* Parses the FORMAT command
|
|
616
538
|
*/
|
|
617
|
-
parse
|
|
618
|
-
|
|
619
|
-
var args = input.args;
|
|
539
|
+
parse(input) {
|
|
540
|
+
const { args } = input;
|
|
620
541
|
try {
|
|
621
|
-
|
|
622
|
-
|
|
542
|
+
let sign;
|
|
543
|
+
const signRaw = args.shift();
|
|
623
544
|
if (/^exact/i.test(signRaw)) {
|
|
624
545
|
sign = 'EXACTLY';
|
|
625
546
|
}
|
|
@@ -630,59 +551,50 @@ var expectCommandParser = {
|
|
|
630
551
|
sign = 'MAXIMUM';
|
|
631
552
|
}
|
|
632
553
|
else {
|
|
633
|
-
throw new ParseError(
|
|
554
|
+
throw new ParseError(`Invalid sign "${signRaw}", expected EXACTLY, MIN or MAX`);
|
|
634
555
|
}
|
|
635
|
-
|
|
636
|
-
|
|
556
|
+
const amountRaw = args.shift();
|
|
557
|
+
const amount = parseNumber(amountRaw);
|
|
637
558
|
if (amount < 0) {
|
|
638
559
|
throw new ParseError('Amount must be positive number or zero');
|
|
639
560
|
}
|
|
640
561
|
if (amount !== Math.floor(amount)) {
|
|
641
562
|
throw new ParseError('Amount must be whole number');
|
|
642
563
|
}
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
existingUnitText =
|
|
650
|
-
if (existingUnitText === 'CHARACTER') {
|
|
651
|
-
existingUnitText = 'CHAR';
|
|
652
|
-
}
|
|
653
|
-
if (new RegExp("^".concat(existingUnitText.toLowerCase())).test(unitRaw.toLowerCase()) ||
|
|
654
|
-
new RegExp("^".concat(unitRaw.toLowerCase())).test(existingUnitText.toLowerCase())) {
|
|
655
|
-
if (unit !== undefined) {
|
|
656
|
-
throw new ParseError("Ambiguous unit \"".concat(unitRaw, "\""));
|
|
657
|
-
}
|
|
658
|
-
unit = existingUnit;
|
|
659
|
-
}
|
|
564
|
+
const unitRaw = args.shift();
|
|
565
|
+
let unit = undefined;
|
|
566
|
+
for (const existingUnit of EXPECTATION_UNITS) {
|
|
567
|
+
let existingUnitText = existingUnit;
|
|
568
|
+
existingUnitText = existingUnitText.substring(0, existingUnitText.length - 1);
|
|
569
|
+
if (existingUnitText === 'CHARACTER') {
|
|
570
|
+
existingUnitText = 'CHAR';
|
|
660
571
|
}
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
572
|
+
if (new RegExp(`^${existingUnitText.toLowerCase()}`).test(unitRaw.toLowerCase()) ||
|
|
573
|
+
new RegExp(`^${unitRaw.toLowerCase()}`).test(existingUnitText.toLowerCase())) {
|
|
574
|
+
if (unit !== undefined) {
|
|
575
|
+
throw new ParseError(`Ambiguous unit "${unitRaw}"`);
|
|
576
|
+
}
|
|
577
|
+
unit = existingUnit;
|
|
666
578
|
}
|
|
667
|
-
finally { if (e_1) throw e_1.error; }
|
|
668
579
|
}
|
|
669
580
|
if (unit === undefined) {
|
|
670
|
-
throw new ParseError(
|
|
581
|
+
throw new ParseError(`Invalid unit "${unitRaw}"`);
|
|
671
582
|
}
|
|
672
583
|
return {
|
|
673
584
|
type: 'EXPECT',
|
|
674
|
-
sign
|
|
675
|
-
unit
|
|
676
|
-
amount
|
|
585
|
+
sign,
|
|
586
|
+
unit,
|
|
587
|
+
amount,
|
|
677
588
|
};
|
|
678
589
|
}
|
|
679
590
|
catch (error) {
|
|
680
591
|
if (!(error instanceof Error)) {
|
|
681
592
|
throw error;
|
|
682
593
|
}
|
|
683
|
-
throw new ParseError(spaceTrim(
|
|
684
|
-
|
|
685
|
-
|
|
594
|
+
throw new ParseError(spaceTrim((block) => `
|
|
595
|
+
Invalid FORMAT command
|
|
596
|
+
${block(error.message)}:
|
|
597
|
+
`));
|
|
686
598
|
}
|
|
687
599
|
},
|
|
688
600
|
/**
|
|
@@ -690,20 +602,20 @@ var expectCommandParser = {
|
|
|
690
602
|
*
|
|
691
603
|
* Note: `$` is used to indicate that this function mutates given `taskJson`
|
|
692
604
|
*/
|
|
693
|
-
$applyToTaskJson
|
|
605
|
+
$applyToTaskJson(command, $taskJson) {
|
|
694
606
|
// eslint-disable-next-line no-case-declarations
|
|
695
|
-
|
|
607
|
+
const unit = command.unit.toLowerCase();
|
|
696
608
|
$taskJson.expectations = $taskJson.expectations || {};
|
|
697
609
|
$taskJson.expectations[unit] = $taskJson.expectations[unit] || {};
|
|
698
610
|
if (command.sign === 'MINIMUM' || command.sign === 'EXACTLY') {
|
|
699
611
|
if ($taskJson.expectations[unit].min !== undefined) {
|
|
700
|
-
throw new ParseError(
|
|
612
|
+
throw new ParseError(`Already defined minumum ${$taskJson.expectations[unit].min} ${command.unit.toLowerCase()}, now trying to redefine it to ${command.amount}`);
|
|
701
613
|
}
|
|
702
614
|
$taskJson.expectations[unit].min = command.amount;
|
|
703
615
|
} /* not else */
|
|
704
616
|
if (command.sign === 'MAXIMUM' || command.sign === 'EXACTLY') {
|
|
705
617
|
if ($taskJson.expectations[unit].max !== undefined) {
|
|
706
|
-
throw new ParseError(
|
|
618
|
+
throw new ParseError(`Already defined maximum ${$taskJson.expectations[unit].max} ${command.unit.toLowerCase()}, now trying to redefine it to ${command.amount}`);
|
|
707
619
|
}
|
|
708
620
|
$taskJson.expectations[unit].max = command.amount;
|
|
709
621
|
}
|
|
@@ -713,16 +625,16 @@ var expectCommandParser = {
|
|
|
713
625
|
*
|
|
714
626
|
* Note: This is used in `pipelineJsonToString` utility
|
|
715
627
|
*/
|
|
716
|
-
stringify
|
|
717
|
-
return
|
|
628
|
+
stringify(command) {
|
|
629
|
+
return `---`; // <- TODO: [🛋] Implement
|
|
718
630
|
},
|
|
719
631
|
/**
|
|
720
632
|
* Reads the FORMAT command from the `TaskJson`
|
|
721
633
|
*
|
|
722
634
|
* Note: This is used in `pipelineJsonToString` utility
|
|
723
635
|
*/
|
|
724
|
-
takeFromTaskJson
|
|
725
|
-
throw new NotYetImplementedError(
|
|
636
|
+
takeFromTaskJson($taskJson) {
|
|
637
|
+
throw new NotYetImplementedError(`[🛋] Not implemented yet`); // <- TODO: [🛋] Implement
|
|
726
638
|
},
|
|
727
639
|
};
|
|
728
640
|
|
|
@@ -734,40 +646,34 @@ var expectCommandParser = {
|
|
|
734
646
|
*
|
|
735
647
|
* @public exported from `@promptbook/core`
|
|
736
648
|
*/
|
|
737
|
-
|
|
738
|
-
__extends(AbstractFormatError, _super);
|
|
649
|
+
class AbstractFormatError extends Error {
|
|
739
650
|
// Note: To allow instanceof do not put here error `name`
|
|
740
651
|
// public readonly name = 'AbstractFormatError';
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
Object.setPrototypeOf(
|
|
744
|
-
return _this;
|
|
652
|
+
constructor(message) {
|
|
653
|
+
super(message);
|
|
654
|
+
Object.setPrototypeOf(this, AbstractFormatError.prototype);
|
|
745
655
|
}
|
|
746
|
-
|
|
747
|
-
}(Error));
|
|
656
|
+
}
|
|
748
657
|
|
|
749
658
|
/**
|
|
750
659
|
* This error indicates problem with parsing of CSV
|
|
751
660
|
*
|
|
752
661
|
* @public exported from `@promptbook/core`
|
|
753
662
|
*/
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
Object.setPrototypeOf(_this, CsvFormatError.prototype);
|
|
760
|
-
return _this;
|
|
663
|
+
class CsvFormatError extends AbstractFormatError {
|
|
664
|
+
constructor(message) {
|
|
665
|
+
super(message);
|
|
666
|
+
this.name = 'CsvFormatError';
|
|
667
|
+
Object.setPrototypeOf(this, CsvFormatError.prototype);
|
|
761
668
|
}
|
|
762
|
-
|
|
763
|
-
}(AbstractFormatError));
|
|
669
|
+
}
|
|
764
670
|
|
|
765
671
|
/**
|
|
766
672
|
* @@@
|
|
767
673
|
*
|
|
768
674
|
* @public exported from `@promptbook/core`
|
|
769
675
|
*/
|
|
770
|
-
|
|
676
|
+
const MANDATORY_CSV_SETTINGS = Object.freeze({
|
|
771
677
|
header: true,
|
|
772
678
|
// encoding: 'utf-8',
|
|
773
679
|
});
|
|
@@ -778,92 +684,76 @@ var MANDATORY_CSV_SETTINGS = Object.freeze({
|
|
|
778
684
|
* @public exported from `@promptbook/core`
|
|
779
685
|
* <- TODO: [🏢] Export from package `@promptbook/csv`
|
|
780
686
|
*/
|
|
781
|
-
|
|
687
|
+
const CsvFormatDefinition = {
|
|
782
688
|
formatName: 'CSV',
|
|
783
689
|
aliases: ['SPREADSHEET', 'TABLE'],
|
|
784
|
-
isValid
|
|
690
|
+
isValid(value, settings, schema) {
|
|
785
691
|
return true;
|
|
786
692
|
},
|
|
787
|
-
canBeValid
|
|
693
|
+
canBeValid(partialValue, settings, schema) {
|
|
788
694
|
return true;
|
|
789
695
|
},
|
|
790
|
-
heal
|
|
696
|
+
heal(value, settings, schema) {
|
|
791
697
|
throw new Error('Not implemented');
|
|
792
698
|
},
|
|
793
699
|
subvalueDefinitions: [
|
|
794
700
|
{
|
|
795
701
|
subvalueName: 'ROW',
|
|
796
|
-
mapValues
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
}); }))];
|
|
824
|
-
case 1:
|
|
825
|
-
mappedData = _a.sent();
|
|
826
|
-
return [2 /*return*/, unparse(mappedData, __assign(__assign({}, settings), MANDATORY_CSV_SETTINGS))];
|
|
827
|
-
}
|
|
828
|
-
});
|
|
829
|
-
});
|
|
702
|
+
async mapValues(value, outputParameterName, settings, mapCallback) {
|
|
703
|
+
// TODO: [👨🏾🤝👨🏼] DRY csv parsing
|
|
704
|
+
const csv = parse(value, { ...settings, ...MANDATORY_CSV_SETTINGS });
|
|
705
|
+
if (csv.errors.length !== 0) {
|
|
706
|
+
throw new CsvFormatError(spaceTrim((block) => `
|
|
707
|
+
CSV parsing error
|
|
708
|
+
|
|
709
|
+
Error(s) from CSV parsing:
|
|
710
|
+
${block(csv.errors.map((error) => error.message).join('\n\n'))}
|
|
711
|
+
|
|
712
|
+
The CSV setings:
|
|
713
|
+
${block(JSON.stringify({ ...settings, ...MANDATORY_CSV_SETTINGS }, null, 2))}
|
|
714
|
+
|
|
715
|
+
The CSV data:
|
|
716
|
+
${block(value)}
|
|
717
|
+
`));
|
|
718
|
+
}
|
|
719
|
+
const mappedData = await Promise.all(csv.data.map(async (row, index) => {
|
|
720
|
+
if (row[outputParameterName]) {
|
|
721
|
+
throw new CsvFormatError(`Can not overwrite existing column "${outputParameterName}" in CSV row`);
|
|
722
|
+
}
|
|
723
|
+
return {
|
|
724
|
+
...row,
|
|
725
|
+
[outputParameterName]: await mapCallback(row, index),
|
|
726
|
+
};
|
|
727
|
+
}));
|
|
728
|
+
return unparse(mappedData, { ...settings, ...MANDATORY_CSV_SETTINGS });
|
|
830
729
|
},
|
|
831
730
|
},
|
|
832
731
|
{
|
|
833
732
|
subvalueName: 'CELL',
|
|
834
|
-
mapValues
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
}))];
|
|
859
|
-
});
|
|
860
|
-
}); }))];
|
|
861
|
-
case 1:
|
|
862
|
-
mappedData = _a.sent();
|
|
863
|
-
return [2 /*return*/, unparse(mappedData, __assign(__assign({}, settings), MANDATORY_CSV_SETTINGS))];
|
|
864
|
-
}
|
|
865
|
-
});
|
|
866
|
-
});
|
|
733
|
+
async mapValues(value, outputParameterName, settings, mapCallback) {
|
|
734
|
+
// TODO: [👨🏾🤝👨🏼] DRY csv parsing
|
|
735
|
+
const csv = parse(value, { ...settings, ...MANDATORY_CSV_SETTINGS });
|
|
736
|
+
if (csv.errors.length !== 0) {
|
|
737
|
+
throw new CsvFormatError(spaceTrim((block) => `
|
|
738
|
+
CSV parsing error
|
|
739
|
+
|
|
740
|
+
Error(s) from CSV parsing:
|
|
741
|
+
${block(csv.errors.map((error) => error.message).join('\n\n'))}
|
|
742
|
+
|
|
743
|
+
The CSV setings:
|
|
744
|
+
${block(JSON.stringify({ ...settings, ...MANDATORY_CSV_SETTINGS }, null, 2))}
|
|
745
|
+
|
|
746
|
+
The CSV data:
|
|
747
|
+
${block(value)}
|
|
748
|
+
`));
|
|
749
|
+
}
|
|
750
|
+
const mappedData = await Promise.all(csv.data.map(async (row, rowIndex) => {
|
|
751
|
+
return /* not await */ Promise.all(Object.entries(row).map(async ([key, value], columnIndex) => {
|
|
752
|
+
const index = rowIndex * Object.keys(row).length + columnIndex;
|
|
753
|
+
return /* not await */ mapCallback({ [key]: value }, index);
|
|
754
|
+
}));
|
|
755
|
+
}));
|
|
756
|
+
return unparse(mappedData, { ...settings, ...MANDATORY_CSV_SETTINGS });
|
|
867
757
|
},
|
|
868
758
|
},
|
|
869
759
|
],
|
|
@@ -902,16 +792,16 @@ function isValidJsonString(value /* <- [👨⚖️] */) {
|
|
|
902
792
|
*
|
|
903
793
|
* @private still in development [🏢]
|
|
904
794
|
*/
|
|
905
|
-
|
|
795
|
+
const JsonFormatDefinition = {
|
|
906
796
|
formatName: 'JSON',
|
|
907
797
|
mimeType: 'application/json',
|
|
908
|
-
isValid
|
|
798
|
+
isValid(value, settings, schema) {
|
|
909
799
|
return isValidJsonString(value);
|
|
910
800
|
},
|
|
911
|
-
canBeValid
|
|
801
|
+
canBeValid(partialValue, settings, schema) {
|
|
912
802
|
return true;
|
|
913
803
|
},
|
|
914
|
-
heal
|
|
804
|
+
heal(value, settings, schema) {
|
|
915
805
|
throw new Error('Not implemented');
|
|
916
806
|
},
|
|
917
807
|
subvalueDefinitions: [],
|
|
@@ -935,48 +825,37 @@ var JsonFormatDefinition = {
|
|
|
935
825
|
*
|
|
936
826
|
* @public exported from `@promptbook/core`
|
|
937
827
|
*/
|
|
938
|
-
|
|
828
|
+
const TextFormatDefinition = {
|
|
939
829
|
formatName: 'TEXT',
|
|
940
|
-
isValid
|
|
830
|
+
isValid(value) {
|
|
941
831
|
return typeof value === 'string';
|
|
942
832
|
},
|
|
943
|
-
canBeValid
|
|
833
|
+
canBeValid(partialValue) {
|
|
944
834
|
return typeof partialValue === 'string';
|
|
945
835
|
},
|
|
946
|
-
heal
|
|
836
|
+
heal() {
|
|
947
837
|
throw new UnexpectedError('It does not make sense to call `TextFormatDefinition.heal`');
|
|
948
838
|
},
|
|
949
839
|
subvalueDefinitions: [
|
|
950
840
|
{
|
|
951
841
|
subvalueName: 'LINE',
|
|
952
|
-
mapValues
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
/* not await */ return mapCallback({
|
|
962
|
-
lineContent: lineContent,
|
|
963
|
-
// TODO: [🧠] Maybe also put here `lineNumber`
|
|
964
|
-
}, lineNumber);
|
|
965
|
-
}))];
|
|
966
|
-
case 1:
|
|
967
|
-
mappedLines = _a.sent();
|
|
968
|
-
return [2 /*return*/, mappedLines.join('\n')];
|
|
969
|
-
}
|
|
970
|
-
});
|
|
971
|
-
});
|
|
842
|
+
async mapValues(value, outputParameterName, settings, mapCallback) {
|
|
843
|
+
const lines = value.split('\n');
|
|
844
|
+
const mappedLines = await Promise.all(lines.map((lineContent, lineNumber) =>
|
|
845
|
+
// TODO: [🧠] Maybe option to skip empty line
|
|
846
|
+
/* not await */ mapCallback({
|
|
847
|
+
lineContent,
|
|
848
|
+
// TODO: [🧠] Maybe also put here `lineNumber`
|
|
849
|
+
}, lineNumber)));
|
|
850
|
+
return mappedLines.join('\n');
|
|
972
851
|
},
|
|
973
852
|
},
|
|
974
|
-
// <- TODO: [🧠][🤠] Here should be all words, characters, lines, paragraphs, pages
|
|
853
|
+
// <- TODO: [🧠][🤠] Here should be all words, characters, lines, paragraphs, pages available as subvalues
|
|
975
854
|
],
|
|
976
855
|
};
|
|
977
856
|
/**
|
|
978
857
|
* TODO: [1] Make type for XML Text and Schema
|
|
979
|
-
* TODO: [🧠][🤠] Here should be all words, characters, lines, paragraphs, pages
|
|
858
|
+
* TODO: [🧠][🤠] Here should be all words, characters, lines, paragraphs, pages available as subvalues
|
|
980
859
|
* TODO: [🍓] In `TextFormatDefinition` implement simple `isValid`
|
|
981
860
|
* TODO: [🍓] In `TextFormatDefinition` implement partial `canBeValid`
|
|
982
861
|
* TODO: [🍓] In `TextFormatDefinition` implement `heal
|
|
@@ -989,16 +868,16 @@ var TextFormatDefinition = {
|
|
|
989
868
|
*
|
|
990
869
|
* @private still in development [🏢]
|
|
991
870
|
*/
|
|
992
|
-
|
|
871
|
+
const XmlFormatDefinition = {
|
|
993
872
|
formatName: 'XML',
|
|
994
873
|
mimeType: 'application/xml',
|
|
995
|
-
isValid
|
|
874
|
+
isValid(value, settings, schema) {
|
|
996
875
|
return true;
|
|
997
876
|
},
|
|
998
|
-
canBeValid
|
|
877
|
+
canBeValid(partialValue, settings, schema) {
|
|
999
878
|
return true;
|
|
1000
879
|
},
|
|
1001
|
-
heal
|
|
880
|
+
heal(value, settings, schema) {
|
|
1002
881
|
throw new Error('Not implemented');
|
|
1003
882
|
},
|
|
1004
883
|
subvalueDefinitions: [],
|
|
@@ -1020,7 +899,7 @@ var XmlFormatDefinition = {
|
|
|
1020
899
|
*
|
|
1021
900
|
* @private internal index of `...` <- TODO [🏢]
|
|
1022
901
|
*/
|
|
1023
|
-
|
|
902
|
+
const FORMAT_DEFINITIONS = [
|
|
1024
903
|
JsonFormatDefinition,
|
|
1025
904
|
XmlFormatDefinition,
|
|
1026
905
|
TextFormatDefinition,
|
|
@@ -1040,46 +919,35 @@ var FORMAT_DEFINITIONS = [
|
|
|
1040
919
|
* @public exported from `@promptbook/utils`
|
|
1041
920
|
*/
|
|
1042
921
|
function normalizeTo_SCREAMING_CASE(text) {
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
if (/^[a-z]$/.test(char)) {
|
|
1052
|
-
charType = 'LOWERCASE';
|
|
1053
|
-
normalizedChar = char.toUpperCase();
|
|
1054
|
-
}
|
|
1055
|
-
else if (/^[A-Z]$/.test(char)) {
|
|
1056
|
-
charType = 'UPPERCASE';
|
|
1057
|
-
normalizedChar = char;
|
|
1058
|
-
}
|
|
1059
|
-
else if (/^[0-9]$/.test(char)) {
|
|
1060
|
-
charType = 'NUMBER';
|
|
1061
|
-
normalizedChar = char;
|
|
1062
|
-
}
|
|
1063
|
-
else {
|
|
1064
|
-
charType = 'OTHER';
|
|
1065
|
-
normalizedChar = '_';
|
|
1066
|
-
}
|
|
1067
|
-
if (charType !== lastCharType &&
|
|
1068
|
-
!(lastCharType === 'UPPERCASE' && charType === 'LOWERCASE') &&
|
|
1069
|
-
!(lastCharType === 'NUMBER') &&
|
|
1070
|
-
!(charType === 'NUMBER')) {
|
|
1071
|
-
normalizedName += '_';
|
|
1072
|
-
}
|
|
1073
|
-
normalizedName += normalizedChar;
|
|
1074
|
-
lastCharType = charType;
|
|
922
|
+
let charType;
|
|
923
|
+
let lastCharType = 'OTHER';
|
|
924
|
+
let normalizedName = '';
|
|
925
|
+
for (const char of text) {
|
|
926
|
+
let normalizedChar;
|
|
927
|
+
if (/^[a-z]$/.test(char)) {
|
|
928
|
+
charType = 'LOWERCASE';
|
|
929
|
+
normalizedChar = char.toUpperCase();
|
|
1075
930
|
}
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
try {
|
|
1080
|
-
if (text_1_1 && !text_1_1.done && (_a = text_1.return)) _a.call(text_1);
|
|
931
|
+
else if (/^[A-Z]$/.test(char)) {
|
|
932
|
+
charType = 'UPPERCASE';
|
|
933
|
+
normalizedChar = char;
|
|
1081
934
|
}
|
|
1082
|
-
|
|
935
|
+
else if (/^[0-9]$/.test(char)) {
|
|
936
|
+
charType = 'NUMBER';
|
|
937
|
+
normalizedChar = char;
|
|
938
|
+
}
|
|
939
|
+
else {
|
|
940
|
+
charType = 'OTHER';
|
|
941
|
+
normalizedChar = '_';
|
|
942
|
+
}
|
|
943
|
+
if (charType !== lastCharType &&
|
|
944
|
+
!(lastCharType === 'UPPERCASE' && charType === 'LOWERCASE') &&
|
|
945
|
+
!(lastCharType === 'NUMBER') &&
|
|
946
|
+
!(charType === 'NUMBER')) {
|
|
947
|
+
normalizedName += '_';
|
|
948
|
+
}
|
|
949
|
+
normalizedName += normalizedChar;
|
|
950
|
+
lastCharType = charType;
|
|
1083
951
|
}
|
|
1084
952
|
normalizedName = normalizedName.replace(/_+/g, '_');
|
|
1085
953
|
normalizedName = normalizedName.replace(/_?\/_?/g, '/');
|
|
@@ -1103,8 +971,11 @@ function normalizeTo_SCREAMING_CASE(text) {
|
|
|
1103
971
|
* @public exported from `@promptbook/utils`
|
|
1104
972
|
*/
|
|
1105
973
|
function orderJson(options) {
|
|
1106
|
-
|
|
1107
|
-
|
|
974
|
+
const { value, order } = options;
|
|
975
|
+
const orderedValue = {
|
|
976
|
+
...(order === undefined ? {} : Object.fromEntries(order.map((key) => [key, undefined]))),
|
|
977
|
+
...value,
|
|
978
|
+
};
|
|
1108
979
|
return orderedValue;
|
|
1109
980
|
}
|
|
1110
981
|
|
|
@@ -1118,26 +989,15 @@ function orderJson(options) {
|
|
|
1118
989
|
* @public exported from `@promptbook/utils`
|
|
1119
990
|
*/
|
|
1120
991
|
function $deepFreeze(objectValue) {
|
|
1121
|
-
var e_1, _a;
|
|
1122
992
|
if (Array.isArray(objectValue)) {
|
|
1123
|
-
return Object.freeze(objectValue.map(
|
|
993
|
+
return Object.freeze(objectValue.map((item) => $deepFreeze(item)));
|
|
1124
994
|
}
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
if (value && typeof value === 'object') {
|
|
1131
|
-
$deepFreeze(value);
|
|
1132
|
-
}
|
|
1133
|
-
}
|
|
1134
|
-
}
|
|
1135
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
1136
|
-
finally {
|
|
1137
|
-
try {
|
|
1138
|
-
if (propertyNames_1_1 && !propertyNames_1_1.done && (_a = propertyNames_1.return)) _a.call(propertyNames_1);
|
|
995
|
+
const propertyNames = Object.getOwnPropertyNames(objectValue);
|
|
996
|
+
for (const propertyName of propertyNames) {
|
|
997
|
+
const value = objectValue[propertyName];
|
|
998
|
+
if (value && typeof value === 'object') {
|
|
999
|
+
$deepFreeze(value);
|
|
1139
1000
|
}
|
|
1140
|
-
finally { if (e_1) throw e_1.error; }
|
|
1141
1001
|
}
|
|
1142
1002
|
Object.freeze(objectValue);
|
|
1143
1003
|
return objectValue;
|
|
@@ -1167,10 +1027,9 @@ function $deepFreeze(objectValue) {
|
|
|
1167
1027
|
* @public exported from `@promptbook/utils`
|
|
1168
1028
|
*/
|
|
1169
1029
|
function checkSerializableAsJson(options) {
|
|
1170
|
-
|
|
1171
|
-
var value = options.value, name = options.name, message = options.message;
|
|
1030
|
+
const { value, name, message } = options;
|
|
1172
1031
|
if (value === undefined) {
|
|
1173
|
-
throw new UnexpectedError(
|
|
1032
|
+
throw new UnexpectedError(`${name} is undefined`);
|
|
1174
1033
|
}
|
|
1175
1034
|
else if (value === null) {
|
|
1176
1035
|
return;
|
|
@@ -1185,49 +1044,54 @@ function checkSerializableAsJson(options) {
|
|
|
1185
1044
|
return;
|
|
1186
1045
|
}
|
|
1187
1046
|
else if (typeof value === 'symbol') {
|
|
1188
|
-
throw new UnexpectedError(
|
|
1047
|
+
throw new UnexpectedError(`${name} is symbol`);
|
|
1189
1048
|
}
|
|
1190
1049
|
else if (typeof value === 'function') {
|
|
1191
|
-
throw new UnexpectedError(
|
|
1050
|
+
throw new UnexpectedError(`${name} is function`);
|
|
1192
1051
|
}
|
|
1193
1052
|
else if (typeof value === 'object' && Array.isArray(value)) {
|
|
1194
|
-
for (
|
|
1195
|
-
checkSerializableAsJson({ name:
|
|
1053
|
+
for (let i = 0; i < value.length; i++) {
|
|
1054
|
+
checkSerializableAsJson({ name: `${name}[${i}]`, value: value[i], message });
|
|
1196
1055
|
}
|
|
1197
1056
|
}
|
|
1198
1057
|
else if (typeof value === 'object') {
|
|
1199
1058
|
if (value instanceof Date) {
|
|
1200
|
-
throw new UnexpectedError(spaceTrim(
|
|
1059
|
+
throw new UnexpectedError(spaceTrim((block) => `
|
|
1060
|
+
\`${name}\` is Date
|
|
1061
|
+
|
|
1062
|
+
Use \`string_date_iso8601\` instead
|
|
1063
|
+
|
|
1064
|
+
Additional message for \`${name}\`:
|
|
1065
|
+
${block(message || '(nothing)')}
|
|
1066
|
+
`));
|
|
1201
1067
|
}
|
|
1202
1068
|
else if (value instanceof Map) {
|
|
1203
|
-
throw new UnexpectedError(
|
|
1069
|
+
throw new UnexpectedError(`${name} is Map`);
|
|
1204
1070
|
}
|
|
1205
1071
|
else if (value instanceof Set) {
|
|
1206
|
-
throw new UnexpectedError(
|
|
1072
|
+
throw new UnexpectedError(`${name} is Set`);
|
|
1207
1073
|
}
|
|
1208
1074
|
else if (value instanceof RegExp) {
|
|
1209
|
-
throw new UnexpectedError(
|
|
1075
|
+
throw new UnexpectedError(`${name} is RegExp`);
|
|
1210
1076
|
}
|
|
1211
1077
|
else if (value instanceof Error) {
|
|
1212
|
-
throw new UnexpectedError(spaceTrim(
|
|
1078
|
+
throw new UnexpectedError(spaceTrim((block) => `
|
|
1079
|
+
\`${name}\` is unserialized Error
|
|
1080
|
+
|
|
1081
|
+
Use function \`serializeError\`
|
|
1082
|
+
|
|
1083
|
+
Additional message for \`${name}\`:
|
|
1084
|
+
${block(message || '(nothing)')}
|
|
1085
|
+
|
|
1086
|
+
`));
|
|
1213
1087
|
}
|
|
1214
1088
|
else {
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
// Note: undefined in object is serializable - it is just omited
|
|
1220
|
-
continue;
|
|
1221
|
-
}
|
|
1222
|
-
checkSerializableAsJson({ name: "".concat(name, ".").concat(subName), value: subValue, message: message });
|
|
1089
|
+
for (const [subName, subValue] of Object.entries(value)) {
|
|
1090
|
+
if (subValue === undefined) {
|
|
1091
|
+
// Note: undefined in object is serializable - it is just omited
|
|
1092
|
+
continue;
|
|
1223
1093
|
}
|
|
1224
|
-
|
|
1225
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
1226
|
-
finally {
|
|
1227
|
-
try {
|
|
1228
|
-
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
1229
|
-
}
|
|
1230
|
-
finally { if (e_1) throw e_1.error; }
|
|
1094
|
+
checkSerializableAsJson({ name: `${name}.${subName}`, value: subValue, message });
|
|
1231
1095
|
}
|
|
1232
1096
|
try {
|
|
1233
1097
|
JSON.stringify(value); // <- TODO: [0]
|
|
@@ -1236,7 +1100,14 @@ function checkSerializableAsJson(options) {
|
|
|
1236
1100
|
if (!(error instanceof Error)) {
|
|
1237
1101
|
throw error;
|
|
1238
1102
|
}
|
|
1239
|
-
throw new UnexpectedError(spaceTrim(
|
|
1103
|
+
throw new UnexpectedError(spaceTrim((block) => `
|
|
1104
|
+
\`${name}\` is not serializable
|
|
1105
|
+
|
|
1106
|
+
${block(error.stack || error.message)}
|
|
1107
|
+
|
|
1108
|
+
Additional message for \`${name}\`:
|
|
1109
|
+
${block(message || '(nothing)')}
|
|
1110
|
+
`));
|
|
1240
1111
|
}
|
|
1241
1112
|
/*
|
|
1242
1113
|
TODO: [0] Is there some more elegant way to check circular references?
|
|
@@ -1261,7 +1132,12 @@ function checkSerializableAsJson(options) {
|
|
|
1261
1132
|
}
|
|
1262
1133
|
}
|
|
1263
1134
|
else {
|
|
1264
|
-
throw new UnexpectedError(spaceTrim(
|
|
1135
|
+
throw new UnexpectedError(spaceTrim((block) => `
|
|
1136
|
+
\`${name}\` is unknown type
|
|
1137
|
+
|
|
1138
|
+
Additional message for \`${name}\`:
|
|
1139
|
+
${block(message || '(nothing)')}
|
|
1140
|
+
`));
|
|
1265
1141
|
}
|
|
1266
1142
|
}
|
|
1267
1143
|
/**
|
|
@@ -1307,9 +1183,9 @@ function deepClone(objectValue) {
|
|
|
1307
1183
|
* @public exported from `@promptbook/utils`
|
|
1308
1184
|
*/
|
|
1309
1185
|
function exportJson(options) {
|
|
1310
|
-
|
|
1311
|
-
checkSerializableAsJson({ name
|
|
1312
|
-
|
|
1186
|
+
const { name, value, order, message } = options;
|
|
1187
|
+
checkSerializableAsJson({ name, value, message });
|
|
1188
|
+
const orderedValue =
|
|
1313
1189
|
// TODO: Fix error "Type instantiation is excessively deep and possibly infinite."
|
|
1314
1190
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
1315
1191
|
// @ts-ignore
|
|
@@ -1332,15 +1208,15 @@ function exportJson(options) {
|
|
|
1332
1208
|
*
|
|
1333
1209
|
* @private within the repository
|
|
1334
1210
|
*/
|
|
1335
|
-
|
|
1211
|
+
const REPLACING_NONCE = 'ptbkauk42kV2dzao34faw7FudQUHYPtW';
|
|
1336
1212
|
/**
|
|
1337
1213
|
* The names of the parameters that are reserved for special purposes
|
|
1338
1214
|
*
|
|
1339
1215
|
* @public exported from `@promptbook/core`
|
|
1340
1216
|
*/
|
|
1341
|
-
|
|
1217
|
+
const RESERVED_PARAMETER_NAMES = exportJson({
|
|
1342
1218
|
name: 'RESERVED_PARAMETER_NAMES',
|
|
1343
|
-
message:
|
|
1219
|
+
message: `The names of the parameters that are reserved for special purposes`,
|
|
1344
1220
|
value: [
|
|
1345
1221
|
'content',
|
|
1346
1222
|
'context',
|
|
@@ -1367,53 +1243,41 @@ var RESERVED_PARAMETER_NAMES = exportJson({
|
|
|
1367
1243
|
* @example 'iLovePromptbook'
|
|
1368
1244
|
* @public exported from `@promptbook/utils`
|
|
1369
1245
|
*/
|
|
1370
|
-
function normalizeTo_camelCase(text, _isFirstLetterCapital) {
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
normalizedChar =
|
|
1395
|
-
}
|
|
1396
|
-
if (!lastCharType) {
|
|
1397
|
-
if (_isFirstLetterCapital) {
|
|
1398
|
-
normalizedChar = normalizedChar.toUpperCase(); //TODO: DRY
|
|
1399
|
-
}
|
|
1400
|
-
}
|
|
1401
|
-
else if (charType !== lastCharType &&
|
|
1402
|
-
!(charType === 'LOWERCASE' && lastCharType === 'UPPERCASE') &&
|
|
1403
|
-
!(lastCharType === 'NUMBER') &&
|
|
1404
|
-
!(charType === 'NUMBER')) {
|
|
1405
|
-
normalizedChar = normalizedChar.toUpperCase(); //TODO: [🌺] DRY
|
|
1246
|
+
function normalizeTo_camelCase(text, _isFirstLetterCapital = false) {
|
|
1247
|
+
let charType;
|
|
1248
|
+
let lastCharType = null;
|
|
1249
|
+
let normalizedName = '';
|
|
1250
|
+
for (const char of text) {
|
|
1251
|
+
let normalizedChar;
|
|
1252
|
+
if (/^[a-z]$/.test(char)) {
|
|
1253
|
+
charType = 'LOWERCASE';
|
|
1254
|
+
normalizedChar = char;
|
|
1255
|
+
}
|
|
1256
|
+
else if (/^[A-Z]$/.test(char)) {
|
|
1257
|
+
charType = 'UPPERCASE';
|
|
1258
|
+
normalizedChar = char.toLowerCase();
|
|
1259
|
+
}
|
|
1260
|
+
else if (/^[0-9]$/.test(char)) {
|
|
1261
|
+
charType = 'NUMBER';
|
|
1262
|
+
normalizedChar = char;
|
|
1263
|
+
}
|
|
1264
|
+
else {
|
|
1265
|
+
charType = 'OTHER';
|
|
1266
|
+
normalizedChar = '';
|
|
1267
|
+
}
|
|
1268
|
+
if (!lastCharType) {
|
|
1269
|
+
if (_isFirstLetterCapital) {
|
|
1270
|
+
normalizedChar = normalizedChar.toUpperCase(); //TODO: DRY
|
|
1406
1271
|
}
|
|
1407
|
-
normalizedName += normalizedChar;
|
|
1408
|
-
lastCharType = charType;
|
|
1409
1272
|
}
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1273
|
+
else if (charType !== lastCharType &&
|
|
1274
|
+
!(charType === 'LOWERCASE' && lastCharType === 'UPPERCASE') &&
|
|
1275
|
+
!(lastCharType === 'NUMBER') &&
|
|
1276
|
+
!(charType === 'NUMBER')) {
|
|
1277
|
+
normalizedChar = normalizedChar.toUpperCase(); //TODO: [🌺] DRY
|
|
1415
1278
|
}
|
|
1416
|
-
|
|
1279
|
+
normalizedName += normalizedChar;
|
|
1280
|
+
lastCharType = charType;
|
|
1417
1281
|
}
|
|
1418
1282
|
return normalizedName;
|
|
1419
1283
|
}
|
|
@@ -1421,7 +1285,7 @@ function normalizeTo_camelCase(text, _isFirstLetterCapital) {
|
|
|
1421
1285
|
* TODO: [🌺] Use some intermediate util splitWords
|
|
1422
1286
|
*/
|
|
1423
1287
|
|
|
1424
|
-
|
|
1288
|
+
const defaultDiacriticsRemovalMap = [
|
|
1425
1289
|
{
|
|
1426
1290
|
base: 'A',
|
|
1427
1291
|
letters: '\u0041\u24B6\uFF21\u00C0\u00C1\u00C2\u1EA6\u1EA4\u1EAA\u1EA8\u00C3\u0100\u0102\u1EB0\u1EAE\u1EB4\u1EB2\u0226\u01E0\u00C4\u01DE\u1EA2\u00C5\u01FA\u01CD\u0200\u0202\u1EA0\u1EAC\u1EB6\u1E00\u0104\u023A\u2C6F',
|
|
@@ -1640,12 +1504,12 @@ var defaultDiacriticsRemovalMap = [
|
|
|
1640
1504
|
*
|
|
1641
1505
|
* @public exported from `@promptbook/utils`
|
|
1642
1506
|
*/
|
|
1643
|
-
|
|
1507
|
+
const DIACRITIC_VARIANTS_LETTERS = {};
|
|
1644
1508
|
// tslint:disable-next-line: prefer-for-of
|
|
1645
|
-
for (
|
|
1646
|
-
|
|
1509
|
+
for (let i = 0; i < defaultDiacriticsRemovalMap.length; i++) {
|
|
1510
|
+
const letters = defaultDiacriticsRemovalMap[i].letters;
|
|
1647
1511
|
// tslint:disable-next-line: prefer-for-of
|
|
1648
|
-
for (
|
|
1512
|
+
for (let j = 0; j < letters.length; j++) {
|
|
1649
1513
|
DIACRITIC_VARIANTS_LETTERS[letters[j]] = defaultDiacriticsRemovalMap[i].base;
|
|
1650
1514
|
}
|
|
1651
1515
|
}
|
|
@@ -1674,7 +1538,7 @@ for (var i = 0; i < defaultDiacriticsRemovalMap.length; i++) {
|
|
|
1674
1538
|
*/
|
|
1675
1539
|
function removeDiacritics(input) {
|
|
1676
1540
|
/*eslint no-control-regex: "off"*/
|
|
1677
|
-
return input.replace(/[^\u0000-\u007E]/g,
|
|
1541
|
+
return input.replace(/[^\u0000-\u007E]/g, (a) => {
|
|
1678
1542
|
return DIACRITIC_VARIANTS_LETTERS[a] || a;
|
|
1679
1543
|
});
|
|
1680
1544
|
}
|
|
@@ -1730,33 +1594,22 @@ function removeQuotes(text) {
|
|
|
1730
1594
|
* @private within the repository
|
|
1731
1595
|
*/
|
|
1732
1596
|
function validateParameterName(parameterName) {
|
|
1733
|
-
|
|
1734
|
-
|
|
1735
|
-
|
|
1736
|
-
|
|
1737
|
-
|
|
1738
|
-
|
|
1739
|
-
|
|
1740
|
-
|
|
1741
|
-
|
|
1742
|
-
|
|
1743
|
-
|
|
1744
|
-
|
|
1745
|
-
|
|
1597
|
+
const rawParameterName = parameterName;
|
|
1598
|
+
for (const [start, end] of [
|
|
1599
|
+
['`', '`'],
|
|
1600
|
+
['{', '}'],
|
|
1601
|
+
['[', ']'],
|
|
1602
|
+
['(', ')'],
|
|
1603
|
+
['<', '>'],
|
|
1604
|
+
]) {
|
|
1605
|
+
if (parameterName.substring(0, 1) === start &&
|
|
1606
|
+
parameterName.substring(parameterName.length - 1, parameterName.length) === end
|
|
1607
|
+
// <- TODO: More universal that 1 character
|
|
1608
|
+
) {
|
|
1609
|
+
parameterName = parameterName.substring(1, parameterName.length - 1);
|
|
1746
1610
|
// <- TODO: More universal that 1 character
|
|
1747
|
-
) {
|
|
1748
|
-
parameterName = parameterName.substring(1, parameterName.length - 1);
|
|
1749
|
-
// <- TODO: More universal that 1 character
|
|
1750
|
-
}
|
|
1751
1611
|
}
|
|
1752
1612
|
}
|
|
1753
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
1754
|
-
finally {
|
|
1755
|
-
try {
|
|
1756
|
-
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
1757
|
-
}
|
|
1758
|
-
finally { if (e_1) throw e_1.error; }
|
|
1759
|
-
}
|
|
1760
1613
|
// TODO: [🐠] Following try-catch block should be part of common validators logic
|
|
1761
1614
|
try {
|
|
1762
1615
|
/*
|
|
@@ -1766,10 +1619,10 @@ function validateParameterName(parameterName) {
|
|
|
1766
1619
|
}
|
|
1767
1620
|
*/
|
|
1768
1621
|
if (parameterName.includes('.')) {
|
|
1769
|
-
throw new ParseError(
|
|
1622
|
+
throw new ParseError(`Parameter name cannot contain dots`);
|
|
1770
1623
|
}
|
|
1771
1624
|
if (parameterName.includes('/') || parameterName.includes('\\')) {
|
|
1772
|
-
throw new ParseError(
|
|
1625
|
+
throw new ParseError(`Parameter name cannot contain slashes`);
|
|
1773
1626
|
}
|
|
1774
1627
|
if (parameterName.includes('(') ||
|
|
1775
1628
|
parameterName.includes(')') ||
|
|
@@ -1777,24 +1630,29 @@ function validateParameterName(parameterName) {
|
|
|
1777
1630
|
parameterName.includes('}') ||
|
|
1778
1631
|
parameterName.includes('[') ||
|
|
1779
1632
|
parameterName.includes(']')) {
|
|
1780
|
-
throw new ParseError(
|
|
1633
|
+
throw new ParseError(`Parameter name cannot contain braces`);
|
|
1781
1634
|
}
|
|
1782
1635
|
parameterName = removeDiacritics(parameterName);
|
|
1783
1636
|
parameterName = removeEmojis(parameterName);
|
|
1784
1637
|
parameterName = removeQuotes(parameterName);
|
|
1785
1638
|
parameterName = normalizeTo_camelCase(parameterName);
|
|
1786
1639
|
if (parameterName === '') {
|
|
1787
|
-
throw new ParseError(
|
|
1640
|
+
throw new ParseError(`Parameter name cannot be empty`);
|
|
1788
1641
|
}
|
|
1789
1642
|
if (RESERVED_PARAMETER_NAMES.includes(parameterName)) {
|
|
1790
|
-
throw new ParseError(
|
|
1643
|
+
throw new ParseError(`{${parameterName}} is a reserved parameter name`);
|
|
1791
1644
|
}
|
|
1792
1645
|
}
|
|
1793
1646
|
catch (error) {
|
|
1794
1647
|
if (!(error instanceof ParseError)) {
|
|
1795
1648
|
throw error;
|
|
1796
1649
|
}
|
|
1797
|
-
throw new ParseError(spaceTrim(
|
|
1650
|
+
throw new ParseError(spaceTrim((block) => `
|
|
1651
|
+
${block(error.message)}
|
|
1652
|
+
|
|
1653
|
+
Tried to validate parameter name:
|
|
1654
|
+
${block(rawParameterName)}
|
|
1655
|
+
`));
|
|
1798
1656
|
}
|
|
1799
1657
|
return parameterName;
|
|
1800
1658
|
}
|
|
@@ -1807,7 +1665,7 @@ function validateParameterName(parameterName) {
|
|
|
1807
1665
|
* @see `documentationUrl` for more details
|
|
1808
1666
|
* @public exported from `@promptbook/editable`
|
|
1809
1667
|
*/
|
|
1810
|
-
|
|
1668
|
+
const foreachCommandParser = {
|
|
1811
1669
|
/**
|
|
1812
1670
|
* Name of the command
|
|
1813
1671
|
*/
|
|
@@ -1824,7 +1682,7 @@ var foreachCommandParser = {
|
|
|
1824
1682
|
/**
|
|
1825
1683
|
* Description of the FOREACH command
|
|
1826
1684
|
*/
|
|
1827
|
-
description:
|
|
1685
|
+
description: `@@`,
|
|
1828
1686
|
/**
|
|
1829
1687
|
* Link to documentation
|
|
1830
1688
|
*/
|
|
@@ -1842,58 +1700,64 @@ var foreachCommandParser = {
|
|
|
1842
1700
|
/**
|
|
1843
1701
|
* Parses the FOREACH command
|
|
1844
1702
|
*/
|
|
1845
|
-
parse
|
|
1846
|
-
|
|
1847
|
-
|
|
1848
|
-
|
|
1849
|
-
|
|
1850
|
-
|
|
1851
|
-
|
|
1852
|
-
return __spreadArray([formatDefinition.formatName], __read((formatDefinition.aliases || [])), false).includes(formatName);
|
|
1853
|
-
});
|
|
1703
|
+
parse(input) {
|
|
1704
|
+
const { args } = input;
|
|
1705
|
+
const formatName = normalizeTo_SCREAMING_CASE(args[0] || '');
|
|
1706
|
+
const subformatName = normalizeTo_SCREAMING_CASE(args[1] || '');
|
|
1707
|
+
const parameterNameArg = args[2] || '';
|
|
1708
|
+
const assignSign = args[3];
|
|
1709
|
+
const formatDefinition = FORMAT_DEFINITIONS.find((formatDefinition) => [formatDefinition.formatName, ...(formatDefinition.aliases || [])].includes(formatName));
|
|
1854
1710
|
if (formatDefinition === undefined) {
|
|
1855
|
-
throw new ParseError(spaceTrim(
|
|
1856
|
-
|
|
1857
|
-
|
|
1711
|
+
throw new ParseError(spaceTrim((block) => `
|
|
1712
|
+
Unsupported format "${formatName}"
|
|
1713
|
+
|
|
1714
|
+
Available formats:
|
|
1715
|
+
${block(FORMAT_DEFINITIONS.map((formatDefinition) => formatDefinition.formatName)
|
|
1716
|
+
.map((formatName) => `- ${formatName}`)
|
|
1717
|
+
.join('\n'))}
|
|
1718
|
+
`));
|
|
1858
1719
|
// <- TODO: [🏢] List all supported format names
|
|
1859
1720
|
}
|
|
1860
|
-
|
|
1861
|
-
return __spreadArray([subvalueDefinition.subvalueName], __read((subvalueDefinition.aliases || [])), false).includes(subformatName);
|
|
1862
|
-
});
|
|
1721
|
+
const subvalueDefinition = formatDefinition.subvalueDefinitions.find((subvalueDefinition) => [subvalueDefinition.subvalueName, ...(subvalueDefinition.aliases || [])].includes(subformatName));
|
|
1863
1722
|
if (subvalueDefinition === undefined) {
|
|
1864
|
-
throw new ParseError(spaceTrim(
|
|
1865
|
-
|
|
1866
|
-
|
|
1867
|
-
|
|
1723
|
+
throw new ParseError(spaceTrim((block) => `
|
|
1724
|
+
Unsupported subformat name "${subformatName}" for format "${formatName}"
|
|
1725
|
+
|
|
1726
|
+
Available subformat names for format "${formatDefinition.formatName}":
|
|
1727
|
+
${block(formatDefinition.subvalueDefinitions
|
|
1728
|
+
.map((subvalueDefinition) => subvalueDefinition.subvalueName)
|
|
1729
|
+
.map((subvalueName) => `- ${subvalueName}`)
|
|
1730
|
+
.join('\n'))}
|
|
1731
|
+
`));
|
|
1868
1732
|
// <- TODO: [🏢] List all supported subformat names for the format
|
|
1869
1733
|
}
|
|
1870
1734
|
if (assignSign !== '->') {
|
|
1871
|
-
throw new ParseError(
|
|
1735
|
+
throw new ParseError(`FOREACH command must have '->' to assign the value to the parameter`);
|
|
1872
1736
|
}
|
|
1873
|
-
|
|
1874
|
-
|
|
1737
|
+
const parameterName = validateParameterName(parameterNameArg);
|
|
1738
|
+
let outputSubparameterName = null;
|
|
1875
1739
|
// TODO: [4] DRY
|
|
1876
|
-
|
|
1740
|
+
const inputSubparameterNames = args
|
|
1877
1741
|
.slice(4)
|
|
1878
|
-
.map(
|
|
1879
|
-
.filter(
|
|
1880
|
-
.filter(
|
|
1742
|
+
.map((parameterName) => parameterName.split(',').join(' ').trim())
|
|
1743
|
+
.filter((parameterName) => !parameterName.includes('+'))
|
|
1744
|
+
.filter((parameterName) => parameterName !== '')
|
|
1881
1745
|
.map(validateParameterName);
|
|
1882
1746
|
// TODO: [4] DRY
|
|
1883
|
-
|
|
1747
|
+
const outputSubparameterNames = args
|
|
1884
1748
|
.slice(4)
|
|
1885
|
-
.map(
|
|
1886
|
-
.filter(
|
|
1887
|
-
.map(
|
|
1749
|
+
.map((parameterName) => parameterName.split(',').join(' ').trim())
|
|
1750
|
+
.filter((parameterName) => parameterName.includes('+'))
|
|
1751
|
+
.map((parameterName) => parameterName.split('+').join(''))
|
|
1888
1752
|
.map(validateParameterName);
|
|
1889
1753
|
if (outputSubparameterNames.length === 1) {
|
|
1890
1754
|
outputSubparameterName = outputSubparameterNames[0];
|
|
1891
1755
|
}
|
|
1892
1756
|
else if (outputSubparameterNames.length > 1) {
|
|
1893
|
-
throw new ParseError(
|
|
1757
|
+
throw new ParseError(`FOREACH command can not have more than one output subparameter`);
|
|
1894
1758
|
}
|
|
1895
1759
|
if (inputSubparameterNames.length === 0) {
|
|
1896
|
-
throw new ParseError(
|
|
1760
|
+
throw new ParseError(`FOREACH command must have at least one input subparameter`);
|
|
1897
1761
|
}
|
|
1898
1762
|
if (outputSubparameterName === null) {
|
|
1899
1763
|
// TODO: Following code should be unhardcoded from here and moved to the format definition
|
|
@@ -1904,16 +1768,22 @@ var foreachCommandParser = {
|
|
|
1904
1768
|
outputSubparameterName = 'newLine';
|
|
1905
1769
|
}
|
|
1906
1770
|
else {
|
|
1907
|
-
throw new ParseError(spaceTrim(
|
|
1771
|
+
throw new ParseError(spaceTrim(`
|
|
1772
|
+
FOREACH ${formatName} ${subformatName} must specify output subparameter
|
|
1773
|
+
|
|
1774
|
+
Correct example:
|
|
1775
|
+
- FOREACH ${formatName} ${subformatName} {${parameterName}} -> {inputSubparameterName1}, {inputSubparameterName2}, +{outputSubparameterName}
|
|
1776
|
+
|
|
1777
|
+
`));
|
|
1908
1778
|
}
|
|
1909
1779
|
}
|
|
1910
1780
|
return {
|
|
1911
1781
|
type: 'FOREACH',
|
|
1912
|
-
formatName
|
|
1913
|
-
subformatName
|
|
1914
|
-
parameterName
|
|
1915
|
-
inputSubparameterNames
|
|
1916
|
-
outputSubparameterName
|
|
1782
|
+
formatName,
|
|
1783
|
+
subformatName,
|
|
1784
|
+
parameterName,
|
|
1785
|
+
inputSubparameterNames,
|
|
1786
|
+
outputSubparameterName,
|
|
1917
1787
|
};
|
|
1918
1788
|
},
|
|
1919
1789
|
/**
|
|
@@ -1921,16 +1791,16 @@ var foreachCommandParser = {
|
|
|
1921
1791
|
*
|
|
1922
1792
|
* Note: `$` is used to indicate that this function mutates given `taskJson`
|
|
1923
1793
|
*/
|
|
1924
|
-
$applyToTaskJson
|
|
1925
|
-
|
|
1794
|
+
$applyToTaskJson(command, $taskJson, $pipelineJson) {
|
|
1795
|
+
const { formatName, subformatName, parameterName, inputSubparameterNames, outputSubparameterName } = command;
|
|
1926
1796
|
// TODO: [🍭] Detect double use
|
|
1927
1797
|
// TODO: [🍭] Detect usage with JOKER and don't allow it
|
|
1928
1798
|
$taskJson.foreach = {
|
|
1929
|
-
formatName
|
|
1930
|
-
subformatName
|
|
1931
|
-
parameterName
|
|
1932
|
-
inputSubparameterNames
|
|
1933
|
-
outputSubparameterName
|
|
1799
|
+
formatName,
|
|
1800
|
+
subformatName,
|
|
1801
|
+
parameterName,
|
|
1802
|
+
inputSubparameterNames,
|
|
1803
|
+
outputSubparameterName,
|
|
1934
1804
|
};
|
|
1935
1805
|
// Note: [🍭] FOREACH apply has some sideeffects on different places in codebase
|
|
1936
1806
|
},
|
|
@@ -1939,16 +1809,16 @@ var foreachCommandParser = {
|
|
|
1939
1809
|
*
|
|
1940
1810
|
* Note: This is used in `pipelineJsonToString` utility
|
|
1941
1811
|
*/
|
|
1942
|
-
stringify
|
|
1943
|
-
return
|
|
1812
|
+
stringify(command) {
|
|
1813
|
+
return `---`; // <- TODO: [🛋] Implement
|
|
1944
1814
|
},
|
|
1945
1815
|
/**
|
|
1946
1816
|
* Reads the FOREACH command from the `TaskJson`
|
|
1947
1817
|
*
|
|
1948
1818
|
* Note: This is used in `pipelineJsonToString` utility
|
|
1949
1819
|
*/
|
|
1950
|
-
takeFromTaskJson
|
|
1951
|
-
throw new NotYetImplementedError(
|
|
1820
|
+
takeFromTaskJson($taskJson) {
|
|
1821
|
+
throw new NotYetImplementedError(`[🛋] Not implemented yet`); // <- TODO: [🛋] Implement
|
|
1952
1822
|
},
|
|
1953
1823
|
};
|
|
1954
1824
|
/**
|
|
@@ -1961,7 +1831,7 @@ var foreachCommandParser = {
|
|
|
1961
1831
|
* @see `documentationUrl` for more details
|
|
1962
1832
|
* @public exported from `@promptbook/editable`
|
|
1963
1833
|
*/
|
|
1964
|
-
|
|
1834
|
+
const formatCommandParser = {
|
|
1965
1835
|
/**
|
|
1966
1836
|
* Name of the command
|
|
1967
1837
|
*/
|
|
@@ -1974,7 +1844,10 @@ var formatCommandParser = {
|
|
|
1974
1844
|
/**
|
|
1975
1845
|
* Description of the FORMAT command
|
|
1976
1846
|
*/
|
|
1977
|
-
description: spaceTrim(
|
|
1847
|
+
description: spaceTrim(`
|
|
1848
|
+
Format command describes the desired output of the task (after post-processing)
|
|
1849
|
+
It can set limits for the maximum/minimum length of the output, measured in characters, words, sentences, paragraphs or some other shape of the output.
|
|
1850
|
+
`),
|
|
1978
1851
|
/**
|
|
1979
1852
|
* Link to documentation
|
|
1980
1853
|
*/
|
|
@@ -1986,10 +1859,10 @@ var formatCommandParser = {
|
|
|
1986
1859
|
/**
|
|
1987
1860
|
* Parses the FORMAT command
|
|
1988
1861
|
*/
|
|
1989
|
-
parse
|
|
1990
|
-
|
|
1862
|
+
parse(input) {
|
|
1863
|
+
const { normalized } = input;
|
|
1991
1864
|
if (!normalized.startsWith('FORMAT_JSON')) {
|
|
1992
|
-
throw new ParseError(
|
|
1865
|
+
throw new ParseError(`For now only JSON format is supported, in future we will support more formats`);
|
|
1993
1866
|
}
|
|
1994
1867
|
return {
|
|
1995
1868
|
type: 'FORMAT',
|
|
@@ -2003,9 +1876,10 @@ var formatCommandParser = {
|
|
|
2003
1876
|
*
|
|
2004
1877
|
* Note: `$` is used to indicate that this function mutates given `taskJson`
|
|
2005
1878
|
*/
|
|
2006
|
-
$applyToTaskJson
|
|
1879
|
+
$applyToTaskJson(command, $taskJson) {
|
|
2007
1880
|
if ($taskJson.format !== undefined && command.format !== $taskJson.format) {
|
|
2008
|
-
throw new ParseError(
|
|
1881
|
+
throw new ParseError(`Format format is already defined to "${$taskJson.format}".
|
|
1882
|
+
Now you try to redefine it by "${command.format}"`);
|
|
2009
1883
|
}
|
|
2010
1884
|
$taskJson.format = command.format;
|
|
2011
1885
|
},
|
|
@@ -2014,16 +1888,16 @@ var formatCommandParser = {
|
|
|
2014
1888
|
*
|
|
2015
1889
|
* Note: This is used in `pipelineJsonToString` utility
|
|
2016
1890
|
*/
|
|
2017
|
-
stringify
|
|
2018
|
-
return
|
|
1891
|
+
stringify(command) {
|
|
1892
|
+
return `---`; // <- TODO: [🛋] Implement
|
|
2019
1893
|
},
|
|
2020
1894
|
/**
|
|
2021
1895
|
* Reads the FORMAT command from the `TaskJson`
|
|
2022
1896
|
*
|
|
2023
1897
|
* Note: This is used in `pipelineJsonToString` utility
|
|
2024
1898
|
*/
|
|
2025
|
-
takeFromTaskJson
|
|
2026
|
-
throw new NotYetImplementedError(
|
|
1899
|
+
takeFromTaskJson($taskJson) {
|
|
1900
|
+
throw new NotYetImplementedError(`[🛋] Not implemented yet`); // <- TODO: [🛋] Implement
|
|
2027
1901
|
},
|
|
2028
1902
|
};
|
|
2029
1903
|
|
|
@@ -2032,31 +1906,31 @@ var formatCommandParser = {
|
|
|
2032
1906
|
*
|
|
2033
1907
|
* @public exported from `@promptbook/core`
|
|
2034
1908
|
*/
|
|
2035
|
-
|
|
1909
|
+
const ChatbotFormfactorDefinition = {
|
|
2036
1910
|
name: 'CHATBOT',
|
|
2037
1911
|
aliasNames: ['CHAT'],
|
|
2038
|
-
description:
|
|
2039
|
-
documentationUrl:
|
|
1912
|
+
description: `@@@`,
|
|
1913
|
+
documentationUrl: `https://github.com/webgptorg/promptbook/discussions/174`,
|
|
2040
1914
|
pipelineInterface: {
|
|
2041
1915
|
inputParameters: [
|
|
2042
1916
|
{
|
|
2043
1917
|
name: 'previousTitle',
|
|
2044
|
-
description:
|
|
1918
|
+
description: `Previous title of the conversation`,
|
|
2045
1919
|
isInput: true,
|
|
2046
1920
|
isOutput: false,
|
|
2047
1921
|
},
|
|
2048
1922
|
{
|
|
2049
1923
|
name: 'previousConversationSummary',
|
|
2050
|
-
description:
|
|
1924
|
+
description: `Previous conversation summary`,
|
|
2051
1925
|
isInput: true,
|
|
2052
1926
|
isOutput: false,
|
|
2053
1927
|
},
|
|
2054
|
-
{ name: 'userMessage', description:
|
|
1928
|
+
{ name: 'userMessage', description: `User message`, isInput: true, isOutput: false },
|
|
2055
1929
|
],
|
|
2056
1930
|
outputParameters: [
|
|
2057
|
-
{ name: 'title', description:
|
|
2058
|
-
{ name: 'conversationSummary', description:
|
|
2059
|
-
{ name: 'chatbotResponse', description:
|
|
1931
|
+
{ name: 'title', description: `Title of the conversation`, isInput: false, isOutput: true },
|
|
1932
|
+
{ name: 'conversationSummary', description: `Summary of the conversation`, isInput: false, isOutput: true },
|
|
1933
|
+
{ name: 'chatbotResponse', description: `Chatbot response`, isInput: false, isOutput: true },
|
|
2060
1934
|
],
|
|
2061
1935
|
},
|
|
2062
1936
|
};
|
|
@@ -2066,15 +1940,15 @@ var ChatbotFormfactorDefinition = {
|
|
|
2066
1940
|
*
|
|
2067
1941
|
* @public exported from `@promptbook/core`
|
|
2068
1942
|
*/
|
|
2069
|
-
|
|
1943
|
+
const GeneratorFormfactorDefinition = {
|
|
2070
1944
|
name: 'GENERATOR',
|
|
2071
|
-
description:
|
|
2072
|
-
documentationUrl:
|
|
1945
|
+
description: `Generates any kind (in HTML with possible scripts and css format) of content from input message`,
|
|
1946
|
+
documentationUrl: `https://github.com/webgptorg/promptbook/discussions/184`,
|
|
2073
1947
|
pipelineInterface: {
|
|
2074
1948
|
inputParameters: [
|
|
2075
1949
|
{
|
|
2076
1950
|
name: 'inputMessage',
|
|
2077
|
-
description:
|
|
1951
|
+
description: `Input message to be image made from`,
|
|
2078
1952
|
isInput: true,
|
|
2079
1953
|
isOutput: false,
|
|
2080
1954
|
},
|
|
@@ -2082,7 +1956,7 @@ var GeneratorFormfactorDefinition = {
|
|
|
2082
1956
|
outputParameters: [
|
|
2083
1957
|
{
|
|
2084
1958
|
name: 'result',
|
|
2085
|
-
description:
|
|
1959
|
+
description: `Result in HTML to be shown to user`,
|
|
2086
1960
|
isInput: false,
|
|
2087
1961
|
isOutput: true,
|
|
2088
1962
|
},
|
|
@@ -2097,7 +1971,7 @@ var GeneratorFormfactorDefinition = {
|
|
|
2097
1971
|
*
|
|
2098
1972
|
* @public exported from `@promptbook/core`
|
|
2099
1973
|
*/
|
|
2100
|
-
|
|
1974
|
+
const GENERIC_PIPELINE_INTERFACE = {
|
|
2101
1975
|
inputParameters: [],
|
|
2102
1976
|
outputParameters: [],
|
|
2103
1977
|
};
|
|
@@ -2110,10 +1984,10 @@ var GENERIC_PIPELINE_INTERFACE = {
|
|
|
2110
1984
|
*
|
|
2111
1985
|
* @public exported from `@promptbook/core`
|
|
2112
1986
|
*/
|
|
2113
|
-
|
|
1987
|
+
const GenericFormfactorDefinition = {
|
|
2114
1988
|
name: 'GENERIC',
|
|
2115
|
-
description:
|
|
2116
|
-
documentationUrl:
|
|
1989
|
+
description: `@@@`,
|
|
1990
|
+
documentationUrl: `https://github.com/webgptorg/promptbook/discussions/173`,
|
|
2117
1991
|
pipelineInterface: GENERIC_PIPELINE_INTERFACE,
|
|
2118
1992
|
};
|
|
2119
1993
|
|
|
@@ -2122,15 +1996,15 @@ var GenericFormfactorDefinition = {
|
|
|
2122
1996
|
*
|
|
2123
1997
|
* @public exported from `@promptbook/core`
|
|
2124
1998
|
*/
|
|
2125
|
-
|
|
1999
|
+
const ImageGeneratorFormfactorDefinition = {
|
|
2126
2000
|
name: 'IMAGE_GENERATOR',
|
|
2127
|
-
description:
|
|
2128
|
-
documentationUrl:
|
|
2001
|
+
description: `Generates prompt for image generation from input message`,
|
|
2002
|
+
documentationUrl: `https://github.com/webgptorg/promptbook/discussions/184`,
|
|
2129
2003
|
pipelineInterface: {
|
|
2130
2004
|
inputParameters: [
|
|
2131
2005
|
{
|
|
2132
2006
|
name: 'inputMessage',
|
|
2133
|
-
description:
|
|
2007
|
+
description: `Input message to be image made from`,
|
|
2134
2008
|
isInput: true,
|
|
2135
2009
|
isOutput: false,
|
|
2136
2010
|
},
|
|
@@ -2138,7 +2012,7 @@ var ImageGeneratorFormfactorDefinition = {
|
|
|
2138
2012
|
outputParameters: [
|
|
2139
2013
|
{
|
|
2140
2014
|
name: 'prompt',
|
|
2141
|
-
description:
|
|
2015
|
+
description: `Prompt to be used for image generation`,
|
|
2142
2016
|
isInput: false,
|
|
2143
2017
|
isOutput: true,
|
|
2144
2018
|
},
|
|
@@ -2151,10 +2025,10 @@ var ImageGeneratorFormfactorDefinition = {
|
|
|
2151
2025
|
*
|
|
2152
2026
|
* @public exported from `@promptbook/core`
|
|
2153
2027
|
*/
|
|
2154
|
-
|
|
2028
|
+
const MatcherFormfactorDefinition = {
|
|
2155
2029
|
name: 'EXPERIMENTAL_MATCHER',
|
|
2156
|
-
description:
|
|
2157
|
-
documentationUrl:
|
|
2030
|
+
description: `@@@`,
|
|
2031
|
+
documentationUrl: `https://github.com/webgptorg/promptbook/discussions/177`,
|
|
2158
2032
|
pipelineInterface: {
|
|
2159
2033
|
inputParameters: [
|
|
2160
2034
|
/* @@@ */
|
|
@@ -2176,16 +2050,16 @@ var MatcherFormfactorDefinition = {
|
|
|
2176
2050
|
*
|
|
2177
2051
|
* @public exported from `@promptbook/core`
|
|
2178
2052
|
*/
|
|
2179
|
-
|
|
2053
|
+
const SheetsFormfactorDefinition = {
|
|
2180
2054
|
name: 'SHEETS',
|
|
2181
2055
|
aliasNames: ['SHEETS', 'SHEET'],
|
|
2182
|
-
description:
|
|
2183
|
-
documentationUrl:
|
|
2056
|
+
description: `@@@`,
|
|
2057
|
+
documentationUrl: `https://github.com/webgptorg/promptbook/discussions/176`,
|
|
2184
2058
|
pipelineInterface: {
|
|
2185
2059
|
inputParameters: [
|
|
2186
2060
|
{
|
|
2187
2061
|
name: 'inputSheet',
|
|
2188
|
-
description:
|
|
2062
|
+
description: `Input sheet to be processed as csv`,
|
|
2189
2063
|
isInput: true,
|
|
2190
2064
|
isOutput: false,
|
|
2191
2065
|
},
|
|
@@ -2193,7 +2067,7 @@ var SheetsFormfactorDefinition = {
|
|
|
2193
2067
|
outputParameters: [
|
|
2194
2068
|
{
|
|
2195
2069
|
name: 'outputSheet',
|
|
2196
|
-
description:
|
|
2070
|
+
description: `Output sheet as csv`,
|
|
2197
2071
|
isInput: false,
|
|
2198
2072
|
isOutput: true,
|
|
2199
2073
|
},
|
|
@@ -2206,15 +2080,15 @@ var SheetsFormfactorDefinition = {
|
|
|
2206
2080
|
*
|
|
2207
2081
|
* @public exported from `@promptbook/core`
|
|
2208
2082
|
*/
|
|
2209
|
-
|
|
2083
|
+
const TranslatorFormfactorDefinition = {
|
|
2210
2084
|
name: 'TRANSLATOR',
|
|
2211
|
-
description:
|
|
2212
|
-
documentationUrl:
|
|
2085
|
+
description: `@@@`,
|
|
2086
|
+
documentationUrl: `https://github.com/webgptorg/promptbook/discussions/175`,
|
|
2213
2087
|
pipelineInterface: {
|
|
2214
2088
|
inputParameters: [
|
|
2215
2089
|
{
|
|
2216
2090
|
name: 'inputMessage',
|
|
2217
|
-
description:
|
|
2091
|
+
description: `Input message to be translated`,
|
|
2218
2092
|
isInput: true,
|
|
2219
2093
|
isOutput: false,
|
|
2220
2094
|
},
|
|
@@ -2222,7 +2096,7 @@ var TranslatorFormfactorDefinition = {
|
|
|
2222
2096
|
outputParameters: [
|
|
2223
2097
|
{
|
|
2224
2098
|
name: 'outputMessage',
|
|
2225
|
-
description:
|
|
2099
|
+
description: `Translated output message`,
|
|
2226
2100
|
isInput: false,
|
|
2227
2101
|
isOutput: true,
|
|
2228
2102
|
},
|
|
@@ -2237,7 +2111,7 @@ var TranslatorFormfactorDefinition = {
|
|
|
2237
2111
|
*
|
|
2238
2112
|
* @public exported from `@promptbook/core`
|
|
2239
2113
|
*/
|
|
2240
|
-
|
|
2114
|
+
const FORMFACTOR_DEFINITIONS = [
|
|
2241
2115
|
GenericFormfactorDefinition,
|
|
2242
2116
|
ChatbotFormfactorDefinition,
|
|
2243
2117
|
TranslatorFormfactorDefinition,
|
|
@@ -2258,7 +2132,7 @@ var FORMFACTOR_DEFINITIONS = [
|
|
|
2258
2132
|
* @see `documentationUrl` for more details
|
|
2259
2133
|
* @public exported from `@promptbook/editable`
|
|
2260
2134
|
*/
|
|
2261
|
-
|
|
2135
|
+
const formfactorCommandParser = {
|
|
2262
2136
|
/**
|
|
2263
2137
|
* Name of the command
|
|
2264
2138
|
*/
|
|
@@ -2275,7 +2149,7 @@ var formfactorCommandParser = {
|
|
|
2275
2149
|
/**
|
|
2276
2150
|
* Description of the FORMFACTOR command
|
|
2277
2151
|
*/
|
|
2278
|
-
description:
|
|
2152
|
+
description: `@@`,
|
|
2279
2153
|
/**
|
|
2280
2154
|
* Link to documentation
|
|
2281
2155
|
*/
|
|
@@ -2287,20 +2161,20 @@ var formfactorCommandParser = {
|
|
|
2287
2161
|
/**
|
|
2288
2162
|
* Parses the FORMFACTOR command
|
|
2289
2163
|
*/
|
|
2290
|
-
parse
|
|
2291
|
-
|
|
2164
|
+
parse(input) {
|
|
2165
|
+
const { args } = input;
|
|
2292
2166
|
if (args.length !== 1) {
|
|
2293
|
-
throw new ParseError(
|
|
2167
|
+
throw new ParseError(`FORMFACTOR command requires exactly one argument`);
|
|
2294
2168
|
}
|
|
2295
|
-
|
|
2296
|
-
|
|
2297
|
-
return __spreadArray([definition.name], __read(__assign({ aliasNames: [] }, definition).aliasNames), false).includes(formfactorNameCandidate);
|
|
2298
|
-
});
|
|
2169
|
+
const formfactorNameCandidate = args[0].toUpperCase();
|
|
2170
|
+
const formfactor = FORMFACTOR_DEFINITIONS.find((definition) => [definition.name, ...{ aliasNames: [], ...definition }.aliasNames].includes(formfactorNameCandidate));
|
|
2299
2171
|
if (formfactor === undefined) {
|
|
2300
|
-
throw new ParseError(spaceTrim(
|
|
2301
|
-
|
|
2302
|
-
|
|
2303
|
-
|
|
2172
|
+
throw new ParseError(spaceTrim((block) => `
|
|
2173
|
+
Unknown formfactor name "${formfactorNameCandidate}"
|
|
2174
|
+
|
|
2175
|
+
Available formfactors:
|
|
2176
|
+
${block(FORMFACTOR_DEFINITIONS.map(({ name }) => `- ${name}`).join('\n'))}
|
|
2177
|
+
`));
|
|
2304
2178
|
}
|
|
2305
2179
|
return {
|
|
2306
2180
|
type: 'FORMFACTOR',
|
|
@@ -2312,9 +2186,15 @@ var formfactorCommandParser = {
|
|
|
2312
2186
|
*
|
|
2313
2187
|
* Note: `$` is used to indicate that this function mutates given `pipelineJson`
|
|
2314
2188
|
*/
|
|
2315
|
-
$applyToPipelineJson
|
|
2189
|
+
$applyToPipelineJson(command, $pipelineJson) {
|
|
2316
2190
|
if ($pipelineJson.formfactorName !== undefined && $pipelineJson.formfactorName !== command.formfactorName) {
|
|
2317
|
-
throw new ParseError(spaceTrim(
|
|
2191
|
+
throw new ParseError(spaceTrim(`
|
|
2192
|
+
Redefinition of \`FORMFACTOR\` in the pipeline head
|
|
2193
|
+
|
|
2194
|
+
You have used:
|
|
2195
|
+
1) FORMFACTOR \`${$pipelineJson.formfactorName}\`
|
|
2196
|
+
2) FORMFACTOR \`${command.formfactorName}\`
|
|
2197
|
+
`));
|
|
2318
2198
|
}
|
|
2319
2199
|
$pipelineJson.formfactorName = command.formfactorName;
|
|
2320
2200
|
},
|
|
@@ -2323,15 +2203,15 @@ var formfactorCommandParser = {
|
|
|
2323
2203
|
*
|
|
2324
2204
|
* Note: This is used in `pipelineJsonToString` utility
|
|
2325
2205
|
*/
|
|
2326
|
-
stringify
|
|
2327
|
-
return
|
|
2206
|
+
stringify(command) {
|
|
2207
|
+
return `FORMFACTOR ${command.formfactorName}`;
|
|
2328
2208
|
},
|
|
2329
2209
|
/**
|
|
2330
2210
|
* Reads the FORMFACTOR command from the `PipelineJson`
|
|
2331
2211
|
*
|
|
2332
2212
|
* Note: This is used in `pipelineJsonToString` utility
|
|
2333
2213
|
*/
|
|
2334
|
-
takeFromPipelineJson
|
|
2214
|
+
takeFromPipelineJson(pipelineJson) {
|
|
2335
2215
|
return [
|
|
2336
2216
|
{
|
|
2337
2217
|
type: 'FORMFACTOR',
|
|
@@ -2347,7 +2227,7 @@ var formfactorCommandParser = {
|
|
|
2347
2227
|
* @see `documentationUrl` for more details
|
|
2348
2228
|
* @public exported from `@promptbook/editable`
|
|
2349
2229
|
*/
|
|
2350
|
-
|
|
2230
|
+
const jokerCommandParser = {
|
|
2351
2231
|
/**
|
|
2352
2232
|
* Name of the command
|
|
2353
2233
|
*/
|
|
@@ -2360,7 +2240,7 @@ var jokerCommandParser = {
|
|
|
2360
2240
|
/**
|
|
2361
2241
|
* Description of the JOKER command
|
|
2362
2242
|
*/
|
|
2363
|
-
description:
|
|
2243
|
+
description: `Joker parameter is used instead of executing the task result if jokers value meets the expectations requirements`,
|
|
2364
2244
|
/**
|
|
2365
2245
|
* Link to documentation
|
|
2366
2246
|
*/
|
|
@@ -2372,16 +2252,16 @@ var jokerCommandParser = {
|
|
|
2372
2252
|
/**
|
|
2373
2253
|
* Parses the JOKER command
|
|
2374
2254
|
*/
|
|
2375
|
-
parse
|
|
2376
|
-
|
|
2255
|
+
parse(input) {
|
|
2256
|
+
const { args } = input;
|
|
2377
2257
|
if (args.length !== 1) {
|
|
2378
|
-
throw new ParseError(
|
|
2258
|
+
throw new ParseError(`JOKE command expects exactly one parameter name`);
|
|
2379
2259
|
}
|
|
2380
|
-
|
|
2381
|
-
|
|
2260
|
+
const parameterNameArg = args[0] || '';
|
|
2261
|
+
const parameterName = validateParameterName(parameterNameArg);
|
|
2382
2262
|
return {
|
|
2383
2263
|
type: 'JOKER',
|
|
2384
|
-
parameterName
|
|
2264
|
+
parameterName,
|
|
2385
2265
|
};
|
|
2386
2266
|
},
|
|
2387
2267
|
/**
|
|
@@ -2389,7 +2269,7 @@ var jokerCommandParser = {
|
|
|
2389
2269
|
*
|
|
2390
2270
|
* Note: `$` is used to indicate that this function mutates given `taskJson`
|
|
2391
2271
|
*/
|
|
2392
|
-
$applyToTaskJson
|
|
2272
|
+
$applyToTaskJson(command, $taskJson) {
|
|
2393
2273
|
$taskJson.jokerParameterNames = $taskJson.jokerParameterNames || [];
|
|
2394
2274
|
$taskJson.jokerParameterNames.push(command.parameterName);
|
|
2395
2275
|
},
|
|
@@ -2398,16 +2278,16 @@ var jokerCommandParser = {
|
|
|
2398
2278
|
*
|
|
2399
2279
|
* Note: This is used in `pipelineJsonToString` utility
|
|
2400
2280
|
*/
|
|
2401
|
-
stringify
|
|
2402
|
-
return
|
|
2281
|
+
stringify(command) {
|
|
2282
|
+
return `---`; // <- TODO: [🛋] Implement
|
|
2403
2283
|
},
|
|
2404
2284
|
/**
|
|
2405
2285
|
* Reads the JOKER command from the `TaskJson`
|
|
2406
2286
|
*
|
|
2407
2287
|
* Note: This is used in `pipelineJsonToString` utility
|
|
2408
2288
|
*/
|
|
2409
|
-
takeFromTaskJson
|
|
2410
|
-
throw new NotYetImplementedError(
|
|
2289
|
+
takeFromTaskJson($taskJson) {
|
|
2290
|
+
throw new NotYetImplementedError(`[🛋] Not implemented yet`); // <- TODO: [🛋] Implement
|
|
2411
2291
|
},
|
|
2412
2292
|
};
|
|
2413
2293
|
|
|
@@ -2428,7 +2308,7 @@ function isValidFilePath(filename) {
|
|
|
2428
2308
|
5 /* <- TODO: [🧠][🈷] Make some better non-arbitrary way how to distinct filenames from informational texts */) {
|
|
2429
2309
|
return false;
|
|
2430
2310
|
}
|
|
2431
|
-
|
|
2311
|
+
const filenameSlashes = filename.split('\\').join('/');
|
|
2432
2312
|
// Absolute Unix path: /hello.txt
|
|
2433
2313
|
if (/^(\/)/i.test(filenameSlashes)) {
|
|
2434
2314
|
// console.log(filename, 'Absolute Unix path: /hello.txt');
|
|
@@ -2478,7 +2358,7 @@ function isValidUrl(url) {
|
|
|
2478
2358
|
if (url.startsWith('blob:')) {
|
|
2479
2359
|
url = url.replace(/^blob:/, '');
|
|
2480
2360
|
}
|
|
2481
|
-
|
|
2361
|
+
const urlObject = new URL(url /* because fail is handled */);
|
|
2482
2362
|
if (!['http:', 'https:', 'data:'].includes(urlObject.protocol)) {
|
|
2483
2363
|
return false;
|
|
2484
2364
|
}
|
|
@@ -2499,47 +2379,36 @@ function isValidUrl(url) {
|
|
|
2499
2379
|
* @public exported from `@promptbook/utils`
|
|
2500
2380
|
*/
|
|
2501
2381
|
function normalizeToKebabCase(text) {
|
|
2502
|
-
var e_1, _a;
|
|
2503
2382
|
text = removeDiacritics(text);
|
|
2504
|
-
|
|
2505
|
-
|
|
2506
|
-
|
|
2507
|
-
|
|
2508
|
-
|
|
2509
|
-
|
|
2510
|
-
|
|
2511
|
-
|
|
2512
|
-
charType = 'LOWERCASE';
|
|
2513
|
-
normalizedChar = char;
|
|
2514
|
-
}
|
|
2515
|
-
else if (/^[A-Z]$/.test(char)) {
|
|
2516
|
-
charType = 'UPPERCASE';
|
|
2517
|
-
normalizedChar = char.toLowerCase();
|
|
2518
|
-
}
|
|
2519
|
-
else if (/^[0-9]$/.test(char)) {
|
|
2520
|
-
charType = 'NUMBER';
|
|
2521
|
-
normalizedChar = char;
|
|
2522
|
-
}
|
|
2523
|
-
else {
|
|
2524
|
-
charType = 'OTHER';
|
|
2525
|
-
normalizedChar = '-';
|
|
2526
|
-
}
|
|
2527
|
-
if (charType !== lastCharType &&
|
|
2528
|
-
!(lastCharType === 'UPPERCASE' && charType === 'LOWERCASE') &&
|
|
2529
|
-
!(lastCharType === 'NUMBER') &&
|
|
2530
|
-
!(charType === 'NUMBER')) {
|
|
2531
|
-
normalizedName += '-';
|
|
2532
|
-
}
|
|
2533
|
-
normalizedName += normalizedChar;
|
|
2534
|
-
lastCharType = charType;
|
|
2383
|
+
let charType;
|
|
2384
|
+
let lastCharType = 'OTHER';
|
|
2385
|
+
let normalizedName = '';
|
|
2386
|
+
for (const char of text) {
|
|
2387
|
+
let normalizedChar;
|
|
2388
|
+
if (/^[a-z]$/.test(char)) {
|
|
2389
|
+
charType = 'LOWERCASE';
|
|
2390
|
+
normalizedChar = char;
|
|
2535
2391
|
}
|
|
2536
|
-
|
|
2537
|
-
|
|
2538
|
-
|
|
2539
|
-
|
|
2540
|
-
|
|
2392
|
+
else if (/^[A-Z]$/.test(char)) {
|
|
2393
|
+
charType = 'UPPERCASE';
|
|
2394
|
+
normalizedChar = char.toLowerCase();
|
|
2395
|
+
}
|
|
2396
|
+
else if (/^[0-9]$/.test(char)) {
|
|
2397
|
+
charType = 'NUMBER';
|
|
2398
|
+
normalizedChar = char;
|
|
2541
2399
|
}
|
|
2542
|
-
|
|
2400
|
+
else {
|
|
2401
|
+
charType = 'OTHER';
|
|
2402
|
+
normalizedChar = '-';
|
|
2403
|
+
}
|
|
2404
|
+
if (charType !== lastCharType &&
|
|
2405
|
+
!(lastCharType === 'UPPERCASE' && charType === 'LOWERCASE') &&
|
|
2406
|
+
!(lastCharType === 'NUMBER') &&
|
|
2407
|
+
!(charType === 'NUMBER')) {
|
|
2408
|
+
normalizedName += '-';
|
|
2409
|
+
}
|
|
2410
|
+
normalizedName += normalizedChar;
|
|
2411
|
+
lastCharType = charType;
|
|
2543
2412
|
}
|
|
2544
2413
|
normalizedName = normalizedName.split(/-+/g).join('-');
|
|
2545
2414
|
normalizedName = normalizedName.split(/-?\/-?/g).join('/');
|
|
@@ -2557,14 +2426,14 @@ function normalizeToKebabCase(text) {
|
|
|
2557
2426
|
* @public exported from `@promptbook/editable`
|
|
2558
2427
|
*/
|
|
2559
2428
|
function knowledgeSourceContentToName(knowledgeSourceContent) {
|
|
2560
|
-
|
|
2429
|
+
const hash = SHA256(hexEncoder.parse(JSON.stringify(knowledgeSourceContent)))
|
|
2561
2430
|
// <- TODO: [🥬] Encapsulate sha256 to some private utility function
|
|
2562
2431
|
.toString( /* hex */)
|
|
2563
2432
|
.substring(0, 20);
|
|
2564
2433
|
// <- TODO: [🥬] Make some system for hashes and ids of promptbook
|
|
2565
|
-
|
|
2566
|
-
|
|
2567
|
-
|
|
2434
|
+
const semanticName = normalizeToKebabCase(knowledgeSourceContent.substring(0, 20));
|
|
2435
|
+
const pieces = ['source', semanticName, hash].filter((piece) => piece !== '');
|
|
2436
|
+
const name = pieces.join('-').split('--').join('-');
|
|
2568
2437
|
// <- TODO: Use MAX_FILENAME_LENGTH
|
|
2569
2438
|
return name;
|
|
2570
2439
|
}
|
|
@@ -2578,7 +2447,7 @@ function knowledgeSourceContentToName(knowledgeSourceContent) {
|
|
|
2578
2447
|
* @see `documentationUrl` for more details
|
|
2579
2448
|
* @public exported from `@promptbook/editable`
|
|
2580
2449
|
*/
|
|
2581
|
-
|
|
2450
|
+
const knowledgeCommandParser = {
|
|
2582
2451
|
/**
|
|
2583
2452
|
* Name of the command
|
|
2584
2453
|
*/
|
|
@@ -2591,7 +2460,7 @@ var knowledgeCommandParser = {
|
|
|
2591
2460
|
/**
|
|
2592
2461
|
* Description of the KNOWLEDGE command
|
|
2593
2462
|
*/
|
|
2594
|
-
description:
|
|
2463
|
+
description: `Tells promptbook which external knowledge to use`,
|
|
2595
2464
|
/**
|
|
2596
2465
|
* Link to documentation
|
|
2597
2466
|
*/
|
|
@@ -2610,27 +2479,27 @@ var knowledgeCommandParser = {
|
|
|
2610
2479
|
/**
|
|
2611
2480
|
* Parses the KNOWLEDGE command
|
|
2612
2481
|
*/
|
|
2613
|
-
parse
|
|
2614
|
-
|
|
2615
|
-
|
|
2482
|
+
parse(input) {
|
|
2483
|
+
const { args } = input;
|
|
2484
|
+
const knowledgeSourceContent = spaceTrim(args[0] || '');
|
|
2616
2485
|
if (knowledgeSourceContent === '') {
|
|
2617
|
-
throw new ParseError(
|
|
2486
|
+
throw new ParseError(`Source is not defined`);
|
|
2618
2487
|
}
|
|
2619
2488
|
// TODO: [main] !!4 Following checks should be applied every link in the `sourceContent`
|
|
2620
2489
|
if (knowledgeSourceContent.startsWith('http://')) {
|
|
2621
|
-
throw new ParseError(
|
|
2490
|
+
throw new ParseError(`Source is not secure`);
|
|
2622
2491
|
}
|
|
2623
2492
|
if (!(isValidFilePath(knowledgeSourceContent) || isValidUrl(knowledgeSourceContent))) {
|
|
2624
|
-
throw new ParseError(
|
|
2493
|
+
throw new ParseError(`Source not valid`);
|
|
2625
2494
|
}
|
|
2626
2495
|
if (knowledgeSourceContent.startsWith('../') ||
|
|
2627
2496
|
knowledgeSourceContent.startsWith('/') ||
|
|
2628
2497
|
/^[A-Z]:[\\/]+/i.test(knowledgeSourceContent)) {
|
|
2629
|
-
throw new ParseError(
|
|
2498
|
+
throw new ParseError(`Source cannot be outside of the .book.md folder`);
|
|
2630
2499
|
}
|
|
2631
2500
|
return {
|
|
2632
2501
|
type: 'KNOWLEDGE',
|
|
2633
|
-
knowledgeSourceContent
|
|
2502
|
+
knowledgeSourceContent,
|
|
2634
2503
|
};
|
|
2635
2504
|
},
|
|
2636
2505
|
/**
|
|
@@ -2638,11 +2507,11 @@ var knowledgeCommandParser = {
|
|
|
2638
2507
|
*
|
|
2639
2508
|
* Note: `$` is used to indicate that this function mutates given `pipelineJson`
|
|
2640
2509
|
*/
|
|
2641
|
-
$applyToPipelineJson
|
|
2642
|
-
|
|
2510
|
+
$applyToPipelineJson(command, $pipelineJson) {
|
|
2511
|
+
const { knowledgeSourceContent } = command;
|
|
2643
2512
|
$pipelineJson.knowledgeSources.push({
|
|
2644
2513
|
name: knowledgeSourceContentToName(knowledgeSourceContent),
|
|
2645
|
-
knowledgeSourceContent
|
|
2514
|
+
knowledgeSourceContent,
|
|
2646
2515
|
});
|
|
2647
2516
|
},
|
|
2648
2517
|
/**
|
|
@@ -2650,16 +2519,16 @@ var knowledgeCommandParser = {
|
|
|
2650
2519
|
*
|
|
2651
2520
|
* Note: This is used in `pipelineJsonToString` utility
|
|
2652
2521
|
*/
|
|
2653
|
-
stringify
|
|
2654
|
-
return
|
|
2522
|
+
stringify(command) {
|
|
2523
|
+
return `---`; // <- TODO: [🛋] Implement
|
|
2655
2524
|
},
|
|
2656
2525
|
/**
|
|
2657
2526
|
* Reads the KNOWLEDGE command from the `PipelineJson`
|
|
2658
2527
|
*
|
|
2659
2528
|
* Note: This is used in `pipelineJsonToString` utility
|
|
2660
2529
|
*/
|
|
2661
|
-
takeFromPipelineJson
|
|
2662
|
-
throw new NotYetImplementedError(
|
|
2530
|
+
takeFromPipelineJson(pipelineJson) {
|
|
2531
|
+
throw new NotYetImplementedError(`[🛋] Not implemented yet`); // <- TODO: [🛋] Implement
|
|
2663
2532
|
},
|
|
2664
2533
|
};
|
|
2665
2534
|
/**
|
|
@@ -2671,7 +2540,7 @@ var knowledgeCommandParser = {
|
|
|
2671
2540
|
*
|
|
2672
2541
|
* @public exported from `@promptbook/core`
|
|
2673
2542
|
*/
|
|
2674
|
-
|
|
2543
|
+
const MODEL_VARIANTS = ['COMPLETION', 'CHAT', 'EMBEDDING' /* <- TODO [🏳] */ /* <- [🤖] */];
|
|
2675
2544
|
|
|
2676
2545
|
/**
|
|
2677
2546
|
* Parses the model command
|
|
@@ -2680,7 +2549,7 @@ var MODEL_VARIANTS = ['COMPLETION', 'CHAT', 'EMBEDDING' /* <- TODO [🏳] */ /*
|
|
|
2680
2549
|
* @deprecated Option to manually set the model requirements is not recommended to use, use `PERSONA` instead
|
|
2681
2550
|
* @public exported from `@promptbook/editable`
|
|
2682
2551
|
*/
|
|
2683
|
-
|
|
2552
|
+
const modelCommandParser = {
|
|
2684
2553
|
/**
|
|
2685
2554
|
* Name of the command
|
|
2686
2555
|
*/
|
|
@@ -2693,7 +2562,7 @@ var modelCommandParser = {
|
|
|
2693
2562
|
/**
|
|
2694
2563
|
* Description of the MODEL command
|
|
2695
2564
|
*/
|
|
2696
|
-
description:
|
|
2565
|
+
description: `Tells which \`modelRequirements\` (for example which model) to use for the prompt task execution`,
|
|
2697
2566
|
/**
|
|
2698
2567
|
* Link to documentation
|
|
2699
2568
|
*/
|
|
@@ -2705,11 +2574,12 @@ var modelCommandParser = {
|
|
|
2705
2574
|
/**
|
|
2706
2575
|
* Parses the MODEL command
|
|
2707
2576
|
*/
|
|
2708
|
-
parse
|
|
2709
|
-
|
|
2710
|
-
|
|
2711
|
-
|
|
2712
|
-
|
|
2577
|
+
parse(input) {
|
|
2578
|
+
const { args, normalized } = input;
|
|
2579
|
+
const availableVariantsMessage = spaceTrim((block) => `
|
|
2580
|
+
Available variants are:
|
|
2581
|
+
${block(MODEL_VARIANTS.map((variantName) => `- ${variantName}${variantName !== 'EMBEDDING' ? '' : ' (Not available in pipeline)'}`).join('\n'))}
|
|
2582
|
+
`);
|
|
2713
2583
|
// TODO: Make this more elegant and dynamically
|
|
2714
2584
|
if (normalized.startsWith('MODEL_VARIANT')) {
|
|
2715
2585
|
if (normalized === 'MODEL_VARIANT_CHAT') {
|
|
@@ -2728,10 +2598,18 @@ var modelCommandParser = {
|
|
|
2728
2598
|
// <- Note: [🤖]
|
|
2729
2599
|
}
|
|
2730
2600
|
else if (normalized.startsWith('MODEL_VARIANT_EMBED')) {
|
|
2731
|
-
spaceTrim(
|
|
2601
|
+
spaceTrim((block) => `
|
|
2602
|
+
Embedding model can not be used in pipeline
|
|
2603
|
+
|
|
2604
|
+
${block(availableVariantsMessage)}
|
|
2605
|
+
`);
|
|
2732
2606
|
}
|
|
2733
2607
|
else {
|
|
2734
|
-
throw new ParseError(spaceTrim(
|
|
2608
|
+
throw new ParseError(spaceTrim((block) => `
|
|
2609
|
+
Unknown model variant in command:
|
|
2610
|
+
|
|
2611
|
+
${block(availableVariantsMessage)}
|
|
2612
|
+
`));
|
|
2735
2613
|
}
|
|
2736
2614
|
}
|
|
2737
2615
|
if (normalized.startsWith('MODEL_NAME')) {
|
|
@@ -2742,7 +2620,16 @@ var modelCommandParser = {
|
|
|
2742
2620
|
};
|
|
2743
2621
|
}
|
|
2744
2622
|
else {
|
|
2745
|
-
throw new ParseError(spaceTrim(
|
|
2623
|
+
throw new ParseError(spaceTrim((block) => `
|
|
2624
|
+
Unknown model key in command.
|
|
2625
|
+
|
|
2626
|
+
Supported model keys are:
|
|
2627
|
+
${block(['variant', 'name'].join(', '))}
|
|
2628
|
+
|
|
2629
|
+
Example:
|
|
2630
|
+
- MODEL VARIANT Chat
|
|
2631
|
+
- MODEL NAME gpt-4
|
|
2632
|
+
`));
|
|
2746
2633
|
}
|
|
2747
2634
|
},
|
|
2748
2635
|
/**
|
|
@@ -2750,16 +2637,22 @@ var modelCommandParser = {
|
|
|
2750
2637
|
*
|
|
2751
2638
|
* Note: `$` is used to indicate that this function mutates given `pipelineJson`
|
|
2752
2639
|
*/
|
|
2753
|
-
$applyToPipelineJson
|
|
2640
|
+
$applyToPipelineJson(command, $pipelineJson) {
|
|
2754
2641
|
$pipelineJson.defaultModelRequirements = $pipelineJson.defaultModelRequirements || {};
|
|
2755
2642
|
// TODO: [🚜] DRY
|
|
2756
2643
|
if ($pipelineJson.defaultModelRequirements[command.key] !== undefined) {
|
|
2757
2644
|
if ($pipelineJson.defaultModelRequirements[command.key] === command.value) {
|
|
2758
|
-
console.warn(
|
|
2645
|
+
console.warn(`Multiple commands \`MODEL ${command.key} ${command.value}\` in the pipeline head`);
|
|
2759
2646
|
// <- TODO: [🚎][💩] Some better way how to get warnings from pipeline parsing / logic
|
|
2760
2647
|
}
|
|
2761
2648
|
else {
|
|
2762
|
-
throw new ParseError(spaceTrim(
|
|
2649
|
+
throw new ParseError(spaceTrim(`
|
|
2650
|
+
Redefinition of \`MODEL ${command.key}\` in the pipeline head
|
|
2651
|
+
|
|
2652
|
+
You have used:
|
|
2653
|
+
1) \`MODEL ${command.key} ${$pipelineJson.defaultModelRequirements[command.key]}\`
|
|
2654
|
+
2) \`MODEL ${command.key} ${command.value}\`
|
|
2655
|
+
`));
|
|
2763
2656
|
}
|
|
2764
2657
|
}
|
|
2765
2658
|
$pipelineJson.defaultModelRequirements[command.key] = command.value;
|
|
@@ -2769,26 +2662,40 @@ var modelCommandParser = {
|
|
|
2769
2662
|
*
|
|
2770
2663
|
* Note: `$` is used to indicate that this function mutates given `taskJson`
|
|
2771
2664
|
*/
|
|
2772
|
-
$applyToTaskJson
|
|
2665
|
+
$applyToTaskJson(command, $taskJson, $pipelineJson) {
|
|
2773
2666
|
if ($taskJson.taskType !== 'PROMPT_TASK') {
|
|
2774
|
-
throw new ParseError(
|
|
2667
|
+
throw new ParseError(`MODEL command can only be used in PROMPT_TASK block`);
|
|
2775
2668
|
}
|
|
2776
2669
|
$taskJson.modelRequirements = $taskJson.modelRequirements || {};
|
|
2777
2670
|
// TODO: [🚜] DRY
|
|
2778
2671
|
if ($taskJson.modelRequirements[command.key] !== undefined) {
|
|
2779
2672
|
if ($taskJson.modelRequirements[command.key] === command.value) {
|
|
2780
|
-
console.warn(
|
|
2673
|
+
console.warn(`Multiple commands \`MODEL ${{
|
|
2781
2674
|
modelName: 'NAME',
|
|
2782
2675
|
modelVariant: 'VARIANT',
|
|
2783
2676
|
maxTokens: '???',
|
|
2784
|
-
}[command.key]
|
|
2677
|
+
}[command.key]} ${command.value}\` in the task "${$taskJson.title || $taskJson.name}"`);
|
|
2785
2678
|
}
|
|
2786
2679
|
else {
|
|
2787
|
-
throw new ParseError(spaceTrim(
|
|
2680
|
+
throw new ParseError(spaceTrim(`
|
|
2681
|
+
Redefinition of MODEL \`${command.key}\` in the task "${$taskJson.title || $taskJson.name}"
|
|
2682
|
+
|
|
2683
|
+
You have used:
|
|
2684
|
+
- MODEL ${command.key} ${$taskJson.modelRequirements[command.key]}
|
|
2685
|
+
- MODEL ${command.key} ${command.value}
|
|
2686
|
+
`));
|
|
2788
2687
|
}
|
|
2789
2688
|
}
|
|
2790
2689
|
if (command.value === ($pipelineJson.defaultModelRequirements || {})[command.key]) {
|
|
2791
|
-
console.log(spaceTrim(
|
|
2690
|
+
console.log(spaceTrim(`
|
|
2691
|
+
Setting MODEL \`${command.key}\` in the task "${$taskJson.title || $taskJson.name}" to the same value as in the pipeline head
|
|
2692
|
+
|
|
2693
|
+
In pipeline head:
|
|
2694
|
+
- MODEL ${command.key} ${($pipelineJson.defaultModelRequirements || {})[command.key]}
|
|
2695
|
+
|
|
2696
|
+
But same value is used in the task:
|
|
2697
|
+
- MODEL ${command.key} ${command.value}
|
|
2698
|
+
`));
|
|
2792
2699
|
}
|
|
2793
2700
|
$taskJson.modelRequirements[command.key] = command.value;
|
|
2794
2701
|
},
|
|
@@ -2797,24 +2704,24 @@ var modelCommandParser = {
|
|
|
2797
2704
|
*
|
|
2798
2705
|
* Note: This is used in `pipelineJsonToString` utility
|
|
2799
2706
|
*/
|
|
2800
|
-
stringify
|
|
2801
|
-
return
|
|
2707
|
+
stringify(command) {
|
|
2708
|
+
return `---`; // <- TODO: [🛋] Implement
|
|
2802
2709
|
},
|
|
2803
2710
|
/**
|
|
2804
2711
|
* Reads the MODEL command from the `PipelineJson`
|
|
2805
2712
|
*
|
|
2806
2713
|
* Note: This is used in `pipelineJsonToString` utility
|
|
2807
2714
|
*/
|
|
2808
|
-
takeFromPipelineJson
|
|
2809
|
-
throw new NotYetImplementedError(
|
|
2715
|
+
takeFromPipelineJson(pipelineJson) {
|
|
2716
|
+
throw new NotYetImplementedError(`[🛋] Not implemented yet`); // <- TODO: [🛋] Implement
|
|
2810
2717
|
},
|
|
2811
2718
|
/**
|
|
2812
2719
|
* Reads the MODEL command from the `TaskJson`
|
|
2813
2720
|
*
|
|
2814
2721
|
* Note: This is used in `pipelineJsonToString` utility
|
|
2815
2722
|
*/
|
|
2816
|
-
takeFromTaskJson
|
|
2817
|
-
throw new NotYetImplementedError(
|
|
2723
|
+
takeFromTaskJson($taskJson) {
|
|
2724
|
+
throw new NotYetImplementedError(`[🛋] Not implemented yet`); // <- TODO: [🛋] Implement
|
|
2818
2725
|
},
|
|
2819
2726
|
};
|
|
2820
2727
|
|
|
@@ -2824,7 +2731,7 @@ var modelCommandParser = {
|
|
|
2824
2731
|
* @see `documentationUrl` for more details
|
|
2825
2732
|
* @public exported from `@promptbook/editable`
|
|
2826
2733
|
*/
|
|
2827
|
-
|
|
2734
|
+
const parameterCommandParser = {
|
|
2828
2735
|
/**
|
|
2829
2736
|
* Name of the command
|
|
2830
2737
|
*/
|
|
@@ -2844,7 +2751,7 @@ var parameterCommandParser = {
|
|
|
2844
2751
|
/**
|
|
2845
2752
|
* Description of the PARAMETER command
|
|
2846
2753
|
*/
|
|
2847
|
-
description:
|
|
2754
|
+
description: `Describes one parameter of the task`,
|
|
2848
2755
|
/**
|
|
2849
2756
|
* Link to documentation
|
|
2850
2757
|
*/
|
|
@@ -2856,29 +2763,34 @@ var parameterCommandParser = {
|
|
|
2856
2763
|
/**
|
|
2857
2764
|
* Parses the PARAMETER command
|
|
2858
2765
|
*/
|
|
2859
|
-
parse
|
|
2860
|
-
|
|
2861
|
-
|
|
2862
|
-
|
|
2766
|
+
parse(input) {
|
|
2767
|
+
const { normalized, args, raw } = input;
|
|
2768
|
+
const parameterNameRaw = args.shift() || '';
|
|
2769
|
+
const parameterDescriptionRaw = args.join(' ');
|
|
2863
2770
|
// <- TODO: When [🥶] fixed, change to:
|
|
2864
2771
|
// > const parameterDescriptionRaw = rawArgs.split(parameterNameRaw).join('').trim();
|
|
2865
2772
|
if (parameterDescriptionRaw && parameterDescriptionRaw.match(/\{(?<embeddedParameterName>[a-z0-9_]+)\}/im)) {
|
|
2866
|
-
throw new ParseError(spaceTrim(
|
|
2773
|
+
throw new ParseError(spaceTrim((block) => `
|
|
2774
|
+
Parameter \`{${parameterNameRaw}}\` can not contain another parameter in description
|
|
2775
|
+
|
|
2776
|
+
The description:
|
|
2777
|
+
${block(parameterDescriptionRaw)}
|
|
2778
|
+
`));
|
|
2867
2779
|
}
|
|
2868
|
-
|
|
2869
|
-
|
|
2780
|
+
let isInput = normalized.startsWith('INPUT');
|
|
2781
|
+
let isOutput = normalized.startsWith('OUTPUT');
|
|
2870
2782
|
if (raw.startsWith('> {')) {
|
|
2871
2783
|
isInput = false;
|
|
2872
2784
|
isOutput = false;
|
|
2873
2785
|
}
|
|
2874
|
-
|
|
2875
|
-
|
|
2786
|
+
const parameterName = validateParameterName(parameterNameRaw);
|
|
2787
|
+
const parameterDescription = parameterDescriptionRaw.trim() || null;
|
|
2876
2788
|
return {
|
|
2877
2789
|
type: 'PARAMETER',
|
|
2878
|
-
parameterName
|
|
2879
|
-
parameterDescription
|
|
2880
|
-
isInput
|
|
2881
|
-
isOutput
|
|
2790
|
+
parameterName,
|
|
2791
|
+
parameterDescription,
|
|
2792
|
+
isInput,
|
|
2793
|
+
isOutput,
|
|
2882
2794
|
};
|
|
2883
2795
|
},
|
|
2884
2796
|
/**
|
|
@@ -2886,7 +2798,7 @@ var parameterCommandParser = {
|
|
|
2886
2798
|
*
|
|
2887
2799
|
* Note: `$` is used to indicate that this function mutates given `pipelineJson`
|
|
2888
2800
|
*/
|
|
2889
|
-
$applyToPipelineJson
|
|
2801
|
+
$applyToPipelineJson(command, $pipelineJson) {
|
|
2890
2802
|
// Note: [🍣] Do nothing, its application is implemented separately in `parsePipeline`
|
|
2891
2803
|
},
|
|
2892
2804
|
/**
|
|
@@ -2894,7 +2806,7 @@ var parameterCommandParser = {
|
|
|
2894
2806
|
*
|
|
2895
2807
|
* Note: `$` is used to indicate that this function mutates given `taskJson`
|
|
2896
2808
|
*/
|
|
2897
|
-
$applyToTaskJson
|
|
2809
|
+
$applyToTaskJson(command, $taskJson, $pipelineJson) {
|
|
2898
2810
|
// Note: [🍣] Do nothing, its application is implemented separately in `parsePipeline`
|
|
2899
2811
|
},
|
|
2900
2812
|
/**
|
|
@@ -2902,24 +2814,24 @@ var parameterCommandParser = {
|
|
|
2902
2814
|
*
|
|
2903
2815
|
* Note: This is used in `pipelineJsonToString` utility
|
|
2904
2816
|
*/
|
|
2905
|
-
stringify
|
|
2906
|
-
return
|
|
2817
|
+
stringify(command) {
|
|
2818
|
+
return `---`; // <- TODO: [🛋] Implement
|
|
2907
2819
|
},
|
|
2908
2820
|
/**
|
|
2909
2821
|
* Reads the PARAMETER command from the `PipelineJson`
|
|
2910
2822
|
*
|
|
2911
2823
|
* Note: This is used in `pipelineJsonToString` utility
|
|
2912
2824
|
*/
|
|
2913
|
-
takeFromPipelineJson
|
|
2914
|
-
throw new NotYetImplementedError(
|
|
2825
|
+
takeFromPipelineJson(pipelineJson) {
|
|
2826
|
+
throw new NotYetImplementedError(`[🛋] Not implemented yet`); // <- TODO: [🛋] Implement
|
|
2915
2827
|
},
|
|
2916
2828
|
/**
|
|
2917
2829
|
* Reads the PARAMETER command from the `TaskJson`
|
|
2918
2830
|
*
|
|
2919
2831
|
* Note: This is used in `pipelineJsonToString` utility
|
|
2920
2832
|
*/
|
|
2921
|
-
takeFromTaskJson
|
|
2922
|
-
throw new NotYetImplementedError(
|
|
2833
|
+
takeFromTaskJson($taskJson) {
|
|
2834
|
+
throw new NotYetImplementedError(`[🛋] Not implemented yet`); // <- TODO: [🛋] Implement
|
|
2923
2835
|
},
|
|
2924
2836
|
};
|
|
2925
2837
|
|
|
@@ -2929,7 +2841,7 @@ var parameterCommandParser = {
|
|
|
2929
2841
|
* @see `documentationUrl` for more details
|
|
2930
2842
|
* @public exported from `@promptbook/editable`
|
|
2931
2843
|
*/
|
|
2932
|
-
|
|
2844
|
+
const personaCommandParser = {
|
|
2933
2845
|
/**
|
|
2934
2846
|
* Name of the command
|
|
2935
2847
|
*/
|
|
@@ -2946,7 +2858,7 @@ var personaCommandParser = {
|
|
|
2946
2858
|
/**
|
|
2947
2859
|
* Description of the PERSONA command
|
|
2948
2860
|
*/
|
|
2949
|
-
description:
|
|
2861
|
+
description: `Persona command is used to specify who the system is, it will be transformed into system message, top_t,...`,
|
|
2950
2862
|
/**
|
|
2951
2863
|
* Link to documentation
|
|
2952
2864
|
*/
|
|
@@ -2958,21 +2870,21 @@ var personaCommandParser = {
|
|
|
2958
2870
|
/**
|
|
2959
2871
|
* Parses the PERSONA command
|
|
2960
2872
|
*/
|
|
2961
|
-
parse
|
|
2962
|
-
|
|
2963
|
-
|
|
2964
|
-
|
|
2873
|
+
parse(input) {
|
|
2874
|
+
const { rawArgs } = input;
|
|
2875
|
+
const [personaNameRaw, personaDescriptionRaw] = rawArgs.split(/[,;:]/, 2);
|
|
2876
|
+
const personaName = (personaNameRaw || '').trim();
|
|
2965
2877
|
if (personaName === '') {
|
|
2966
|
-
throw new ParseError(
|
|
2878
|
+
throw new ParseError(`You must set name for the persona`);
|
|
2967
2879
|
}
|
|
2968
|
-
|
|
2880
|
+
let personaDescription = (personaDescriptionRaw || '').trim();
|
|
2969
2881
|
if (personaDescription === '') {
|
|
2970
2882
|
personaDescription = null;
|
|
2971
2883
|
}
|
|
2972
2884
|
return {
|
|
2973
2885
|
type: 'PERSONA',
|
|
2974
|
-
personaName
|
|
2975
|
-
personaDescription
|
|
2886
|
+
personaName,
|
|
2887
|
+
personaDescription,
|
|
2976
2888
|
};
|
|
2977
2889
|
},
|
|
2978
2890
|
/**
|
|
@@ -2980,33 +2892,33 @@ var personaCommandParser = {
|
|
|
2980
2892
|
*
|
|
2981
2893
|
* Note: `$` is used to indicate that this function mutates given `pipelineJson`
|
|
2982
2894
|
*/
|
|
2983
|
-
$applyToPipelineJson
|
|
2895
|
+
$applyToPipelineJson(command, $pipelineJson) {
|
|
2984
2896
|
$applyToTaskJson(command, null, $pipelineJson);
|
|
2985
2897
|
},
|
|
2986
|
-
$applyToTaskJson
|
|
2898
|
+
$applyToTaskJson,
|
|
2987
2899
|
/**
|
|
2988
2900
|
* Converts the PERSONA command back to string
|
|
2989
2901
|
*
|
|
2990
2902
|
* Note: This is used in `pipelineJsonToString` utility
|
|
2991
2903
|
*/
|
|
2992
|
-
stringify
|
|
2993
|
-
return
|
|
2904
|
+
stringify(command) {
|
|
2905
|
+
return `---`; // <- TODO: [🛋] Implement
|
|
2994
2906
|
},
|
|
2995
2907
|
/**
|
|
2996
2908
|
* Reads the PERSONA command from the `PipelineJson`
|
|
2997
2909
|
*
|
|
2998
2910
|
* Note: This is used in `pipelineJsonToString` utility
|
|
2999
2911
|
*/
|
|
3000
|
-
takeFromPipelineJson
|
|
3001
|
-
throw new NotYetImplementedError(
|
|
2912
|
+
takeFromPipelineJson(pipelineJson) {
|
|
2913
|
+
throw new NotYetImplementedError(`[🛋] Not implemented yet`); // <- TODO: [🛋] Implement
|
|
3002
2914
|
},
|
|
3003
2915
|
/**
|
|
3004
2916
|
* Reads the PERSONA command from the `TaskJson`
|
|
3005
2917
|
*
|
|
3006
2918
|
* Note: This is used in `pipelineJsonToString` utility
|
|
3007
2919
|
*/
|
|
3008
|
-
takeFromTaskJson
|
|
3009
|
-
throw new NotYetImplementedError(
|
|
2920
|
+
takeFromTaskJson($taskJson) {
|
|
2921
|
+
throw new NotYetImplementedError(`[🛋] Not implemented yet`); // <- TODO: [🛋] Implement
|
|
3010
2922
|
},
|
|
3011
2923
|
};
|
|
3012
2924
|
/**
|
|
@@ -3015,14 +2927,14 @@ var personaCommandParser = {
|
|
|
3015
2927
|
* Note: `$` is used to indicate that this function mutates given `taskJson`
|
|
3016
2928
|
*/
|
|
3017
2929
|
function $applyToTaskJson(command, $taskJson, $pipelineJson) {
|
|
3018
|
-
|
|
2930
|
+
const { personaName, personaDescription } = command;
|
|
3019
2931
|
if ($taskJson !== null) {
|
|
3020
2932
|
if ($taskJson.taskType !== 'PROMPT_TASK') {
|
|
3021
|
-
throw new ParseError(
|
|
2933
|
+
throw new ParseError(`PERSONA command can be used only in PROMPT_TASK block`);
|
|
3022
2934
|
}
|
|
3023
2935
|
$taskJson.personaName = personaName;
|
|
3024
2936
|
}
|
|
3025
|
-
|
|
2937
|
+
const persona = $pipelineJson.personas.find((persona) => persona.name === personaName);
|
|
3026
2938
|
if (persona === undefined) {
|
|
3027
2939
|
$pipelineJson.personas.push({
|
|
3028
2940
|
name: personaName,
|
|
@@ -3040,7 +2952,17 @@ function $applyToTaskJson(command, $taskJson, $pipelineJson) {
|
|
|
3040
2952
|
persona.description = personaDescription;
|
|
3041
2953
|
return;
|
|
3042
2954
|
}
|
|
3043
|
-
console.warn(spaceTrim(
|
|
2955
|
+
console.warn(spaceTrim(`
|
|
2956
|
+
|
|
2957
|
+
Persona "${personaName}" is defined multiple times with different description:
|
|
2958
|
+
|
|
2959
|
+
First definition:
|
|
2960
|
+
${persona.description}
|
|
2961
|
+
|
|
2962
|
+
Second definition:
|
|
2963
|
+
${personaDescription}
|
|
2964
|
+
|
|
2965
|
+
`));
|
|
3044
2966
|
persona.description += spaceTrim('\n\n' + personaDescription);
|
|
3045
2967
|
}
|
|
3046
2968
|
|
|
@@ -3064,7 +2986,7 @@ function isValidJavascriptName(javascriptName) {
|
|
|
3064
2986
|
* @see `documentationUrl` for more details
|
|
3065
2987
|
* @public exported from `@promptbook/editable`
|
|
3066
2988
|
*/
|
|
3067
|
-
|
|
2989
|
+
const postprocessCommandParser = {
|
|
3068
2990
|
/**
|
|
3069
2991
|
* Name of the command
|
|
3070
2992
|
*/
|
|
@@ -3078,7 +3000,7 @@ var postprocessCommandParser = {
|
|
|
3078
3000
|
/**
|
|
3079
3001
|
* Description of the POSTPROCESS command
|
|
3080
3002
|
*/
|
|
3081
|
-
description:
|
|
3003
|
+
description: `Defines the postprocess function to be used on the result from LLM and before the result is validated`,
|
|
3082
3004
|
/**
|
|
3083
3005
|
* Link to documentation
|
|
3084
3006
|
*/
|
|
@@ -3092,21 +3014,21 @@ var postprocessCommandParser = {
|
|
|
3092
3014
|
/**
|
|
3093
3015
|
* Parses the POSTPROCESS command
|
|
3094
3016
|
*/
|
|
3095
|
-
parse
|
|
3096
|
-
|
|
3097
|
-
|
|
3017
|
+
parse(input) {
|
|
3018
|
+
const { args } = input;
|
|
3019
|
+
const functionName = args.pop();
|
|
3098
3020
|
if (functionName === undefined) {
|
|
3099
|
-
throw new ParseError(
|
|
3021
|
+
throw new ParseError(`Postprocess function name is required`);
|
|
3100
3022
|
}
|
|
3101
3023
|
if (!isValidJavascriptName(functionName)) {
|
|
3102
|
-
throw new ParseError(
|
|
3024
|
+
throw new ParseError(`Invalid postprocess function name "${functionName}"`);
|
|
3103
3025
|
}
|
|
3104
3026
|
if (args.length > 0) {
|
|
3105
|
-
throw new ParseError(
|
|
3027
|
+
throw new ParseError(`Can not have more than one postprocess function`);
|
|
3106
3028
|
}
|
|
3107
3029
|
return {
|
|
3108
3030
|
type: 'POSTPROCESS',
|
|
3109
|
-
functionName
|
|
3031
|
+
functionName,
|
|
3110
3032
|
};
|
|
3111
3033
|
},
|
|
3112
3034
|
/**
|
|
@@ -3114,7 +3036,7 @@ var postprocessCommandParser = {
|
|
|
3114
3036
|
*
|
|
3115
3037
|
* Note: `$` is used to indicate that this function mutates given `taskJson`
|
|
3116
3038
|
*/
|
|
3117
|
-
$applyToTaskJson
|
|
3039
|
+
$applyToTaskJson(command, $taskJson) {
|
|
3118
3040
|
$taskJson.postprocessingFunctionNames = $taskJson.postprocessingFunctionNames || [];
|
|
3119
3041
|
$taskJson.postprocessingFunctionNames.push(command.functionName);
|
|
3120
3042
|
},
|
|
@@ -3123,16 +3045,16 @@ var postprocessCommandParser = {
|
|
|
3123
3045
|
*
|
|
3124
3046
|
* Note: This is used in `pipelineJsonToString` utility
|
|
3125
3047
|
*/
|
|
3126
|
-
stringify
|
|
3127
|
-
return
|
|
3048
|
+
stringify(command) {
|
|
3049
|
+
return `---`; // <- TODO: [🛋] Implement
|
|
3128
3050
|
},
|
|
3129
3051
|
/**
|
|
3130
3052
|
* Reads the POSTPROCESS command from the `TaskJson`
|
|
3131
3053
|
*
|
|
3132
3054
|
* Note: This is used in `pipelineJsonToString` utility
|
|
3133
3055
|
*/
|
|
3134
|
-
takeFromTaskJson
|
|
3135
|
-
throw new NotYetImplementedError(
|
|
3056
|
+
takeFromTaskJson($taskJson) {
|
|
3057
|
+
throw new NotYetImplementedError(`[🛋] Not implemented yet`); // <- TODO: [🛋] Implement
|
|
3136
3058
|
},
|
|
3137
3059
|
};
|
|
3138
3060
|
|
|
@@ -3145,7 +3067,7 @@ var postprocessCommandParser = {
|
|
|
3145
3067
|
*
|
|
3146
3068
|
* @public exported from `@promptbook/core`
|
|
3147
3069
|
*/
|
|
3148
|
-
|
|
3070
|
+
const TaskTypes = [
|
|
3149
3071
|
'PROMPT',
|
|
3150
3072
|
'SIMPLE',
|
|
3151
3073
|
'SCRIPT',
|
|
@@ -3158,7 +3080,7 @@ var TaskTypes = [
|
|
|
3158
3080
|
*
|
|
3159
3081
|
* @public exported from `@promptbook/core`
|
|
3160
3082
|
*/
|
|
3161
|
-
|
|
3083
|
+
const NonTaskSectionTypes = ['EXAMPLE', 'KNOWLEDGE', 'INSTRUMENT', 'ACTION'];
|
|
3162
3084
|
/**
|
|
3163
3085
|
* All available section types
|
|
3164
3086
|
*
|
|
@@ -3168,7 +3090,10 @@ var NonTaskSectionTypes = ['EXAMPLE', 'KNOWLEDGE', 'INSTRUMENT', 'ACTION'];
|
|
|
3168
3090
|
*
|
|
3169
3091
|
* @public exported from `@promptbook/core`
|
|
3170
3092
|
*/
|
|
3171
|
-
|
|
3093
|
+
const SectionTypes = [
|
|
3094
|
+
...TaskTypes.map((TaskType) => `${TaskType}_TASK`),
|
|
3095
|
+
...NonTaskSectionTypes,
|
|
3096
|
+
];
|
|
3172
3097
|
|
|
3173
3098
|
/**
|
|
3174
3099
|
* Parses the section command
|
|
@@ -3176,7 +3101,7 @@ var SectionTypes = __spreadArray(__spreadArray([], __read(TaskTypes.map(function
|
|
|
3176
3101
|
* @see `documentationUrl` for more details
|
|
3177
3102
|
* @public exported from `@promptbook/editable`
|
|
3178
3103
|
*/
|
|
3179
|
-
|
|
3104
|
+
const sectionCommandParser = {
|
|
3180
3105
|
/**
|
|
3181
3106
|
* Name of the command
|
|
3182
3107
|
*/
|
|
@@ -3207,7 +3132,7 @@ var sectionCommandParser = {
|
|
|
3207
3132
|
/**
|
|
3208
3133
|
* Description of the SECTION command
|
|
3209
3134
|
*/
|
|
3210
|
-
description:
|
|
3135
|
+
description: `Defines the purpose of the markdown section - if its a task and which type or something else`,
|
|
3211
3136
|
/**
|
|
3212
3137
|
* Link to documentation
|
|
3213
3138
|
*/
|
|
@@ -3253,21 +3178,24 @@ var sectionCommandParser = {
|
|
|
3253
3178
|
/**
|
|
3254
3179
|
* Parses the SECTION command
|
|
3255
3180
|
*/
|
|
3256
|
-
parse
|
|
3257
|
-
|
|
3181
|
+
parse(input) {
|
|
3182
|
+
let { normalized } = input;
|
|
3258
3183
|
normalized = normalized.split('SAMPLE').join('EXAMPLE');
|
|
3259
3184
|
normalized = normalized.split('EXECUTE_').join('');
|
|
3260
3185
|
normalized = normalized.split('DIALOGUE').join('DIALOG');
|
|
3261
|
-
|
|
3262
|
-
return normalized.includes(sectionType.split('_TASK').join(''));
|
|
3263
|
-
});
|
|
3186
|
+
const taskTypes = SectionTypes.filter((sectionType) => normalized.includes(sectionType.split('_TASK').join('')));
|
|
3264
3187
|
if (taskTypes.length !== 1) {
|
|
3265
|
-
throw new ParseError(spaceTrim(
|
|
3188
|
+
throw new ParseError(spaceTrim((block) => `
|
|
3189
|
+
Unknown section type "${normalized}"
|
|
3190
|
+
|
|
3191
|
+
Supported section types are:
|
|
3192
|
+
${block(SectionTypes.join(', '))}
|
|
3193
|
+
`));
|
|
3266
3194
|
}
|
|
3267
|
-
|
|
3195
|
+
const taskType = taskTypes[0];
|
|
3268
3196
|
return {
|
|
3269
3197
|
type: 'SECTION',
|
|
3270
|
-
taskType
|
|
3198
|
+
taskType,
|
|
3271
3199
|
};
|
|
3272
3200
|
},
|
|
3273
3201
|
/**
|
|
@@ -3275,27 +3203,30 @@ var sectionCommandParser = {
|
|
|
3275
3203
|
*
|
|
3276
3204
|
* Note: `$` is used to indicate that this function mutates given `taskJson`
|
|
3277
3205
|
*/
|
|
3278
|
-
$applyToTaskJson
|
|
3206
|
+
$applyToTaskJson(command, $taskJson, $pipelineJson) {
|
|
3279
3207
|
if ($taskJson.isSectionTypeSet === true) {
|
|
3280
|
-
throw new ParseError(spaceTrim(
|
|
3208
|
+
throw new ParseError(spaceTrim(`
|
|
3209
|
+
Section type is already defined in the section.
|
|
3210
|
+
It can be defined only once.
|
|
3211
|
+
`));
|
|
3281
3212
|
}
|
|
3282
3213
|
$taskJson.isSectionTypeSet = true;
|
|
3283
3214
|
// TODO: [🍧][💩] Rearrange better - but at bottom and unwrap from function
|
|
3284
|
-
|
|
3215
|
+
const expectResultingParameterName = () => {
|
|
3285
3216
|
if ($taskJson.resultingParameterName) {
|
|
3286
3217
|
return;
|
|
3287
3218
|
}
|
|
3288
|
-
throw new ParseError(
|
|
3219
|
+
throw new ParseError(`Task section and example section must end with return statement -> {parameterName}`);
|
|
3289
3220
|
};
|
|
3290
3221
|
if ($taskJson.content === undefined) {
|
|
3291
|
-
throw new UnexpectedError(
|
|
3222
|
+
throw new UnexpectedError(`Content is missing in the taskJson - probbably commands are applied in wrong order`);
|
|
3292
3223
|
}
|
|
3293
3224
|
if (command.taskType === 'EXAMPLE') {
|
|
3294
3225
|
expectResultingParameterName();
|
|
3295
|
-
|
|
3226
|
+
const parameter = $pipelineJson.parameters.find((param) => param.name === $taskJson.resultingParameterName);
|
|
3296
3227
|
if (parameter === undefined) {
|
|
3297
3228
|
// TODO: !!6 Change to logic error for higher level abstraction of chatbot to work
|
|
3298
|
-
throw new ParseError(
|
|
3229
|
+
throw new ParseError(`Parameter \`{${$taskJson.resultingParameterName}}\` is not defined so can not define example value of it`);
|
|
3299
3230
|
}
|
|
3300
3231
|
parameter.exampleValues = parameter.exampleValues || [];
|
|
3301
3232
|
parameter.exampleValues.push($taskJson.content);
|
|
@@ -3329,16 +3260,16 @@ var sectionCommandParser = {
|
|
|
3329
3260
|
*
|
|
3330
3261
|
* Note: This is used in `pipelineJsonToString` utility
|
|
3331
3262
|
*/
|
|
3332
|
-
stringify
|
|
3333
|
-
return
|
|
3263
|
+
stringify(command) {
|
|
3264
|
+
return `---`; // <- TODO: [🛋] Implement
|
|
3334
3265
|
},
|
|
3335
3266
|
/**
|
|
3336
3267
|
* Reads the SECTION command from the `TaskJson`
|
|
3337
3268
|
*
|
|
3338
3269
|
* Note: This is used in `pipelineJsonToString` utility
|
|
3339
3270
|
*/
|
|
3340
|
-
takeFromTaskJson
|
|
3341
|
-
throw new NotYetImplementedError(
|
|
3271
|
+
takeFromTaskJson($taskJson) {
|
|
3272
|
+
throw new NotYetImplementedError(`[🛋] Not implemented yet`); // <- TODO: [🛋] Implement
|
|
3342
3273
|
},
|
|
3343
3274
|
};
|
|
3344
3275
|
/**
|
|
@@ -3391,7 +3322,7 @@ function isValidPipelineUrl(url) {
|
|
|
3391
3322
|
* @see `documentationUrl` for more details
|
|
3392
3323
|
* @public exported from `@promptbook/editable`
|
|
3393
3324
|
*/
|
|
3394
|
-
|
|
3325
|
+
const urlCommandParser = {
|
|
3395
3326
|
/**
|
|
3396
3327
|
* Name of the command
|
|
3397
3328
|
*/
|
|
@@ -3409,7 +3340,7 @@ var urlCommandParser = {
|
|
|
3409
3340
|
/**
|
|
3410
3341
|
* Description of the URL command
|
|
3411
3342
|
*/
|
|
3412
|
-
description:
|
|
3343
|
+
description: `Declares unique URL for the pipeline`,
|
|
3413
3344
|
/**
|
|
3414
3345
|
* Link to documentation
|
|
3415
3346
|
*/
|
|
@@ -3425,18 +3356,18 @@ var urlCommandParser = {
|
|
|
3425
3356
|
/**
|
|
3426
3357
|
* Parses the URL command
|
|
3427
3358
|
*/
|
|
3428
|
-
parse
|
|
3429
|
-
|
|
3430
|
-
|
|
3359
|
+
parse(input) {
|
|
3360
|
+
const { args } = input;
|
|
3361
|
+
const pipelineUrl = args.pop();
|
|
3431
3362
|
if (pipelineUrl === undefined) {
|
|
3432
|
-
throw new ParseError(
|
|
3363
|
+
throw new ParseError(`URL is required`);
|
|
3433
3364
|
}
|
|
3434
3365
|
// TODO: [🧠][🚲] This should be maybe tested as logic not parse
|
|
3435
3366
|
if (!isValidPipelineUrl(pipelineUrl)) {
|
|
3436
|
-
throw new ParseError(
|
|
3367
|
+
throw new ParseError(`Invalid pipeline URL "${pipelineUrl}"`);
|
|
3437
3368
|
}
|
|
3438
3369
|
if (args.length > 0) {
|
|
3439
|
-
throw new ParseError(
|
|
3370
|
+
throw new ParseError(`Can not have more than one pipeline URL`);
|
|
3440
3371
|
}
|
|
3441
3372
|
/*
|
|
3442
3373
|
TODO: [🐠 Maybe more info from `isValidPipelineUrl`:
|
|
@@ -3465,7 +3396,7 @@ var urlCommandParser = {
|
|
|
3465
3396
|
*
|
|
3466
3397
|
* Note: `$` is used to indicate that this function mutates given `pipelineJson`
|
|
3467
3398
|
*/
|
|
3468
|
-
$applyToPipelineJson
|
|
3399
|
+
$applyToPipelineJson(command, $pipelineJson) {
|
|
3469
3400
|
$pipelineJson.pipelineUrl = command.pipelineUrl.href;
|
|
3470
3401
|
},
|
|
3471
3402
|
/**
|
|
@@ -3473,16 +3404,16 @@ var urlCommandParser = {
|
|
|
3473
3404
|
*
|
|
3474
3405
|
* Note: This is used in `pipelineJsonToString` utility
|
|
3475
3406
|
*/
|
|
3476
|
-
stringify
|
|
3477
|
-
return
|
|
3407
|
+
stringify(command) {
|
|
3408
|
+
return `---`; // <- TODO: [🛋] Implement
|
|
3478
3409
|
},
|
|
3479
3410
|
/**
|
|
3480
3411
|
* Reads the URL command from the `PipelineJson`
|
|
3481
3412
|
*
|
|
3482
3413
|
* Note: This is used in `pipelineJsonToString` utility
|
|
3483
3414
|
*/
|
|
3484
|
-
takeFromPipelineJson
|
|
3485
|
-
throw new NotYetImplementedError(
|
|
3415
|
+
takeFromPipelineJson(pipelineJson) {
|
|
3416
|
+
throw new NotYetImplementedError(`[🛋] Not implemented yet`); // <- TODO: [🛋] Implement
|
|
3486
3417
|
},
|
|
3487
3418
|
};
|
|
3488
3419
|
|
|
@@ -3492,7 +3423,7 @@ var urlCommandParser = {
|
|
|
3492
3423
|
* @see `documentationUrl` for more details
|
|
3493
3424
|
* @public exported from `@promptbook/editable`
|
|
3494
3425
|
*/
|
|
3495
|
-
|
|
3426
|
+
const actionCommandParser = {
|
|
3496
3427
|
/**
|
|
3497
3428
|
* Name of the command
|
|
3498
3429
|
*/
|
|
@@ -3505,7 +3436,7 @@ var actionCommandParser = {
|
|
|
3505
3436
|
/**
|
|
3506
3437
|
* Description of the ACTION command
|
|
3507
3438
|
*/
|
|
3508
|
-
description:
|
|
3439
|
+
description: `Actions influences from the pipeline or task into external world. Like turning on a light, sending an email, etc.`,
|
|
3509
3440
|
/**
|
|
3510
3441
|
* Link to documentation
|
|
3511
3442
|
*/
|
|
@@ -3517,8 +3448,7 @@ var actionCommandParser = {
|
|
|
3517
3448
|
/**
|
|
3518
3449
|
* Parses the ACTION command
|
|
3519
3450
|
*/
|
|
3520
|
-
parse
|
|
3521
|
-
input.args;
|
|
3451
|
+
parse(input) {
|
|
3522
3452
|
return {
|
|
3523
3453
|
type: 'ACTION',
|
|
3524
3454
|
};
|
|
@@ -3528,7 +3458,7 @@ var actionCommandParser = {
|
|
|
3528
3458
|
*
|
|
3529
3459
|
* Note: `$` is used to indicate that this function mutates given `pipelineJson`
|
|
3530
3460
|
*/
|
|
3531
|
-
$applyToPipelineJson
|
|
3461
|
+
$applyToPipelineJson(command, $pipelineJson) {
|
|
3532
3462
|
console.error(new NotYetImplementedError('[🛠] Actions are not implemented yet'));
|
|
3533
3463
|
},
|
|
3534
3464
|
/**
|
|
@@ -3536,7 +3466,7 @@ var actionCommandParser = {
|
|
|
3536
3466
|
*
|
|
3537
3467
|
* Note: This is used in `pipelineJsonToString` utility
|
|
3538
3468
|
*/
|
|
3539
|
-
stringify
|
|
3469
|
+
stringify(command) {
|
|
3540
3470
|
throw new NotYetImplementedError('[🛠] Actions are not implemented yet');
|
|
3541
3471
|
},
|
|
3542
3472
|
/**
|
|
@@ -3544,7 +3474,7 @@ var actionCommandParser = {
|
|
|
3544
3474
|
*
|
|
3545
3475
|
* Note: This is used in `pipelineJsonToString` utility
|
|
3546
3476
|
*/
|
|
3547
|
-
takeFromPipelineJson
|
|
3477
|
+
takeFromPipelineJson(pipelineJson) {
|
|
3548
3478
|
throw new NotYetImplementedError('[🛠] Actions are not implemented yet');
|
|
3549
3479
|
},
|
|
3550
3480
|
};
|
|
@@ -3558,7 +3488,7 @@ var actionCommandParser = {
|
|
|
3558
3488
|
* @see `documentationUrl` for more details
|
|
3559
3489
|
* @public exported from `@promptbook/editable`
|
|
3560
3490
|
*/
|
|
3561
|
-
|
|
3491
|
+
const instrumentCommandParser = {
|
|
3562
3492
|
/**
|
|
3563
3493
|
* Name of the command
|
|
3564
3494
|
*/
|
|
@@ -3571,7 +3501,7 @@ var instrumentCommandParser = {
|
|
|
3571
3501
|
/**
|
|
3572
3502
|
* Description of the INSTRUMENT command
|
|
3573
3503
|
*/
|
|
3574
|
-
description:
|
|
3504
|
+
description: `Instrument command is used to specify the instrument to be used in the pipeline or task like search, calculate, etc.`,
|
|
3575
3505
|
/**
|
|
3576
3506
|
* Link to documentation
|
|
3577
3507
|
*/
|
|
@@ -3583,8 +3513,7 @@ var instrumentCommandParser = {
|
|
|
3583
3513
|
/**
|
|
3584
3514
|
* Parses the INSTRUMENT command
|
|
3585
3515
|
*/
|
|
3586
|
-
parse
|
|
3587
|
-
input.args;
|
|
3516
|
+
parse(input) {
|
|
3588
3517
|
return {
|
|
3589
3518
|
type: 'INSTRUMENT',
|
|
3590
3519
|
};
|
|
@@ -3594,7 +3523,7 @@ var instrumentCommandParser = {
|
|
|
3594
3523
|
*
|
|
3595
3524
|
* Note: `$` is used to indicate that this function mutates given `pipelineJson`
|
|
3596
3525
|
*/
|
|
3597
|
-
$applyToPipelineJson
|
|
3526
|
+
$applyToPipelineJson(command, $pipelineJson) {
|
|
3598
3527
|
console.error(new NotYetImplementedError('[🛠] Instruments are not implemented yet'));
|
|
3599
3528
|
},
|
|
3600
3529
|
/**
|
|
@@ -3602,7 +3531,7 @@ var instrumentCommandParser = {
|
|
|
3602
3531
|
*
|
|
3603
3532
|
* Note: This is used in `pipelineJsonToString` utility
|
|
3604
3533
|
*/
|
|
3605
|
-
stringify
|
|
3534
|
+
stringify(command) {
|
|
3606
3535
|
throw new NotYetImplementedError('[🛠] Instruments are not implemented yet');
|
|
3607
3536
|
},
|
|
3608
3537
|
/**
|
|
@@ -3610,7 +3539,7 @@ var instrumentCommandParser = {
|
|
|
3610
3539
|
*
|
|
3611
3540
|
* Note: This is used in `pipelineJsonToString` utility
|
|
3612
3541
|
*/
|
|
3613
|
-
takeFromPipelineJson
|
|
3542
|
+
takeFromPipelineJson(pipelineJson) {
|
|
3614
3543
|
throw new NotYetImplementedError('[🛠] Instruments are not implemented yet');
|
|
3615
3544
|
},
|
|
3616
3545
|
};
|
|
@@ -3623,7 +3552,7 @@ var instrumentCommandParser = {
|
|
|
3623
3552
|
*
|
|
3624
3553
|
* @public exported from `@promptbook/editable`
|
|
3625
3554
|
*/
|
|
3626
|
-
|
|
3555
|
+
const COMMANDS = [
|
|
3627
3556
|
sectionCommandParser,
|
|
3628
3557
|
expectCommandParser,
|
|
3629
3558
|
formatCommandParser,
|
|
@@ -3655,12 +3584,16 @@ var COMMANDS = [
|
|
|
3655
3584
|
* @public exported from `@promptbook/editable`
|
|
3656
3585
|
*/
|
|
3657
3586
|
function getParserForCommand(command) {
|
|
3658
|
-
|
|
3587
|
+
const commandParser = COMMANDS.find((commandParser) => commandParser.name === command.type);
|
|
3659
3588
|
if (commandParser === undefined) {
|
|
3660
|
-
throw new UnexpectedError(spaceTrim$1(
|
|
3589
|
+
throw new UnexpectedError(spaceTrim$1((block) => `
|
|
3590
|
+
Command ${command.type} parser is not found
|
|
3591
|
+
|
|
3592
|
+
${block(JSON.stringify(command, null, 4)
|
|
3661
3593
|
.split('\n')
|
|
3662
|
-
.map(
|
|
3663
|
-
.join('\n'))
|
|
3594
|
+
.map((line) => `> ${line}`)
|
|
3595
|
+
.join('\n'))}
|
|
3596
|
+
`));
|
|
3664
3597
|
}
|
|
3665
3598
|
return commandParser;
|
|
3666
3599
|
}
|
|
@@ -3695,7 +3628,7 @@ function parseCommand(raw, usagePlace) {
|
|
|
3695
3628
|
throw new ParseError('Command can not contain new line characters' /* <- TODO: [🚞] */);
|
|
3696
3629
|
}
|
|
3697
3630
|
// TODO: Unit test all this processing and parsing
|
|
3698
|
-
|
|
3631
|
+
let normalized = raw.trim();
|
|
3699
3632
|
normalized = normalized.split('`').join('');
|
|
3700
3633
|
normalized = normalized.split('"').join('');
|
|
3701
3634
|
normalized = normalized.split("'").join('');
|
|
@@ -3705,7 +3638,7 @@ function parseCommand(raw, usagePlace) {
|
|
|
3705
3638
|
normalized = normalized.split('(').join('');
|
|
3706
3639
|
normalized = normalized.split(')').join('');
|
|
3707
3640
|
normalized = normalizeTo_SCREAMING_CASE(normalized);
|
|
3708
|
-
|
|
3641
|
+
const items = raw
|
|
3709
3642
|
.trim()
|
|
3710
3643
|
// Note: [🐡]
|
|
3711
3644
|
.split(/^>/)
|
|
@@ -3724,25 +3657,30 @@ function parseCommand(raw, usagePlace) {
|
|
|
3724
3657
|
.join('PARAMETER {')
|
|
3725
3658
|
// ---
|
|
3726
3659
|
.split(' ')
|
|
3727
|
-
.map(
|
|
3728
|
-
.filter(
|
|
3660
|
+
.map((part) => part.trim())
|
|
3661
|
+
.filter((item) => item !== '')
|
|
3729
3662
|
.map(removeMarkdownFormatting)
|
|
3730
|
-
.map(
|
|
3663
|
+
.map((item) => item.trim());
|
|
3731
3664
|
if (items.length === 0 || items[0] === '') {
|
|
3732
|
-
throw new ParseError(spaceTrim$1(
|
|
3733
|
-
|
|
3734
|
-
|
|
3665
|
+
throw new ParseError(spaceTrim$1((block) => `
|
|
3666
|
+
Malformed command:
|
|
3667
|
+
- ${raw}
|
|
3668
|
+
|
|
3669
|
+
Supported commands are:
|
|
3670
|
+
${block(getSupportedCommandsMessage())}
|
|
3671
|
+
|
|
3672
|
+
`));
|
|
3735
3673
|
}
|
|
3736
3674
|
// Note: Taking command name from beginning of the line
|
|
3737
3675
|
// FOO | BAR Arg1 Arg2 Arg3
|
|
3738
3676
|
// FOO BAR | Arg1 Arg2 Arg3
|
|
3739
|
-
for (
|
|
3740
|
-
|
|
3741
|
-
|
|
3742
|
-
|
|
3677
|
+
for (let commandNameSegmentsCount = 0; commandNameSegmentsCount < Math.min(items.length, 3); commandNameSegmentsCount++) {
|
|
3678
|
+
const commandNameRaw = items.slice(0, commandNameSegmentsCount + 1).join('_');
|
|
3679
|
+
const args = items.slice(commandNameSegmentsCount + 1);
|
|
3680
|
+
const rawArgs = raw
|
|
3743
3681
|
.substring(commandNameRaw.length)
|
|
3744
3682
|
.trim();
|
|
3745
|
-
|
|
3683
|
+
const command = parseCommandVariant({ usagePlace, raw, rawArgs, normalized, args, commandNameRaw });
|
|
3746
3684
|
if (command !== null) {
|
|
3747
3685
|
return command;
|
|
3748
3686
|
}
|
|
@@ -3750,78 +3688,79 @@ function parseCommand(raw, usagePlace) {
|
|
|
3750
3688
|
// Note: Taking command name from end of the line
|
|
3751
3689
|
// Arg1 Arg2 Arg3 | FOO
|
|
3752
3690
|
{
|
|
3753
|
-
|
|
3754
|
-
|
|
3755
|
-
|
|
3691
|
+
const commandNameRaw = items.slice(-1).join('_');
|
|
3692
|
+
const args = items.slice(0, -1); // <- Note: This is probbably not correct
|
|
3693
|
+
const rawArgs = raw
|
|
3756
3694
|
.substring(0, raw.length - commandNameRaw.length)
|
|
3757
3695
|
.trim();
|
|
3758
|
-
|
|
3696
|
+
const command = parseCommandVariant({ usagePlace, raw, rawArgs, normalized, args, commandNameRaw });
|
|
3759
3697
|
if (command !== null) {
|
|
3760
3698
|
return command;
|
|
3761
3699
|
}
|
|
3762
3700
|
}
|
|
3763
|
-
throw new ParseError(spaceTrim$1(
|
|
3764
|
-
|
|
3765
|
-
|
|
3701
|
+
throw new ParseError(spaceTrim$1((block) => `
|
|
3702
|
+
Malformed or unknown command:
|
|
3703
|
+
- ${raw}
|
|
3704
|
+
|
|
3705
|
+
Supported commands are:
|
|
3706
|
+
${block(getSupportedCommandsMessage())}
|
|
3707
|
+
|
|
3708
|
+
`));
|
|
3766
3709
|
}
|
|
3767
3710
|
/**
|
|
3768
3711
|
* @@@
|
|
3769
3712
|
*/
|
|
3770
3713
|
function getSupportedCommandsMessage() {
|
|
3771
|
-
return COMMANDS.flatMap(
|
|
3772
|
-
|
|
3773
|
-
|
|
3774
|
-
|
|
3775
|
-
|
|
3776
|
-
|
|
3777
|
-
}).join('\n');
|
|
3714
|
+
return COMMANDS.flatMap(({ name, aliasNames, description, documentationUrl }) =>
|
|
3715
|
+
// <- Note: [🦦] Its strange that this type assertion is needed
|
|
3716
|
+
[
|
|
3717
|
+
`- **${name}** ${description}, see [discussion](${documentationUrl})`,
|
|
3718
|
+
...(aliasNames || []).map((aliasName) => ` - **${aliasName}** Alias for **${name}**`),
|
|
3719
|
+
]).join('\n');
|
|
3778
3720
|
}
|
|
3779
3721
|
/**
|
|
3780
3722
|
* @@@
|
|
3781
3723
|
*/
|
|
3782
3724
|
function parseCommandVariant(input) {
|
|
3783
|
-
|
|
3784
|
-
|
|
3785
|
-
|
|
3786
|
-
var _loop_1 = function (commandParser) {
|
|
3725
|
+
const { commandNameRaw, usagePlace, normalized, args, raw, rawArgs } = input;
|
|
3726
|
+
const commandName = normalizeTo_SCREAMING_CASE(commandNameRaw);
|
|
3727
|
+
for (const commandParser of COMMANDS) {
|
|
3787
3728
|
// <- Note: [🦦] Its strange that this type assertion is needed
|
|
3788
|
-
|
|
3729
|
+
const { name, isUsedInPipelineHead, isUsedInPipelineTask, aliasNames, deprecatedNames, parse } = commandParser;
|
|
3789
3730
|
if (just(false)) ;
|
|
3790
3731
|
else if (usagePlace === 'PIPELINE_HEAD' && !isUsedInPipelineHead) {
|
|
3791
|
-
|
|
3732
|
+
continue;
|
|
3792
3733
|
}
|
|
3793
3734
|
else if (usagePlace === 'PIPELINE_TASK' && !isUsedInPipelineTask) {
|
|
3794
|
-
|
|
3735
|
+
continue;
|
|
3795
3736
|
}
|
|
3796
|
-
|
|
3737
|
+
const names = [name, ...(aliasNames || []), ...(deprecatedNames || [])];
|
|
3797
3738
|
if (names.includes(commandName)) {
|
|
3798
3739
|
try {
|
|
3799
|
-
return
|
|
3740
|
+
return parse({ usagePlace, raw, rawArgs, normalized, args }); // <- Note: [🦦]
|
|
3800
3741
|
}
|
|
3801
3742
|
catch (error) {
|
|
3802
3743
|
if (!(error instanceof ParseError)) {
|
|
3803
3744
|
throw error;
|
|
3804
3745
|
}
|
|
3805
|
-
throw new ParseError(spaceTrim$1(
|
|
3806
|
-
|
|
3807
|
-
|
|
3746
|
+
throw new ParseError(spaceTrim$1((block) => `
|
|
3747
|
+
Invalid ${commandName} command:
|
|
3748
|
+
|
|
3749
|
+
Your command:
|
|
3750
|
+
- ${raw}
|
|
3751
|
+
|
|
3752
|
+
The detailed error:
|
|
3753
|
+
${block(error.message)}
|
|
3754
|
+
|
|
3755
|
+
Usage of ${commandName}:
|
|
3756
|
+
${block(commandParser.examples.map((example) => `- ${example}`).join('\n'))}
|
|
3757
|
+
|
|
3758
|
+
All supported commands are:
|
|
3759
|
+
${block(getSupportedCommandsMessage())}
|
|
3760
|
+
|
|
3761
|
+
`));
|
|
3808
3762
|
}
|
|
3809
3763
|
}
|
|
3810
|
-
};
|
|
3811
|
-
try {
|
|
3812
|
-
for (var _b = __values(COMMANDS), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
3813
|
-
var commandParser = _c.value;
|
|
3814
|
-
var state_1 = _loop_1(commandParser);
|
|
3815
|
-
if (typeof state_1 === "object")
|
|
3816
|
-
return state_1.value;
|
|
3817
|
-
}
|
|
3818
|
-
}
|
|
3819
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
3820
|
-
finally {
|
|
3821
|
-
try {
|
|
3822
|
-
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
3823
|
-
}
|
|
3824
|
-
finally { if (e_1) throw e_1.error; }
|
|
3825
3764
|
}
|
|
3826
3765
|
return null;
|
|
3827
3766
|
}
|
|
@@ -3855,13 +3794,13 @@ function validatePipelineString(pipelineString) {
|
|
|
3855
3794
|
throw new ParseError('Expected a book, but got a JSON string');
|
|
3856
3795
|
}
|
|
3857
3796
|
else if (isValidUrl(pipelineString)) {
|
|
3858
|
-
throw new ParseError(
|
|
3797
|
+
throw new ParseError(`Expected a book, but got just the URL "${pipelineString}"`);
|
|
3859
3798
|
}
|
|
3860
3799
|
else if (isValidFilePath(pipelineString)) {
|
|
3861
|
-
throw new ParseError(
|
|
3800
|
+
throw new ParseError(`Expected a book, but got just the file path "${pipelineString}"`);
|
|
3862
3801
|
}
|
|
3863
3802
|
else if (isValidEmail(pipelineString)) {
|
|
3864
|
-
throw new ParseError(
|
|
3803
|
+
throw new ParseError(`Expected a book, but got just the email "${pipelineString}"`);
|
|
3865
3804
|
}
|
|
3866
3805
|
// <- TODO: Implement the validation + add tests when the pipeline logic considered as invalid
|
|
3867
3806
|
return pipelineString;
|
|
@@ -3889,16 +3828,16 @@ function removeMarkdownComments(content) {
|
|
|
3889
3828
|
function isFlatPipeline(pipelineString) {
|
|
3890
3829
|
pipelineString = removeMarkdownComments(pipelineString);
|
|
3891
3830
|
pipelineString = spaceTrim(pipelineString);
|
|
3892
|
-
|
|
3831
|
+
const isMarkdownBeginningWithHeadline = pipelineString.startsWith('# ');
|
|
3893
3832
|
//const isLastLineReturnStatement = pipelineString.split('\n').pop()!.split('`').join('').startsWith('->');
|
|
3894
|
-
|
|
3895
|
-
|
|
3896
|
-
|
|
3833
|
+
const isBacktickBlockUsed = pipelineString.includes('```');
|
|
3834
|
+
const isQuoteBlocksUsed = /^>\s+/m.test(pipelineString);
|
|
3835
|
+
const isBlocksUsed = isBacktickBlockUsed || isQuoteBlocksUsed;
|
|
3897
3836
|
// TODO: [🧉] Also (double)check
|
|
3898
3837
|
// > const usedCommands
|
|
3899
3838
|
// > const isBlocksUsed
|
|
3900
3839
|
// > const returnStatementCount
|
|
3901
|
-
|
|
3840
|
+
const isFlat = !isMarkdownBeginningWithHeadline && !isBlocksUsed; /* && isLastLineReturnStatement */
|
|
3902
3841
|
return isFlat;
|
|
3903
3842
|
}
|
|
3904
3843
|
|
|
@@ -3911,27 +3850,39 @@ function deflatePipeline(pipelineString) {
|
|
|
3911
3850
|
if (!isFlatPipeline(pipelineString)) {
|
|
3912
3851
|
return pipelineString;
|
|
3913
3852
|
}
|
|
3914
|
-
|
|
3915
|
-
|
|
3916
|
-
|
|
3853
|
+
const pipelineStringLines = pipelineString.split('\n');
|
|
3854
|
+
const potentialReturnStatement = pipelineStringLines.pop();
|
|
3855
|
+
let returnStatement;
|
|
3917
3856
|
if (/(-|=)>\s*\{.*\}/.test(potentialReturnStatement)) {
|
|
3918
3857
|
// Note: Last line is return statement
|
|
3919
3858
|
returnStatement = potentialReturnStatement;
|
|
3920
3859
|
}
|
|
3921
3860
|
else {
|
|
3922
3861
|
// Note: Last line is not a return statement
|
|
3923
|
-
returnStatement =
|
|
3862
|
+
returnStatement = `-> {${DEFAULT_BOOK_OUTPUT_PARAMETER_NAME}}`;
|
|
3924
3863
|
pipelineStringLines.push(potentialReturnStatement);
|
|
3925
3864
|
}
|
|
3926
|
-
|
|
3927
|
-
|
|
3865
|
+
const prompt = spaceTrim(pipelineStringLines.join('\n'));
|
|
3866
|
+
let quotedPrompt;
|
|
3928
3867
|
if (prompt.split('\n').length <= 1) {
|
|
3929
|
-
quotedPrompt =
|
|
3868
|
+
quotedPrompt = `> ${prompt}`;
|
|
3930
3869
|
}
|
|
3931
3870
|
else {
|
|
3932
|
-
quotedPrompt = spaceTrim(
|
|
3871
|
+
quotedPrompt = spaceTrim((block) => `
|
|
3872
|
+
\`\`\`
|
|
3873
|
+
${block(prompt.split('`').join('\\`'))}
|
|
3874
|
+
\`\`\`
|
|
3875
|
+
`);
|
|
3933
3876
|
}
|
|
3934
|
-
pipelineString = validatePipelineString(spaceTrim(
|
|
3877
|
+
pipelineString = validatePipelineString(spaceTrim((block) => `
|
|
3878
|
+
# ${DEFAULT_BOOK_TITLE}
|
|
3879
|
+
|
|
3880
|
+
## Prompt
|
|
3881
|
+
|
|
3882
|
+
${block(quotedPrompt)}
|
|
3883
|
+
|
|
3884
|
+
${returnStatement}
|
|
3885
|
+
`));
|
|
3935
3886
|
// <- TODO: Maybe use book` notation
|
|
3936
3887
|
return pipelineString;
|
|
3937
3888
|
}
|
|
@@ -3945,37 +3896,26 @@ function deflatePipeline(pipelineString) {
|
|
|
3945
3896
|
* @public exported from `@promptbook/editable`
|
|
3946
3897
|
*/
|
|
3947
3898
|
function addPipelineCommand(options) {
|
|
3948
|
-
|
|
3949
|
-
|
|
3950
|
-
|
|
3951
|
-
|
|
3952
|
-
|
|
3953
|
-
|
|
3954
|
-
|
|
3955
|
-
|
|
3956
|
-
|
|
3957
|
-
|
|
3958
|
-
|
|
3959
|
-
newLines.push("- ".concat(commandString));
|
|
3960
|
-
newLines.push('');
|
|
3961
|
-
isCommandAdded = true;
|
|
3962
|
-
}
|
|
3963
|
-
newLines.push(line);
|
|
3964
|
-
}
|
|
3965
|
-
}
|
|
3966
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
3967
|
-
finally {
|
|
3968
|
-
try {
|
|
3969
|
-
if (lines_1_1 && !lines_1_1.done && (_a = lines_1.return)) _a.call(lines_1);
|
|
3899
|
+
const { commandString, pipelineString } = options;
|
|
3900
|
+
const deflatedPipelineString = deflatePipeline(pipelineString);
|
|
3901
|
+
const lines = deflatedPipelineString.split('\n');
|
|
3902
|
+
const newLines = [];
|
|
3903
|
+
let isCommandAdded = false;
|
|
3904
|
+
for (const line of lines) {
|
|
3905
|
+
// Add command before second (or more) heading
|
|
3906
|
+
if (!isCommandAdded && line.startsWith('##')) {
|
|
3907
|
+
newLines.push(`- ${commandString}`);
|
|
3908
|
+
newLines.push('');
|
|
3909
|
+
isCommandAdded = true;
|
|
3970
3910
|
}
|
|
3971
|
-
|
|
3911
|
+
newLines.push(line);
|
|
3972
3912
|
}
|
|
3973
3913
|
if (!isCommandAdded) {
|
|
3974
3914
|
// Note: Only situation when this should happen is when pipeline has no tasks
|
|
3975
3915
|
if ((newLines[newLines.length - 1] || '').startsWith('#')) {
|
|
3976
3916
|
newLines.push('');
|
|
3977
3917
|
}
|
|
3978
|
-
newLines.push(
|
|
3918
|
+
newLines.push(`- ${commandString}`);
|
|
3979
3919
|
/*
|
|
3980
3920
|
TODO: [🧠] Is this error relevant:
|
|
3981
3921
|
throw new UnexpectedError(
|
|
@@ -4015,47 +3955,36 @@ function addPipelineCommand(options) {
|
|
|
4015
3955
|
* @public exported from `@promptbook/editable`
|
|
4016
3956
|
*/
|
|
4017
3957
|
function removePipelineCommand(options) {
|
|
4018
|
-
|
|
4019
|
-
|
|
4020
|
-
var lines = pipelineString.split('\n');
|
|
3958
|
+
const { command, pipelineString } = options;
|
|
3959
|
+
const lines = pipelineString.split('\n');
|
|
4021
3960
|
// TODO: [🧽] DRY
|
|
4022
|
-
|
|
4023
|
-
|
|
4024
|
-
|
|
4025
|
-
|
|
4026
|
-
|
|
4027
|
-
|
|
4028
|
-
if (line.startsWith('```')) {
|
|
4029
|
-
currentType = 'CODE_BLOCK';
|
|
4030
|
-
}
|
|
4031
|
-
else if (line.includes('<!--')) {
|
|
4032
|
-
currentType = 'COMMENT';
|
|
4033
|
-
}
|
|
3961
|
+
let currentType = 'MARKDOWN';
|
|
3962
|
+
const newLines = [];
|
|
3963
|
+
for (const line of lines) {
|
|
3964
|
+
if (currentType === 'MARKDOWN') {
|
|
3965
|
+
if (line.startsWith('```')) {
|
|
3966
|
+
currentType = 'CODE_BLOCK';
|
|
4034
3967
|
}
|
|
4035
|
-
else if (
|
|
4036
|
-
|
|
4037
|
-
currentType = 'MARKDOWN';
|
|
4038
|
-
}
|
|
3968
|
+
else if (line.includes('<!--')) {
|
|
3969
|
+
currentType = 'COMMENT';
|
|
4039
3970
|
}
|
|
4040
|
-
|
|
4041
|
-
|
|
4042
|
-
|
|
4043
|
-
|
|
3971
|
+
}
|
|
3972
|
+
else if (currentType === 'CODE_BLOCK') {
|
|
3973
|
+
if (line.startsWith('```')) {
|
|
3974
|
+
currentType = 'MARKDOWN';
|
|
4044
3975
|
}
|
|
4045
|
-
|
|
4046
|
-
|
|
3976
|
+
}
|
|
3977
|
+
else if (currentType === 'COMMENT') {
|
|
3978
|
+
if (line.includes('-->')) {
|
|
3979
|
+
currentType = 'MARKDOWN';
|
|
4047
3980
|
}
|
|
4048
|
-
newLines.push(line);
|
|
4049
3981
|
}
|
|
4050
|
-
|
|
4051
|
-
|
|
4052
|
-
finally {
|
|
4053
|
-
try {
|
|
4054
|
-
if (lines_1_1 && !lines_1_1.done && (_a = lines_1.return)) _a.call(lines_1);
|
|
3982
|
+
if (currentType === 'MARKDOWN' && /^(-|\d\))/m.test(line) && line.toUpperCase().includes(command)) {
|
|
3983
|
+
continue;
|
|
4055
3984
|
}
|
|
4056
|
-
|
|
3985
|
+
newLines.push(line);
|
|
4057
3986
|
}
|
|
4058
|
-
|
|
3987
|
+
const newPipeline = spaceTrim(newLines.join('\n'));
|
|
4059
3988
|
return newPipeline;
|
|
4060
3989
|
}
|
|
4061
3990
|
|
|
@@ -4064,16 +3993,13 @@ function removePipelineCommand(options) {
|
|
|
4064
3993
|
*
|
|
4065
3994
|
* @public exported from `@promptbook/core`
|
|
4066
3995
|
*/
|
|
4067
|
-
|
|
4068
|
-
|
|
4069
|
-
|
|
4070
|
-
|
|
4071
|
-
|
|
4072
|
-
Object.setPrototypeOf(_this, PipelineLogicError.prototype);
|
|
4073
|
-
return _this;
|
|
3996
|
+
class PipelineLogicError extends Error {
|
|
3997
|
+
constructor(message) {
|
|
3998
|
+
super(message);
|
|
3999
|
+
this.name = 'PipelineLogicError';
|
|
4000
|
+
Object.setPrototypeOf(this, PipelineLogicError.prototype);
|
|
4074
4001
|
}
|
|
4075
|
-
|
|
4076
|
-
}(Error));
|
|
4002
|
+
}
|
|
4077
4003
|
|
|
4078
4004
|
/**
|
|
4079
4005
|
* Function `renamePipelineParameter` will find all usable parameters for given task
|
|
@@ -4083,53 +4009,33 @@ var PipelineLogicError = /** @class */ (function (_super) {
|
|
|
4083
4009
|
* @public exported from `@promptbook/editable`
|
|
4084
4010
|
*/
|
|
4085
4011
|
function renamePipelineParameter(options) {
|
|
4086
|
-
|
|
4087
|
-
|
|
4088
|
-
|
|
4089
|
-
throw new PipelineLogicError("Can not replace {".concat(oldParameterName, "} to {").concat(newParameterName, "} because {").concat(newParameterName, "} is already used in the pipeline"));
|
|
4012
|
+
const { pipeline: pipeline, oldParameterName, newParameterName } = options;
|
|
4013
|
+
if (pipeline.parameters.some((parameter) => parameter.name === newParameterName)) {
|
|
4014
|
+
throw new PipelineLogicError(`Can not replace {${oldParameterName}} to {${newParameterName}} because {${newParameterName}} is already used in the pipeline`);
|
|
4090
4015
|
}
|
|
4091
|
-
|
|
4016
|
+
const renamedPipeline = {
|
|
4017
|
+
...pipeline,
|
|
4092
4018
|
// <- TODO: [🪓] This should be without `as $PipelineJson`
|
|
4093
|
-
parameters:
|
|
4094
|
-
|
|
4095
|
-
|
|
4096
|
-
|
|
4097
|
-
|
|
4098
|
-
|
|
4099
|
-
}
|
|
4100
|
-
parameter.name = newParameterName;
|
|
4101
|
-
}
|
|
4102
|
-
}
|
|
4103
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
4104
|
-
finally {
|
|
4105
|
-
try {
|
|
4106
|
-
if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
|
|
4107
|
-
}
|
|
4108
|
-
finally { if (e_1) throw e_1.error; }
|
|
4109
|
-
}
|
|
4110
|
-
try {
|
|
4111
|
-
for (var _e = __values(renamedPipeline.tasks), _f = _e.next(); !_f.done; _f = _e.next()) {
|
|
4112
|
-
var task = _f.value;
|
|
4113
|
-
if (task.resultingParameterName === oldParameterName) {
|
|
4114
|
-
task.resultingParameterName = newParameterName;
|
|
4115
|
-
}
|
|
4116
|
-
task.dependentParameterNames = task.dependentParameterNames.map(function (dependentParameterName) {
|
|
4117
|
-
return dependentParameterName === oldParameterName ? newParameterName : dependentParameterName;
|
|
4118
|
-
});
|
|
4119
|
-
task.content = task.content.replace(new RegExp("{".concat(oldParameterName, "}"), 'g'), "{".concat(newParameterName, "}"));
|
|
4120
|
-
task.title = task.title.replace(new RegExp("{".concat(oldParameterName, "}"), 'g'), "{".concat(newParameterName, "}"));
|
|
4121
|
-
task.description =
|
|
4122
|
-
task.description === undefined
|
|
4123
|
-
? undefined
|
|
4124
|
-
: task.description.replace(new RegExp("{".concat(oldParameterName, "}"), 'g'), "{".concat(newParameterName, "}"));
|
|
4019
|
+
parameters: [...pipeline.parameters],
|
|
4020
|
+
tasks: [...pipeline.tasks],
|
|
4021
|
+
};
|
|
4022
|
+
for (const parameter of renamedPipeline.parameters) {
|
|
4023
|
+
if (parameter.name !== oldParameterName) {
|
|
4024
|
+
continue;
|
|
4125
4025
|
}
|
|
4026
|
+
parameter.name = newParameterName;
|
|
4126
4027
|
}
|
|
4127
|
-
|
|
4128
|
-
|
|
4129
|
-
|
|
4130
|
-
if (_f && !_f.done && (_b = _e.return)) _b.call(_e);
|
|
4028
|
+
for (const task of renamedPipeline.tasks) {
|
|
4029
|
+
if (task.resultingParameterName === oldParameterName) {
|
|
4030
|
+
task.resultingParameterName = newParameterName;
|
|
4131
4031
|
}
|
|
4132
|
-
|
|
4032
|
+
task.dependentParameterNames = task.dependentParameterNames.map((dependentParameterName) => dependentParameterName === oldParameterName ? newParameterName : dependentParameterName);
|
|
4033
|
+
task.content = task.content.replace(new RegExp(`{${oldParameterName}}`, 'g'), `{${newParameterName}}`);
|
|
4034
|
+
task.title = task.title.replace(new RegExp(`{${oldParameterName}}`, 'g'), `{${newParameterName}}`);
|
|
4035
|
+
task.description =
|
|
4036
|
+
task.description === undefined
|
|
4037
|
+
? undefined
|
|
4038
|
+
: task.description.replace(new RegExp(`{${oldParameterName}}`, 'g'), `{${newParameterName}}`);
|
|
4133
4039
|
}
|
|
4134
4040
|
return renamedPipeline;
|
|
4135
4041
|
}
|
|
@@ -4159,7 +4065,7 @@ function renamePipelineParameter(options) {
|
|
|
4159
4065
|
*/
|
|
4160
4066
|
function isSerializableAsJson(value) {
|
|
4161
4067
|
try {
|
|
4162
|
-
checkSerializableAsJson({ value
|
|
4068
|
+
checkSerializableAsJson({ value });
|
|
4163
4069
|
return true;
|
|
4164
4070
|
}
|
|
4165
4071
|
catch (error) {
|
|
@@ -4181,11 +4087,17 @@ function isSerializableAsJson(value) {
|
|
|
4181
4087
|
*/
|
|
4182
4088
|
function stringifyPipelineJson(pipeline) {
|
|
4183
4089
|
if (!isSerializableAsJson(pipeline)) {
|
|
4184
|
-
throw new UnexpectedError(spaceTrim(
|
|
4090
|
+
throw new UnexpectedError(spaceTrim(`
|
|
4091
|
+
Cannot stringify the pipeline, because it is not serializable as JSON
|
|
4092
|
+
|
|
4093
|
+
There can be multiple reasons:
|
|
4094
|
+
1) The pipeline contains circular references
|
|
4095
|
+
2) It is not a valid PipelineJson
|
|
4096
|
+
`));
|
|
4185
4097
|
}
|
|
4186
|
-
|
|
4187
|
-
for (
|
|
4188
|
-
pipelineJsonStringified = pipelineJsonStringified.replace(/(-?0\.\d+),[\n\s]+(-?0\.\d+)/gms,
|
|
4098
|
+
let pipelineJsonStringified = JSON.stringify(pipeline, null, 4);
|
|
4099
|
+
for (let i = 0; i < LOOP_LIMIT; i++) {
|
|
4100
|
+
pipelineJsonStringified = pipelineJsonStringified.replace(/(-?0\.\d+),[\n\s]+(-?0\.\d+)/gms, `$1${REPLACING_NONCE}$2`);
|
|
4189
4101
|
}
|
|
4190
4102
|
pipelineJsonStringified = pipelineJsonStringified.split(REPLACING_NONCE).join(', ');
|
|
4191
4103
|
pipelineJsonStringified += '\n';
|