@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/README.md CHANGED
@@ -23,6 +23,10 @@
23
23
 
24
24
 
25
25
 
26
+ <blockquote style="color: #ff8811">
27
+ <b>⚠ Warning:</b> This is a pre-release version of the library. It is not yet ready for production use. Please look at <a href="https://www.npmjs.com/package/@promptbook/core?activeTab=versions">latest stable release</a>.
28
+ </blockquote>
29
+
26
30
  ## 📦 Package `@promptbook/remote-client`
27
31
 
28
32
  - Promptbooks are [divided into several](#-packages) packages, all are published from [single monorepo](https://github.com/webgptorg/promptbook).
package/esm/index.es.js CHANGED
@@ -19,7 +19,7 @@ var BOOK_LANGUAGE_VERSION = '1.0.0';
19
19
  * @generated
20
20
  * @see https://github.com/webgptorg/promptbook
21
21
  */
22
- var PROMPTBOOK_ENGINE_VERSION = '0.82.0-3';
22
+ var PROMPTBOOK_ENGINE_VERSION = '0.83.0';
23
23
  /**
24
24
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
25
25
  * Note: [💞] Ignore a discrepancy between file name and entity name
@@ -1086,15 +1086,15 @@ function normalizeToKebabCase(text) {
1086
1086
  /**
1087
1087
  * Creates unique name for the source
1088
1088
  *
1089
- * @private within the repository
1089
+ * @public exported from `@promptbook/editable`
1090
1090
  */
1091
- function sourceContentToName(sourceContent) {
1092
- var hash = SHA256(hexEncoder.parse(JSON.stringify(sourceContent)))
1091
+ function knowledgeSourceContentToName(knowledgeSourceContent) {
1092
+ var hash = SHA256(hexEncoder.parse(JSON.stringify(knowledgeSourceContent)))
1093
1093
  // <- TODO: [🥬] Encapsulate sha256 to some private utility function
1094
1094
  .toString( /* hex */)
1095
1095
  .substring(0, 20);
1096
1096
  // <- TODO: [🥬] Make some system for hashes and ids of promptbook
1097
- var semanticName = normalizeToKebabCase(sourceContent.substring(0, 20));
1097
+ var semanticName = normalizeToKebabCase(knowledgeSourceContent.substring(0, 20));
1098
1098
  var pieces = ['source', semanticName, hash].filter(function (piece) { return piece !== ''; });
1099
1099
  var name = pieces.join('-').split('--').join('-');
1100
1100
  // <- TODO: Use MAX_FILENAME_LENGTH
@@ -1108,7 +1108,7 @@ function sourceContentToName(sourceContent) {
1108
1108
  * Parses the knowledge command
1109
1109
  *
1110
1110
  * @see `documentationUrl` for more details
1111
- * @private within the commands folder
1111
+ * @public exported from `@promptbook/editable`
1112
1112
  */
1113
1113
  var knowledgeCommandParser = {
1114
1114
  /**
@@ -1144,23 +1144,25 @@ var knowledgeCommandParser = {
1144
1144
  */
1145
1145
  parse: function (input) {
1146
1146
  var args = input.args;
1147
- var sourceContent = spaceTrim$1(args[0] || '');
1148
- if (sourceContent === '') {
1147
+ var knowledgeSourceContent = spaceTrim$1(args[0] || '');
1148
+ if (knowledgeSourceContent === '') {
1149
1149
  throw new ParseError("Source is not defined");
1150
1150
  }
1151
1151
  // TODO: [main] !!4 Following checks should be applied every link in the `sourceContent`
1152
- if (sourceContent.startsWith('http://')) {
1152
+ if (knowledgeSourceContent.startsWith('http://')) {
1153
1153
  throw new ParseError("Source is not secure");
1154
1154
  }
1155
- if (!(isValidFilePath(sourceContent) || isValidUrl(sourceContent))) {
1155
+ if (!(isValidFilePath(knowledgeSourceContent) || isValidUrl(knowledgeSourceContent))) {
1156
1156
  throw new ParseError("Source not valid");
1157
1157
  }
1158
- if (sourceContent.startsWith('../') || sourceContent.startsWith('/') || /^[A-Z]:[\\/]+/i.test(sourceContent)) {
1158
+ if (knowledgeSourceContent.startsWith('../') ||
1159
+ knowledgeSourceContent.startsWith('/') ||
1160
+ /^[A-Z]:[\\/]+/i.test(knowledgeSourceContent)) {
1159
1161
  throw new ParseError("Source cannot be outside of the .book.md folder");
1160
1162
  }
1161
1163
  return {
1162
1164
  type: 'KNOWLEDGE',
1163
- sourceContent: sourceContent,
1165
+ knowledgeSourceContent: knowledgeSourceContent,
1164
1166
  };
1165
1167
  },
1166
1168
  /**
@@ -1169,10 +1171,10 @@ var knowledgeCommandParser = {
1169
1171
  * Note: `$` is used to indicate that this function mutates given `pipelineJson`
1170
1172
  */
1171
1173
  $applyToPipelineJson: function (command, $pipelineJson) {
1172
- var sourceContent = command.sourceContent;
1174
+ var knowledgeSourceContent = command.knowledgeSourceContent;
1173
1175
  $pipelineJson.knowledgeSources.push({
1174
- name: sourceContentToName(sourceContent),
1175
- sourceContent: sourceContent,
1176
+ name: knowledgeSourceContentToName(knowledgeSourceContent),
1177
+ knowledgeSourceContent: knowledgeSourceContent,
1176
1178
  });
1177
1179
  },
1178
1180
  /**
@@ -1200,7 +1202,7 @@ var knowledgeCommandParser = {
1200
1202
  * Parses the section command
1201
1203
  *
1202
1204
  * @see `documentationUrl` for more details
1203
- * @private within the commands folder
1205
+ * @public exported from `@promptbook/editable`
1204
1206
  */
1205
1207
  var sectionCommandParser = {
1206
1208
  /**
@@ -1331,7 +1333,7 @@ var sectionCommandParser = {
1331
1333
  if (command.taskType === 'KNOWLEDGE') {
1332
1334
  knowledgeCommandParser.$applyToPipelineJson({
1333
1335
  type: 'KNOWLEDGE',
1334
- sourceContent: $taskJson.content, // <- TODO: [🐝][main] !!3 Work with KNOWLEDGE which not referring to the source file or website, but its content itself
1336
+ knowledgeSourceContent: $taskJson.content, // <- TODO: [🐝][main] !!3 Work with KNOWLEDGE which not referring to the source file or website, but its content itself
1335
1337
  }, $pipelineJson);
1336
1338
  $taskJson.isTask = false;
1337
1339
  return;
@@ -1518,7 +1520,7 @@ function isValidPromptbookVersion(version) {
1518
1520
  * Parses the BOOK_VERSION command
1519
1521
  *
1520
1522
  * @see `documentationUrl` for more details
1521
- * @private within the commands folder
1523
+ * @public exported from `@promptbook/editable`
1522
1524
  */
1523
1525
  var bookVersionCommandParser = {
1524
1526
  /**
@@ -1673,7 +1675,7 @@ function parseNumber(value) {
1673
1675
  * Parses the expect command
1674
1676
  *
1675
1677
  * @see `documentationUrl` for more details
1676
- * @private within the commands folder
1678
+ * @public exported from `@promptbook/editable`
1677
1679
  */
1678
1680
  var expectCommandParser = {
1679
1681
  /**
@@ -2614,7 +2616,7 @@ function validateParameterName(parameterName) {
2614
2616
  * Note: @@@ This command is used as foreach for new commands - it should NOT be used in any `.book.md` file
2615
2617
  *
2616
2618
  * @see `documentationUrl` for more details
2617
- * @private within the commands folder
2619
+ * @public exported from `@promptbook/editable`
2618
2620
  */
2619
2621
  var foreachCommandParser = {
2620
2622
  /**
@@ -2768,7 +2770,7 @@ var foreachCommandParser = {
2768
2770
  * Parses the format command
2769
2771
  *
2770
2772
  * @see `documentationUrl` for more details
2771
- * @private within the commands folder
2773
+ * @public exported from `@promptbook/editable`
2772
2774
  */
2773
2775
  var formatCommandParser = {
2774
2776
  /**
@@ -3065,7 +3067,7 @@ var FORMFACTOR_DEFINITIONS = [
3065
3067
  * Note: @@@ This command is used as formfactor for new commands - it should NOT be used in any `.book.md` file
3066
3068
  *
3067
3069
  * @see `documentationUrl` for more details
3068
- * @private within the commands folder
3070
+ * @public exported from `@promptbook/editable`
3069
3071
  */
3070
3072
  var formfactorCommandParser = {
3071
3073
  /**
@@ -3154,7 +3156,7 @@ var formfactorCommandParser = {
3154
3156
  * Parses the joker command
3155
3157
  *
3156
3158
  * @see `documentationUrl` for more details
3157
- * @private within the commands folder
3159
+ * @public exported from `@promptbook/editable`
3158
3160
  */
3159
3161
  var jokerCommandParser = {
3160
3162
  /**
@@ -3231,7 +3233,8 @@ var MODEL_VARIANTS = ['COMPLETION', 'CHAT', 'EMBEDDING' /* <- TODO [🏳] */ /*
3231
3233
  * Parses the model command
3232
3234
  *
3233
3235
  * @see `documentationUrl` for more details
3234
- * @private within the commands folder
3236
+ * @deprecated Option to manually set the model requirements is not recommended to use, use `PERSONA` instead
3237
+ * @public exported from `@promptbook/editable`
3235
3238
  */
3236
3239
  var modelCommandParser = {
3237
3240
  /**
@@ -3375,7 +3378,7 @@ var modelCommandParser = {
3375
3378
  * Parses the parameter command
3376
3379
  *
3377
3380
  * @see `documentationUrl` for more details
3378
- * @private within the commands folder
3381
+ * @public exported from `@promptbook/editable`
3379
3382
  */
3380
3383
  var parameterCommandParser = {
3381
3384
  /**
@@ -3480,7 +3483,7 @@ var parameterCommandParser = {
3480
3483
  * Parses the persona command
3481
3484
  *
3482
3485
  * @see `documentationUrl` for more details
3483
- * @private within the commands folder
3486
+ * @public exported from `@promptbook/editable`
3484
3487
  */
3485
3488
  var personaCommandParser = {
3486
3489
  /**
@@ -3615,7 +3618,7 @@ function isValidJavascriptName(javascriptName) {
3615
3618
  * Parses the postprocess command
3616
3619
  *
3617
3620
  * @see `documentationUrl` for more details
3618
- * @private within the commands folder
3621
+ * @public exported from `@promptbook/editable`
3619
3622
  */
3620
3623
  var postprocessCommandParser = {
3621
3624
  /**
@@ -3773,7 +3776,7 @@ function isValidPipelineUrl(url) {
3773
3776
  * Parses the url command
3774
3777
  *
3775
3778
  * @see `documentationUrl` for more details
3776
- * @private within the commands folder
3779
+ * @public exported from `@promptbook/editable`
3777
3780
  */
3778
3781
  var urlCommandParser = {
3779
3782
  /**
@@ -3874,7 +3877,7 @@ var urlCommandParser = {
3874
3877
  * Parses the action command
3875
3878
  *
3876
3879
  * @see `documentationUrl` for more details
3877
- * @private within the commands folder
3880
+ * @public exported from `@promptbook/editable`
3878
3881
  */
3879
3882
  var actionCommandParser = {
3880
3883
  /**
@@ -3940,7 +3943,7 @@ var actionCommandParser = {
3940
3943
  * Parses the instrument command
3941
3944
  *
3942
3945
  * @see `documentationUrl` for more details
3943
- * @private within the commands folder
3946
+ * @public exported from `@promptbook/editable`
3944
3947
  */
3945
3948
  var instrumentCommandParser = {
3946
3949
  /**
@@ -4005,7 +4008,7 @@ var instrumentCommandParser = {
4005
4008
  /**
4006
4009
  * All available command parsers
4007
4010
  *
4008
- * @private internal index of `parseCommand`
4011
+ * @public exported from `@promptbook/editable`
4009
4012
  */
4010
4013
  var COMMANDS = [
4011
4014
  sectionCommandParser,
@@ -4036,7 +4039,7 @@ var COMMANDS = [
4036
4039
  * @returns the parser for the command
4037
4040
  * @throws {UnexpectedError} if the parser is not found
4038
4041
  *
4039
- * @private within the compilePipeline
4042
+ * @public exported from `@promptbook/editable`
4040
4043
  */
4041
4044
  function getParserForCommand(command) {
4042
4045
  var commandParser = COMMANDS.find(function (commandParser) { return commandParser.name === command.type; });
@@ -4072,7 +4075,7 @@ function removeMarkdownFormatting(str) {
4072
4075
  * @returns parsed command object
4073
4076
  * @throws {ParseError} if the command is invalid
4074
4077
  *
4075
- * @private within the compilePipeline
4078
+ * @public exported from `@promptbook/editable`
4076
4079
  */
4077
4080
  function parseCommand(raw, usagePlace) {
4078
4081
  if (raw.includes('\n') || raw.includes('\r')) {
@@ -4533,6 +4536,55 @@ function validatePipelineString(pipelineString) {
4533
4536
  var SUPPORTED_SCRIPT_LANGUAGES = ['javascript', 'typescript', 'python'];
4534
4537
  // <- TODO: [🏥] DRY
4535
4538
 
4539
+ /**
4540
+ * Removes Markdown (or HTML) comments
4541
+ *
4542
+ * @param {string} content - The string to remove comments from.
4543
+ * @returns {string} The input string with all comments removed.
4544
+ * @public exported from `@promptbook/markdown-utils`
4545
+ */
4546
+ function removeMarkdownComments(content) {
4547
+ return spaceTrim(content.replace(/<!--(.*?)-->/gs, ''));
4548
+ }
4549
+
4550
+ /**
4551
+ * @@@
4552
+ *
4553
+ * @public exported from `@promptbook/editable`
4554
+ */
4555
+ function isFlatPipeline(pipelineString) {
4556
+ pipelineString = removeMarkdownComments(pipelineString);
4557
+ pipelineString = spaceTrim$1(pipelineString);
4558
+ var isMarkdownBeginningWithHeadline = pipelineString.startsWith('# ');
4559
+ var isLastLineReturnStatement = pipelineString.split('\n').pop().split('`').join('').startsWith('->');
4560
+ // TODO: Also (double)check
4561
+ // > const usedCommands
4562
+ // > const isBlocksUsed
4563
+ // > const returnStatementCount
4564
+ var isFlat = !isMarkdownBeginningWithHeadline && isLastLineReturnStatement;
4565
+ return isFlat;
4566
+ }
4567
+
4568
+ /**
4569
+ * @@@
4570
+ *
4571
+ * @public exported from `@promptbook/editable`
4572
+ */
4573
+ function deflatePipeline(pipelineString) {
4574
+ if (!isFlatPipeline(pipelineString)) {
4575
+ return pipelineString;
4576
+ }
4577
+ var pipelineStringLines = pipelineString.split('\n');
4578
+ var returnStatement = pipelineStringLines.pop();
4579
+ var prompt = spaceTrim$1(pipelineStringLines.join('\n'));
4580
+ pipelineString = validatePipelineString(spaceTrim$1(function (block) { return "\n # ".concat(DEFAULT_BOOK_TITLE, "\n\n ## Prompt\n\n ```\n ").concat(block(prompt), "\n ```\n\n ").concat(returnStatement, "\n "); }));
4581
+ // <- TODO: Maybe use book` notation
4582
+ return pipelineString;
4583
+ }
4584
+ /**
4585
+ * TODO: Unit test
4586
+ */
4587
+
4536
4588
  /**
4537
4589
  * Utility function to extract all list items from markdown
4538
4590
  *
@@ -4834,17 +4886,6 @@ function flattenMarkdown(markdown) {
4834
4886
  * NOW we are working just with markdown string and its good enough
4835
4887
  */
4836
4888
 
4837
- /**
4838
- * Removes Markdown (or HTML) comments
4839
- *
4840
- * @param {string} content - The string to remove comments from.
4841
- * @returns {string} The input string with all comments removed.
4842
- * @public exported from `@promptbook/markdown-utils`
4843
- */
4844
- function removeMarkdownComments(content) {
4845
- return spaceTrim(content.replace(/<!--(.*?)-->/gs, ''));
4846
- }
4847
-
4848
4889
  /**
4849
4890
  * @@@
4850
4891
  *
@@ -5102,26 +5143,9 @@ function parsePipeline(pipelineString) {
5102
5143
  pipelineString = removeMarkdownComments(pipelineString);
5103
5144
  pipelineString = spaceTrim(pipelineString);
5104
5145
  // <- TODO: [😧] `spaceTrim` should preserve discriminated type *(or at lease `PipelineString`)*
5146
+ pipelineString = deflatePipeline(pipelineString);
5105
5147
  // ==============
5106
- // Note: 1️⃣◽2️⃣ Process flat pipeline
5107
- var isMarkdownBeginningWithHeadline = pipelineString.startsWith('# ');
5108
- var isLastLineReturnStatement = pipelineString.split('\n').pop().split('`').join('').startsWith('->');
5109
- // TODO: Also (double)check
5110
- // > const usedCommands
5111
- // > const isBlocksUsed
5112
- // > const returnStatementCount
5113
- var isFlatPipeline = !isMarkdownBeginningWithHeadline && isLastLineReturnStatement;
5114
- // console.log({ isMarkdownBeginningWithHeadline, isLastLineReturnStatement, isFlatPipeline });
5115
- if (isFlatPipeline) {
5116
- var pipelineStringLines = pipelineString.split('\n');
5117
- var returnStatement_1 = pipelineStringLines.pop();
5118
- var prompt_1 = spaceTrim(pipelineStringLines.join('\n'));
5119
- pipelineString = validatePipelineString(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 "); }));
5120
- // <- TODO: Maybe use book` notation
5121
- // console.log(pipelineString);
5122
- }
5123
- // ==============
5124
- // Note: 1️⃣◽3️⃣ Parse the markdown
5148
+ // Note: 1️⃣◽2️⃣ Parse the markdown
5125
5149
  pipelineString = flattenMarkdown(pipelineString) /* <- Note: [🥞] */;
5126
5150
  pipelineString = pipelineString.replaceAll(/`\{(?<parameterName>[a-z0-9_]+)\}`/gi, '{$<parameterName>}');
5127
5151
  pipelineString = pipelineString.replaceAll(/`->\s+\{(?<parameterName>[a-z0-9_]+)\}`/gi, '-> {$<parameterName>}');