@promptbook/cli 0.85.0-3 โ 0.85.0-5
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/bin/promptbook-cli.js +1 -1
- package/esm/index.es.js +97 -50
- package/esm/index.es.js.map +1 -1
- package/esm/typings/src/execution/ExecutionTask.d.ts +7 -3
- package/esm/typings/src/execution/FilesystemTools.d.ts +1 -1
- package/package.json +1 -1
- package/umd/index.umd.js +135 -88
- package/umd/index.umd.js.map +1 -1
package/bin/promptbook-cli.js
CHANGED
|
@@ -12,6 +12,6 @@ const { _CLI } = require('../umd/index.umd.js');
|
|
|
12
12
|
_CLI._initialize_promptbookCli();
|
|
13
13
|
|
|
14
14
|
/**
|
|
15
|
-
* TODO:
|
|
15
|
+
* TODO: [๐ฉโ๐ฉโ๐งโ๐ฆ] During the build check that this file exists
|
|
16
16
|
* TODO: [๐] When more functionalities, rename
|
|
17
17
|
*/
|
package/esm/index.es.js
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import colors from 'colors';
|
|
2
2
|
import commander from 'commander';
|
|
3
3
|
import spaceTrim, { spaceTrim as spaceTrim$1 } from 'spacetrim';
|
|
4
|
-
import { forTime } from 'waitasecond';
|
|
5
|
-
import { basename, join, dirname } from '
|
|
6
|
-
import { stat, access, constants, readFile, writeFile, readdir, mkdir, unlink, rm, rmdir, rename } from '
|
|
4
|
+
import { forTime, forEver } from 'waitasecond';
|
|
5
|
+
import { basename, join, dirname } from 'path';
|
|
6
|
+
import { stat, access, constants, readFile, writeFile, readdir, mkdir, unlink, rm, rmdir, rename } from 'fs/promises';
|
|
7
7
|
import hexEncoder from 'crypto-js/enc-hex';
|
|
8
8
|
import sha256 from 'crypto-js/sha256';
|
|
9
9
|
import * as dotenv from 'dotenv';
|
|
10
|
-
import { spawn } from '
|
|
10
|
+
import { spawn } from 'child_process';
|
|
11
11
|
import { format } from 'prettier';
|
|
12
12
|
import parserHtml from 'prettier/parser-html';
|
|
13
|
-
import { BehaviorSubject
|
|
13
|
+
import { BehaviorSubject } from 'rxjs';
|
|
14
14
|
import { randomBytes } from 'crypto';
|
|
15
15
|
import { unparse, parse } from 'papaparse';
|
|
16
16
|
import { SHA256 } from 'crypto-js';
|
|
@@ -19,7 +19,7 @@ import glob from 'glob-promise';
|
|
|
19
19
|
import prompts from 'prompts';
|
|
20
20
|
import moment from 'moment';
|
|
21
21
|
import express from 'express';
|
|
22
|
-
import http from '
|
|
22
|
+
import http from 'http';
|
|
23
23
|
import { Server } from 'socket.io';
|
|
24
24
|
import { io } from 'socket.io-client';
|
|
25
25
|
import Anthropic from '@anthropic-ai/sdk';
|
|
@@ -43,7 +43,7 @@ var BOOK_LANGUAGE_VERSION = '1.0.0';
|
|
|
43
43
|
* @generated
|
|
44
44
|
* @see https://github.com/webgptorg/promptbook
|
|
45
45
|
*/
|
|
46
|
-
var PROMPTBOOK_ENGINE_VERSION = '0.85.0-
|
|
46
|
+
var PROMPTBOOK_ENGINE_VERSION = '0.85.0-4';
|
|
47
47
|
/**
|
|
48
48
|
* TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
|
|
49
49
|
* Note: [๐] Ignore a discrepancy between file name and entity name
|
|
@@ -4920,11 +4920,29 @@ function assertsTaskSuccessful(executionResult) {
|
|
|
4920
4920
|
*/
|
|
4921
4921
|
function createTask(options) {
|
|
4922
4922
|
var taskType = options.taskType, taskProcessCallback = options.taskProcessCallback;
|
|
4923
|
-
var taskId = "".concat(taskType.toLowerCase(), "-").concat($randomToken(
|
|
4923
|
+
var taskId = "".concat(taskType.toLowerCase().substring(0, 4), "-").concat($randomToken(8 /* <- TODO: !!! To global config + Use Base58 to avoid simmilar char conflicts */));
|
|
4924
4924
|
var partialResultSubject = new BehaviorSubject({});
|
|
4925
4925
|
var finalResultPromise = /* not await */ taskProcessCallback(function (newOngoingResult) {
|
|
4926
4926
|
partialResultSubject.next(newOngoingResult);
|
|
4927
4927
|
});
|
|
4928
|
+
finalResultPromise
|
|
4929
|
+
.catch(function (error) {
|
|
4930
|
+
// console.error('!!!!! Task failed:', error);
|
|
4931
|
+
partialResultSubject.error(error);
|
|
4932
|
+
})
|
|
4933
|
+
.then(function (value) {
|
|
4934
|
+
// console.error('!!!!! Task finished:', value);
|
|
4935
|
+
if (value) {
|
|
4936
|
+
try {
|
|
4937
|
+
assertsTaskSuccessful(value);
|
|
4938
|
+
partialResultSubject.next(value);
|
|
4939
|
+
}
|
|
4940
|
+
catch (error) {
|
|
4941
|
+
partialResultSubject.error(error);
|
|
4942
|
+
}
|
|
4943
|
+
}
|
|
4944
|
+
partialResultSubject.complete();
|
|
4945
|
+
});
|
|
4928
4946
|
function asPromise(options) {
|
|
4929
4947
|
return __awaiter(this, void 0, void 0, function () {
|
|
4930
4948
|
var _a, isCrashedOnError, finalResult;
|
|
@@ -4935,7 +4953,9 @@ function createTask(options) {
|
|
|
4935
4953
|
return [4 /*yield*/, finalResultPromise];
|
|
4936
4954
|
case 1:
|
|
4937
4955
|
finalResult = _b.sent();
|
|
4956
|
+
console.error('!!!!! finalResult:', finalResult);
|
|
4938
4957
|
if (isCrashedOnError) {
|
|
4958
|
+
console.error('!!!!! isCrashedOnError:', finalResult);
|
|
4939
4959
|
assertsTaskSuccessful(finalResult);
|
|
4940
4960
|
}
|
|
4941
4961
|
return [2 /*return*/, finalResult];
|
|
@@ -4948,9 +4968,10 @@ function createTask(options) {
|
|
|
4948
4968
|
taskId: taskId,
|
|
4949
4969
|
asPromise: asPromise,
|
|
4950
4970
|
asObservable: function () {
|
|
4951
|
-
return
|
|
4952
|
-
|
|
4953
|
-
|
|
4971
|
+
return partialResultSubject.asObservable();
|
|
4972
|
+
},
|
|
4973
|
+
get currentValue() {
|
|
4974
|
+
return partialResultSubject.value;
|
|
4954
4975
|
},
|
|
4955
4976
|
};
|
|
4956
4977
|
}
|
|
@@ -13782,7 +13803,7 @@ function startRemoteServer(options) {
|
|
|
13782
13803
|
next();
|
|
13783
13804
|
});
|
|
13784
13805
|
var runningExecutionTasks = [];
|
|
13785
|
-
// TODO:
|
|
13806
|
+
// TODO: [๐ง ] Do here some garbage collection of finished tasks
|
|
13786
13807
|
app.get(['/', rootPath], function (request, response) { return __awaiter(_this, void 0, void 0, function () {
|
|
13787
13808
|
var _a, _b;
|
|
13788
13809
|
var _this = this;
|
|
@@ -13831,20 +13852,19 @@ function startRemoteServer(options) {
|
|
|
13831
13852
|
});
|
|
13832
13853
|
}); });
|
|
13833
13854
|
app.get("".concat(rootPath, "/books"), function (request, response) { return __awaiter(_this, void 0, void 0, function () {
|
|
13834
|
-
var
|
|
13835
|
-
return __generator(this, function (
|
|
13836
|
-
switch (
|
|
13855
|
+
var pipelines;
|
|
13856
|
+
return __generator(this, function (_a) {
|
|
13857
|
+
switch (_a.label) {
|
|
13837
13858
|
case 0:
|
|
13838
|
-
|
|
13839
|
-
|
|
13840
|
-
|
|
13841
|
-
|
|
13842
|
-
|
|
13843
|
-
case
|
|
13844
|
-
|
|
13845
|
-
|
|
13846
|
-
|
|
13847
|
-
_b.apply(_a, [_c]);
|
|
13859
|
+
if (collection === null) {
|
|
13860
|
+
response.status(500).send('No collection available');
|
|
13861
|
+
return [2 /*return*/];
|
|
13862
|
+
}
|
|
13863
|
+
return [4 /*yield*/, collection.listPipelines()];
|
|
13864
|
+
case 1:
|
|
13865
|
+
pipelines = _a.sent();
|
|
13866
|
+
// <- TODO: [๐ง ][๐ฉ๐พโ๐คโ๐ง๐ฟ] List `inputParameters` required for the execution
|
|
13867
|
+
response.send(pipelines);
|
|
13848
13868
|
return [2 /*return*/];
|
|
13849
13869
|
}
|
|
13850
13870
|
});
|
|
@@ -13858,22 +13878,23 @@ function startRemoteServer(options) {
|
|
|
13858
13878
|
app.get("".concat(rootPath, "/executions/:taskId"), function (request, response) { return __awaiter(_this, void 0, void 0, function () {
|
|
13859
13879
|
var taskId, execution;
|
|
13860
13880
|
return __generator(this, function (_a) {
|
|
13861
|
-
taskId = request.
|
|
13881
|
+
taskId = request.params.taskId;
|
|
13862
13882
|
execution = runningExecutionTasks.find(function (executionTask) { return executionTask.taskId === taskId; });
|
|
13863
13883
|
if (execution === undefined) {
|
|
13864
13884
|
response.status(404).send("Execution \"".concat(taskId, "\" not found"));
|
|
13865
13885
|
return [2 /*return*/];
|
|
13866
13886
|
}
|
|
13867
|
-
response.send(execution);
|
|
13887
|
+
response.send(execution.currentValue);
|
|
13868
13888
|
return [2 /*return*/];
|
|
13869
13889
|
});
|
|
13870
13890
|
}); });
|
|
13871
13891
|
app.post("".concat(rootPath, "/executions/new"), function (request, response) { return __awaiter(_this, void 0, void 0, function () {
|
|
13872
|
-
var inputParameters, pipelineUrl, pipeline, llm, fs, executables, tools, pipelineExecutor, executionTask;
|
|
13892
|
+
var inputParameters, pipelineUrl, pipeline, llm, fs, executables, tools, pipelineExecutor, executionTask, error_1;
|
|
13873
13893
|
var _a;
|
|
13874
13894
|
return __generator(this, function (_b) {
|
|
13875
13895
|
switch (_b.label) {
|
|
13876
13896
|
case 0:
|
|
13897
|
+
_b.trys.push([0, 6, , 7]);
|
|
13877
13898
|
inputParameters = request.body.inputParameters;
|
|
13878
13899
|
pipelineUrl = request.body.pipelineUrl || request.body.book;
|
|
13879
13900
|
return [4 /*yield*/, (collection === null || collection === void 0 ? void 0 : collection.getPipelineByUrl(pipelineUrl))];
|
|
@@ -13905,8 +13926,21 @@ function startRemoteServer(options) {
|
|
|
13905
13926
|
pipelineExecutor = createPipelineExecutor(__assign({ pipeline: pipeline, tools: tools }, options));
|
|
13906
13927
|
executionTask = pipelineExecutor(inputParameters);
|
|
13907
13928
|
runningExecutionTasks.push(executionTask);
|
|
13929
|
+
return [4 /*yield*/, forTime(10)];
|
|
13930
|
+
case 5:
|
|
13931
|
+
_b.sent();
|
|
13932
|
+
// <- Note: Wait for a while to wait for quick responses or sudden but asynchronous errors
|
|
13933
|
+
// <- TODO: Put this into configuration
|
|
13908
13934
|
response.send(executionTask);
|
|
13909
|
-
return [
|
|
13935
|
+
return [3 /*break*/, 7];
|
|
13936
|
+
case 6:
|
|
13937
|
+
error_1 = _b.sent();
|
|
13938
|
+
if (!(error_1 instanceof Error)) {
|
|
13939
|
+
throw error_1;
|
|
13940
|
+
}
|
|
13941
|
+
response.status(400).send({ error: serializeError(error_1) });
|
|
13942
|
+
return [3 /*break*/, 7];
|
|
13943
|
+
case 7: return [2 /*return*/];
|
|
13910
13944
|
}
|
|
13911
13945
|
});
|
|
13912
13946
|
}); });
|
|
@@ -13971,7 +14005,7 @@ function startRemoteServer(options) {
|
|
|
13971
14005
|
}); };
|
|
13972
14006
|
// -----------
|
|
13973
14007
|
socket.on('prompt-request', function (request) { return __awaiter(_this, void 0, void 0, function () {
|
|
13974
|
-
var identification, prompt, executionTools, llm, _a, promptResult, _b,
|
|
14008
|
+
var identification, prompt, executionTools, llm, _a, promptResult, _b, error_2;
|
|
13975
14009
|
return __generator(this, function (_c) {
|
|
13976
14010
|
switch (_c.label) {
|
|
13977
14011
|
case 0:
|
|
@@ -14040,11 +14074,11 @@ function startRemoteServer(options) {
|
|
|
14040
14074
|
socket.emit('prompt-response', { promptResult: promptResult } /* <- Note: [๐ค] */);
|
|
14041
14075
|
return [3 /*break*/, 15];
|
|
14042
14076
|
case 13:
|
|
14043
|
-
|
|
14044
|
-
if (!(
|
|
14045
|
-
throw
|
|
14077
|
+
error_2 = _c.sent();
|
|
14078
|
+
if (!(error_2 instanceof Error)) {
|
|
14079
|
+
throw error_2;
|
|
14046
14080
|
}
|
|
14047
|
-
socket.emit('error', serializeError(
|
|
14081
|
+
socket.emit('error', serializeError(error_2) /* <- Note: [๐ค] */);
|
|
14048
14082
|
return [3 /*break*/, 15];
|
|
14049
14083
|
case 14:
|
|
14050
14084
|
socket.disconnect();
|
|
@@ -14056,7 +14090,7 @@ function startRemoteServer(options) {
|
|
|
14056
14090
|
// -----------
|
|
14057
14091
|
// TODO: [๐] Listing models (and checking configuration) probbably should go through REST API not Socket.io
|
|
14058
14092
|
socket.on('listModels-request', function (request) { return __awaiter(_this, void 0, void 0, function () {
|
|
14059
|
-
var identification, executionTools, llm, models,
|
|
14093
|
+
var identification, executionTools, llm, models, error_3;
|
|
14060
14094
|
return __generator(this, function (_a) {
|
|
14061
14095
|
switch (_a.label) {
|
|
14062
14096
|
case 0:
|
|
@@ -14077,11 +14111,11 @@ function startRemoteServer(options) {
|
|
|
14077
14111
|
socket.emit('listModels-response', { models: models } /* <- Note: [๐ค] */);
|
|
14078
14112
|
return [3 /*break*/, 6];
|
|
14079
14113
|
case 4:
|
|
14080
|
-
|
|
14081
|
-
if (!(
|
|
14082
|
-
throw
|
|
14114
|
+
error_3 = _a.sent();
|
|
14115
|
+
if (!(error_3 instanceof Error)) {
|
|
14116
|
+
throw error_3;
|
|
14083
14117
|
}
|
|
14084
|
-
socket.emit('error', serializeError(
|
|
14118
|
+
socket.emit('error', serializeError(error_3));
|
|
14085
14119
|
return [3 /*break*/, 6];
|
|
14086
14120
|
case 5:
|
|
14087
14121
|
socket.disconnect();
|
|
@@ -14093,7 +14127,7 @@ function startRemoteServer(options) {
|
|
|
14093
14127
|
// -----------
|
|
14094
14128
|
// TODO: [๐] Listing models (and checking configuration) probbably should go through REST API not Socket.io
|
|
14095
14129
|
socket.on('preparePipeline-request', function (request) { return __awaiter(_this, void 0, void 0, function () {
|
|
14096
|
-
var identification, pipeline, executionTools, preparedPipeline,
|
|
14130
|
+
var identification, pipeline, executionTools, preparedPipeline, error_4;
|
|
14097
14131
|
return __generator(this, function (_a) {
|
|
14098
14132
|
switch (_a.label) {
|
|
14099
14133
|
case 0:
|
|
@@ -14113,11 +14147,11 @@ function startRemoteServer(options) {
|
|
|
14113
14147
|
socket.emit('preparePipeline-response', { preparedPipeline: preparedPipeline } /* <- Note: [๐ค] */);
|
|
14114
14148
|
return [3 /*break*/, 6];
|
|
14115
14149
|
case 4:
|
|
14116
|
-
|
|
14117
|
-
if (!(
|
|
14118
|
-
throw
|
|
14150
|
+
error_4 = _a.sent();
|
|
14151
|
+
if (!(error_4 instanceof Error)) {
|
|
14152
|
+
throw error_4;
|
|
14119
14153
|
}
|
|
14120
|
-
socket.emit('error', serializeError(
|
|
14154
|
+
socket.emit('error', serializeError(error_4));
|
|
14121
14155
|
return [3 /*break*/, 6];
|
|
14122
14156
|
case 5:
|
|
14123
14157
|
socket.disconnect();
|
|
@@ -14185,21 +14219,30 @@ function $initializeStartServerCommand(program) {
|
|
|
14185
14219
|
// <- TODO: [๐งโโ๏ธ] Unite path to promptbook collection argument
|
|
14186
14220
|
'Path to promptbook collection directory', DEFAULT_BOOKS_DIRNAME);
|
|
14187
14221
|
startServerCommand.option('--port <port>', "Port to start the server on", '4460');
|
|
14188
|
-
startServerCommand.option('-u, --url', spaceTrim("\n Public root url of the server\n It is used for following purposes:\n\n 1) It is suffixed with /books and used as rootUrl for all served books\n 2) Path (if not just /) is used as rootPath for the server\n "));
|
|
14222
|
+
startServerCommand.option('-u, --url <url>', spaceTrim("\n Public root url of the server\n It is used for following purposes:\n\n 1) It is suffixed with /books and used as rootUrl for all served books\n 2) Path (if not just /) is used as rootPath for the server\n "));
|
|
14189
14223
|
startServerCommand.option('--allow-anonymous', "Is anonymous mode allowed", false);
|
|
14190
14224
|
startServerCommand.option('-r, --reload', "Call LLM models even if same prompt with result is in the cache", false);
|
|
14191
14225
|
startServerCommand.option('-v, --verbose', "Is output verbose", false);
|
|
14192
14226
|
startServerCommand.description(spaceTrim("\n Starts a remote server to execute books\n "));
|
|
14193
14227
|
startServerCommand.action(function (path, _a) {
|
|
14194
|
-
var
|
|
14228
|
+
var portRaw = _a.port, rawUrl = _a.url, isAnonymousModeAllowed = _a.allowAnonymous, isCacheReloaded = _a.reload, isVerbose = _a.verbose;
|
|
14195
14229
|
return __awaiter(_this, void 0, void 0, function () {
|
|
14196
|
-
var url, rootUrl, rootPath, prepareAndScrapeOptions, fs, llm, executables, tools, collection;
|
|
14230
|
+
var port, url, rootUrl, rootPath, prepareAndScrapeOptions, fs, llm, executables, tools, collection;
|
|
14197
14231
|
var _b;
|
|
14198
14232
|
return __generator(this, function (_c) {
|
|
14199
14233
|
switch (_c.label) {
|
|
14200
14234
|
case 0:
|
|
14235
|
+
if (rawUrl && !isValidUrl(rawUrl)) {
|
|
14236
|
+
console.error(colors.red("Invalid URL: ".concat(rawUrl)));
|
|
14237
|
+
return [2 /*return*/, process.exit(1)];
|
|
14238
|
+
}
|
|
14239
|
+
port = parseInt(portRaw, 10);
|
|
14240
|
+
if (isNaN(port) || port <= 0 || port > 65535) {
|
|
14241
|
+
console.error(colors.red("Invalid port number: ".concat(portRaw)));
|
|
14242
|
+
return [2 /*return*/, process.exit(1)];
|
|
14243
|
+
}
|
|
14201
14244
|
url = !rawUrl ? null : new URL(rawUrl);
|
|
14202
|
-
if (url !== null && url.port !== port) {
|
|
14245
|
+
if (url !== null && url.port !== port.toString()) {
|
|
14203
14246
|
console.warn(colors.yellow("Port in --url is different from --port which the server will listen on, this is ok only if you proxy from one port to another, for exaple via nginx or docker"));
|
|
14204
14247
|
}
|
|
14205
14248
|
rootUrl = undefined;
|
|
@@ -14244,7 +14287,7 @@ function $initializeStartServerCommand(program) {
|
|
|
14244
14287
|
collection = _c.sent();
|
|
14245
14288
|
startRemoteServer({
|
|
14246
14289
|
rootPath: rootPath,
|
|
14247
|
-
port:
|
|
14290
|
+
port: port,
|
|
14248
14291
|
isAnonymousModeAllowed: isAnonymousModeAllowed,
|
|
14249
14292
|
isApplicationModeAllowed: true,
|
|
14250
14293
|
collection: collection,
|
|
@@ -14253,7 +14296,11 @@ function $initializeStartServerCommand(program) {
|
|
|
14253
14296
|
return llm;
|
|
14254
14297
|
},
|
|
14255
14298
|
});
|
|
14256
|
-
return [
|
|
14299
|
+
return [4 /*yield*/, forEver()];
|
|
14300
|
+
case 5:
|
|
14301
|
+
// Note: Already logged by `startRemoteServer`
|
|
14302
|
+
// console.error(colors.green(`Server started on port ${port}`));
|
|
14303
|
+
return [2 /*return*/, _c.sent()];
|
|
14257
14304
|
}
|
|
14258
14305
|
});
|
|
14259
14306
|
});
|