@promptbook/remote-client 0.82.0 → 0.84.0-0

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.
Files changed (52) hide show
  1. package/README.md +4 -0
  2. package/esm/index.es.js +87 -63
  3. package/esm/index.es.js.map +1 -1
  4. package/esm/typings/src/_packages/editable.index.d.ts +82 -2
  5. package/esm/typings/src/_packages/types.index.d.ts +26 -0
  6. package/esm/typings/src/commands/BOOK_VERSION/BookVersionCommand.d.ts +1 -1
  7. package/esm/typings/src/commands/BOOK_VERSION/bookVersionCommandParser.d.ts +1 -1
  8. package/esm/typings/src/commands/EXPECT/expectCommandParser.d.ts +1 -1
  9. package/esm/typings/src/commands/FOREACH/ForeachCommand.d.ts +1 -1
  10. package/esm/typings/src/commands/FOREACH/foreachCommandParser.d.ts +1 -1
  11. package/esm/typings/src/commands/FORMAT/formatCommandParser.d.ts +1 -1
  12. package/esm/typings/src/commands/FORMFACTOR/FormfactorCommand.d.ts +1 -1
  13. package/esm/typings/src/commands/FORMFACTOR/formfactorCommandParser.d.ts +1 -1
  14. package/esm/typings/src/commands/JOKER/JokerCommand.d.ts +1 -1
  15. package/esm/typings/src/commands/JOKER/jokerCommandParser.d.ts +1 -1
  16. package/esm/typings/src/commands/KNOWLEDGE/KnowledgeCommand.d.ts +2 -2
  17. package/esm/typings/src/commands/KNOWLEDGE/knowledgeCommandParser.d.ts +1 -1
  18. package/esm/typings/src/commands/KNOWLEDGE/utils/{sourceContentToName.d.ts → knowledgeSourceContentToName.d.ts} +2 -2
  19. package/esm/typings/src/commands/MODEL/ModelCommand.d.ts +2 -1
  20. package/esm/typings/src/commands/MODEL/modelCommandParser.d.ts +2 -1
  21. package/esm/typings/src/commands/PARAMETER/ParameterCommand.d.ts +1 -1
  22. package/esm/typings/src/commands/PARAMETER/parameterCommandParser.d.ts +1 -1
  23. package/esm/typings/src/commands/PERSONA/PersonaCommand.d.ts +1 -1
  24. package/esm/typings/src/commands/PERSONA/personaCommandParser.d.ts +1 -1
  25. package/esm/typings/src/commands/POSTPROCESS/PostprocessCommand.d.ts +1 -1
  26. package/esm/typings/src/commands/POSTPROCESS/postprocessCommandParser.d.ts +1 -1
  27. package/esm/typings/src/commands/SECTION/SectionCommand.d.ts +1 -1
  28. package/esm/typings/src/commands/SECTION/sectionCommandParser.d.ts +1 -1
  29. package/esm/typings/src/commands/URL/UrlCommand.d.ts +1 -1
  30. package/esm/typings/src/commands/URL/urlCommandParser.d.ts +1 -1
  31. package/esm/typings/src/commands/X_ACTION/ActionCommand.d.ts +1 -1
  32. package/esm/typings/src/commands/X_ACTION/actionCommandParser.d.ts +1 -1
  33. package/esm/typings/src/commands/X_INSTRUMENT/InstrumentCommand.d.ts +1 -1
  34. package/esm/typings/src/commands/X_INSTRUMENT/instrumentCommandParser.d.ts +1 -1
  35. package/esm/typings/src/commands/_common/getParserForCommand.d.ts +1 -1
  36. package/esm/typings/src/commands/_common/parseCommand.d.ts +1 -1
  37. package/esm/typings/src/commands/_common/stringifyCommand.d.ts +1 -0
  38. package/esm/typings/src/commands/_common/types/CommandParser.d.ts +8 -0
  39. package/esm/typings/src/commands/_common/types/CommandUsagePlaces.d.ts +2 -0
  40. package/esm/typings/src/commands/index.d.ts +1 -1
  41. package/esm/typings/src/pipeline/PipelineJson/KnowledgeSourceJson.d.ts +1 -1
  42. package/esm/typings/src/utils/editable/edit-pipeline-string/addPipelineCommand.d.ts +17 -0
  43. package/esm/typings/src/utils/editable/edit-pipeline-string/deflatePipeline.d.ts +10 -0
  44. package/esm/typings/src/utils/editable/{utils → edit-pipeline-string}/removePipelineCommand.d.ts +1 -1
  45. package/esm/typings/src/utils/editable/edit-pipeline-string/removePipelineCommand.test.d.ts +1 -0
  46. package/esm/typings/src/utils/editable/utils/isFlatPipeline.d.ts +7 -0
  47. package/esm/typings/src/utils/editable/utils/renamePipelineParameter.d.ts +3 -0
  48. package/package.json +2 -2
  49. package/umd/index.umd.js +87 -63
  50. package/umd/index.umd.js.map +1 -1
  51. /package/esm/typings/src/commands/KNOWLEDGE/utils/{sourceContentToName.test.d.ts → knowledgeSourceContentToName.test.d.ts} +0 -0
  52. /package/esm/typings/src/utils/editable/{utils/removePipelineCommand.test.d.ts → edit-pipeline-string/addPipelineCommand.test.d.ts} +0 -0
package/umd/index.umd.js CHANGED
@@ -23,7 +23,7 @@
23
23
  * @generated
24
24
  * @see https://github.com/webgptorg/promptbook
25
25
  */
26
- var PROMPTBOOK_ENGINE_VERSION = '0.82.0-3';
26
+ var PROMPTBOOK_ENGINE_VERSION = '0.83.0';
27
27
  /**
28
28
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
29
29
  * Note: [💞] Ignore a discrepancy between file name and entity name
@@ -1090,15 +1090,15 @@
1090
1090
  /**
1091
1091
  * Creates unique name for the source
1092
1092
  *
1093
- * @private within the repository
1093
+ * @public exported from `@promptbook/editable`
1094
1094
  */
1095
- function sourceContentToName(sourceContent) {
1096
- var hash = cryptoJs.SHA256(hexEncoder__default["default"].parse(JSON.stringify(sourceContent)))
1095
+ function knowledgeSourceContentToName(knowledgeSourceContent) {
1096
+ var hash = cryptoJs.SHA256(hexEncoder__default["default"].parse(JSON.stringify(knowledgeSourceContent)))
1097
1097
  // <- TODO: [🥬] Encapsulate sha256 to some private utility function
1098
1098
  .toString( /* hex */)
1099
1099
  .substring(0, 20);
1100
1100
  // <- TODO: [🥬] Make some system for hashes and ids of promptbook
1101
- var semanticName = normalizeToKebabCase(sourceContent.substring(0, 20));
1101
+ var semanticName = normalizeToKebabCase(knowledgeSourceContent.substring(0, 20));
1102
1102
  var pieces = ['source', semanticName, hash].filter(function (piece) { return piece !== ''; });
1103
1103
  var name = pieces.join('-').split('--').join('-');
1104
1104
  // <- TODO: Use MAX_FILENAME_LENGTH
@@ -1112,7 +1112,7 @@
1112
1112
  * Parses the knowledge command
1113
1113
  *
1114
1114
  * @see `documentationUrl` for more details
1115
- * @private within the commands folder
1115
+ * @public exported from `@promptbook/editable`
1116
1116
  */
1117
1117
  var knowledgeCommandParser = {
1118
1118
  /**
@@ -1148,23 +1148,25 @@
1148
1148
  */
1149
1149
  parse: function (input) {
1150
1150
  var args = input.args;
1151
- var sourceContent = spaceTrim__default["default"](args[0] || '');
1152
- if (sourceContent === '') {
1151
+ var knowledgeSourceContent = spaceTrim__default["default"](args[0] || '');
1152
+ if (knowledgeSourceContent === '') {
1153
1153
  throw new ParseError("Source is not defined");
1154
1154
  }
1155
1155
  // TODO: [main] !!4 Following checks should be applied every link in the `sourceContent`
1156
- if (sourceContent.startsWith('http://')) {
1156
+ if (knowledgeSourceContent.startsWith('http://')) {
1157
1157
  throw new ParseError("Source is not secure");
1158
1158
  }
1159
- if (!(isValidFilePath(sourceContent) || isValidUrl(sourceContent))) {
1159
+ if (!(isValidFilePath(knowledgeSourceContent) || isValidUrl(knowledgeSourceContent))) {
1160
1160
  throw new ParseError("Source not valid");
1161
1161
  }
1162
- if (sourceContent.startsWith('../') || sourceContent.startsWith('/') || /^[A-Z]:[\\/]+/i.test(sourceContent)) {
1162
+ if (knowledgeSourceContent.startsWith('../') ||
1163
+ knowledgeSourceContent.startsWith('/') ||
1164
+ /^[A-Z]:[\\/]+/i.test(knowledgeSourceContent)) {
1163
1165
  throw new ParseError("Source cannot be outside of the .book.md folder");
1164
1166
  }
1165
1167
  return {
1166
1168
  type: 'KNOWLEDGE',
1167
- sourceContent: sourceContent,
1169
+ knowledgeSourceContent: knowledgeSourceContent,
1168
1170
  };
1169
1171
  },
1170
1172
  /**
@@ -1173,10 +1175,10 @@
1173
1175
  * Note: `$` is used to indicate that this function mutates given `pipelineJson`
1174
1176
  */
1175
1177
  $applyToPipelineJson: function (command, $pipelineJson) {
1176
- var sourceContent = command.sourceContent;
1178
+ var knowledgeSourceContent = command.knowledgeSourceContent;
1177
1179
  $pipelineJson.knowledgeSources.push({
1178
- name: sourceContentToName(sourceContent),
1179
- sourceContent: sourceContent,
1180
+ name: knowledgeSourceContentToName(knowledgeSourceContent),
1181
+ knowledgeSourceContent: knowledgeSourceContent,
1180
1182
  });
1181
1183
  },
1182
1184
  /**
@@ -1204,7 +1206,7 @@
1204
1206
  * Parses the section command
1205
1207
  *
1206
1208
  * @see `documentationUrl` for more details
1207
- * @private within the commands folder
1209
+ * @public exported from `@promptbook/editable`
1208
1210
  */
1209
1211
  var sectionCommandParser = {
1210
1212
  /**
@@ -1335,7 +1337,7 @@
1335
1337
  if (command.taskType === 'KNOWLEDGE') {
1336
1338
  knowledgeCommandParser.$applyToPipelineJson({
1337
1339
  type: 'KNOWLEDGE',
1338
- sourceContent: $taskJson.content, // <- TODO: [🐝][main] !!3 Work with KNOWLEDGE which not referring to the source file or website, but its content itself
1340
+ knowledgeSourceContent: $taskJson.content, // <- TODO: [🐝][main] !!3 Work with KNOWLEDGE which not referring to the source file or website, but its content itself
1339
1341
  }, $pipelineJson);
1340
1342
  $taskJson.isTask = false;
1341
1343
  return;
@@ -1522,7 +1524,7 @@
1522
1524
  * Parses the BOOK_VERSION command
1523
1525
  *
1524
1526
  * @see `documentationUrl` for more details
1525
- * @private within the commands folder
1527
+ * @public exported from `@promptbook/editable`
1526
1528
  */
1527
1529
  var bookVersionCommandParser = {
1528
1530
  /**
@@ -1677,7 +1679,7 @@
1677
1679
  * Parses the expect command
1678
1680
  *
1679
1681
  * @see `documentationUrl` for more details
1680
- * @private within the commands folder
1682
+ * @public exported from `@promptbook/editable`
1681
1683
  */
1682
1684
  var expectCommandParser = {
1683
1685
  /**
@@ -2618,7 +2620,7 @@
2618
2620
  * Note: @@@ This command is used as foreach for new commands - it should NOT be used in any `.book.md` file
2619
2621
  *
2620
2622
  * @see `documentationUrl` for more details
2621
- * @private within the commands folder
2623
+ * @public exported from `@promptbook/editable`
2622
2624
  */
2623
2625
  var foreachCommandParser = {
2624
2626
  /**
@@ -2772,7 +2774,7 @@
2772
2774
  * Parses the format command
2773
2775
  *
2774
2776
  * @see `documentationUrl` for more details
2775
- * @private within the commands folder
2777
+ * @public exported from `@promptbook/editable`
2776
2778
  */
2777
2779
  var formatCommandParser = {
2778
2780
  /**
@@ -3069,7 +3071,7 @@
3069
3071
  * Note: @@@ This command is used as formfactor for new commands - it should NOT be used in any `.book.md` file
3070
3072
  *
3071
3073
  * @see `documentationUrl` for more details
3072
- * @private within the commands folder
3074
+ * @public exported from `@promptbook/editable`
3073
3075
  */
3074
3076
  var formfactorCommandParser = {
3075
3077
  /**
@@ -3158,7 +3160,7 @@
3158
3160
  * Parses the joker command
3159
3161
  *
3160
3162
  * @see `documentationUrl` for more details
3161
- * @private within the commands folder
3163
+ * @public exported from `@promptbook/editable`
3162
3164
  */
3163
3165
  var jokerCommandParser = {
3164
3166
  /**
@@ -3235,7 +3237,8 @@
3235
3237
  * Parses the model command
3236
3238
  *
3237
3239
  * @see `documentationUrl` for more details
3238
- * @private within the commands folder
3240
+ * @deprecated Option to manually set the model requirements is not recommended to use, use `PERSONA` instead
3241
+ * @public exported from `@promptbook/editable`
3239
3242
  */
3240
3243
  var modelCommandParser = {
3241
3244
  /**
@@ -3379,7 +3382,7 @@
3379
3382
  * Parses the parameter command
3380
3383
  *
3381
3384
  * @see `documentationUrl` for more details
3382
- * @private within the commands folder
3385
+ * @public exported from `@promptbook/editable`
3383
3386
  */
3384
3387
  var parameterCommandParser = {
3385
3388
  /**
@@ -3484,7 +3487,7 @@
3484
3487
  * Parses the persona command
3485
3488
  *
3486
3489
  * @see `documentationUrl` for more details
3487
- * @private within the commands folder
3490
+ * @public exported from `@promptbook/editable`
3488
3491
  */
3489
3492
  var personaCommandParser = {
3490
3493
  /**
@@ -3619,7 +3622,7 @@
3619
3622
  * Parses the postprocess command
3620
3623
  *
3621
3624
  * @see `documentationUrl` for more details
3622
- * @private within the commands folder
3625
+ * @public exported from `@promptbook/editable`
3623
3626
  */
3624
3627
  var postprocessCommandParser = {
3625
3628
  /**
@@ -3777,7 +3780,7 @@
3777
3780
  * Parses the url command
3778
3781
  *
3779
3782
  * @see `documentationUrl` for more details
3780
- * @private within the commands folder
3783
+ * @public exported from `@promptbook/editable`
3781
3784
  */
3782
3785
  var urlCommandParser = {
3783
3786
  /**
@@ -3878,7 +3881,7 @@
3878
3881
  * Parses the action command
3879
3882
  *
3880
3883
  * @see `documentationUrl` for more details
3881
- * @private within the commands folder
3884
+ * @public exported from `@promptbook/editable`
3882
3885
  */
3883
3886
  var actionCommandParser = {
3884
3887
  /**
@@ -3944,7 +3947,7 @@
3944
3947
  * Parses the instrument command
3945
3948
  *
3946
3949
  * @see `documentationUrl` for more details
3947
- * @private within the commands folder
3950
+ * @public exported from `@promptbook/editable`
3948
3951
  */
3949
3952
  var instrumentCommandParser = {
3950
3953
  /**
@@ -4009,7 +4012,7 @@
4009
4012
  /**
4010
4013
  * All available command parsers
4011
4014
  *
4012
- * @private internal index of `parseCommand`
4015
+ * @public exported from `@promptbook/editable`
4013
4016
  */
4014
4017
  var COMMANDS = [
4015
4018
  sectionCommandParser,
@@ -4040,7 +4043,7 @@
4040
4043
  * @returns the parser for the command
4041
4044
  * @throws {UnexpectedError} if the parser is not found
4042
4045
  *
4043
- * @private within the compilePipeline
4046
+ * @public exported from `@promptbook/editable`
4044
4047
  */
4045
4048
  function getParserForCommand(command) {
4046
4049
  var commandParser = COMMANDS.find(function (commandParser) { return commandParser.name === command.type; });
@@ -4076,7 +4079,7 @@
4076
4079
  * @returns parsed command object
4077
4080
  * @throws {ParseError} if the command is invalid
4078
4081
  *
4079
- * @private within the compilePipeline
4082
+ * @public exported from `@promptbook/editable`
4080
4083
  */
4081
4084
  function parseCommand(raw, usagePlace) {
4082
4085
  if (raw.includes('\n') || raw.includes('\r')) {
@@ -4537,6 +4540,55 @@
4537
4540
  var SUPPORTED_SCRIPT_LANGUAGES = ['javascript', 'typescript', 'python'];
4538
4541
  // <- TODO: [🏥] DRY
4539
4542
 
4543
+ /**
4544
+ * Removes Markdown (or HTML) comments
4545
+ *
4546
+ * @param {string} content - The string to remove comments from.
4547
+ * @returns {string} The input string with all comments removed.
4548
+ * @public exported from `@promptbook/markdown-utils`
4549
+ */
4550
+ function removeMarkdownComments(content) {
4551
+ return spaceTrim.spaceTrim(content.replace(/<!--(.*?)-->/gs, ''));
4552
+ }
4553
+
4554
+ /**
4555
+ * @@@
4556
+ *
4557
+ * @public exported from `@promptbook/editable`
4558
+ */
4559
+ function isFlatPipeline(pipelineString) {
4560
+ pipelineString = removeMarkdownComments(pipelineString);
4561
+ pipelineString = spaceTrim__default["default"](pipelineString);
4562
+ var isMarkdownBeginningWithHeadline = pipelineString.startsWith('# ');
4563
+ var isLastLineReturnStatement = pipelineString.split('\n').pop().split('`').join('').startsWith('->');
4564
+ // TODO: Also (double)check
4565
+ // > const usedCommands
4566
+ // > const isBlocksUsed
4567
+ // > const returnStatementCount
4568
+ var isFlat = !isMarkdownBeginningWithHeadline && isLastLineReturnStatement;
4569
+ return isFlat;
4570
+ }
4571
+
4572
+ /**
4573
+ * @@@
4574
+ *
4575
+ * @public exported from `@promptbook/editable`
4576
+ */
4577
+ function deflatePipeline(pipelineString) {
4578
+ if (!isFlatPipeline(pipelineString)) {
4579
+ return pipelineString;
4580
+ }
4581
+ var pipelineStringLines = pipelineString.split('\n');
4582
+ var returnStatement = pipelineStringLines.pop();
4583
+ var prompt = spaceTrim__default["default"](pipelineStringLines.join('\n'));
4584
+ pipelineString = validatePipelineString(spaceTrim__default["default"](function (block) { return "\n # ".concat(DEFAULT_BOOK_TITLE, "\n\n ## Prompt\n\n ```\n ").concat(block(prompt), "\n ```\n\n ").concat(returnStatement, "\n "); }));
4585
+ // <- TODO: Maybe use book` notation
4586
+ return pipelineString;
4587
+ }
4588
+ /**
4589
+ * TODO: Unit test
4590
+ */
4591
+
4540
4592
  /**
4541
4593
  * Utility function to extract all list items from markdown
4542
4594
  *
@@ -4838,17 +4890,6 @@
4838
4890
  * NOW we are working just with markdown string and its good enough
4839
4891
  */
4840
4892
 
4841
- /**
4842
- * Removes Markdown (or HTML) comments
4843
- *
4844
- * @param {string} content - The string to remove comments from.
4845
- * @returns {string} The input string with all comments removed.
4846
- * @public exported from `@promptbook/markdown-utils`
4847
- */
4848
- function removeMarkdownComments(content) {
4849
- return spaceTrim.spaceTrim(content.replace(/<!--(.*?)-->/gs, ''));
4850
- }
4851
-
4852
4893
  /**
4853
4894
  * @@@
4854
4895
  *
@@ -5106,26 +5147,9 @@
5106
5147
  pipelineString = removeMarkdownComments(pipelineString);
5107
5148
  pipelineString = spaceTrim.spaceTrim(pipelineString);
5108
5149
  // <- TODO: [😧] `spaceTrim` should preserve discriminated type *(or at lease `PipelineString`)*
5150
+ pipelineString = deflatePipeline(pipelineString);
5109
5151
  // ==============
5110
- // Note: 1️⃣◽2️⃣ Process flat pipeline
5111
- var isMarkdownBeginningWithHeadline = pipelineString.startsWith('# ');
5112
- var isLastLineReturnStatement = pipelineString.split('\n').pop().split('`').join('').startsWith('->');
5113
- // TODO: Also (double)check
5114
- // > const usedCommands
5115
- // > const isBlocksUsed
5116
- // > const returnStatementCount
5117
- var isFlatPipeline = !isMarkdownBeginningWithHeadline && isLastLineReturnStatement;
5118
- // console.log({ isMarkdownBeginningWithHeadline, isLastLineReturnStatement, isFlatPipeline });
5119
- if (isFlatPipeline) {
5120
- var pipelineStringLines = pipelineString.split('\n');
5121
- var returnStatement_1 = pipelineStringLines.pop();
5122
- var prompt_1 = spaceTrim.spaceTrim(pipelineStringLines.join('\n'));
5123
- pipelineString = validatePipelineString(spaceTrim.spaceTrim(function (block) { return "\n # ".concat(DEFAULT_BOOK_TITLE, "\n\n ## Prompt\n\n ```\n ").concat(block(prompt_1), "\n ```\n\n ").concat(returnStatement_1, "\n "); }));
5124
- // <- TODO: Maybe use book` notation
5125
- // console.log(pipelineString);
5126
- }
5127
- // ==============
5128
- // Note: 1️⃣◽3️⃣ Parse the markdown
5152
+ // Note: 1️⃣◽2️⃣ Parse the markdown
5129
5153
  pipelineString = flattenMarkdown(pipelineString) /* <- Note: [🥞] */;
5130
5154
  pipelineString = pipelineString.replaceAll(/`\{(?<parameterName>[a-z0-9_]+)\}`/gi, '{$<parameterName>}');
5131
5155
  pipelineString = pipelineString.replaceAll(/`->\s+\{(?<parameterName>[a-z0-9_]+)\}`/gi, '-> {$<parameterName>}');