@promptbook/cli 0.46.0 → 0.47.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 (74) hide show
  1. package/README.md +18 -8
  2. package/esm/index.es.js +64 -50
  3. package/esm/index.es.js.map +1 -1
  4. package/esm/typings/_packages/langtail.index.d.ts +2 -2
  5. package/esm/typings/_packages/mock.index.d.ts +3 -3
  6. package/esm/typings/_packages/openai.index.d.ts +2 -2
  7. package/esm/typings/_packages/remote-client.index.d.ts +4 -4
  8. package/esm/typings/_packages/remote-server.index.d.ts +2 -2
  9. package/esm/typings/_packages/types.index.d.ts +2 -2
  10. package/esm/typings/_packages/utils.index.d.ts +2 -0
  11. package/esm/typings/conversion/prettify/PrettifyOptions.d.ts +9 -3
  12. package/esm/typings/conversion/prettify/prettifyPromptbookString.d.ts +1 -1
  13. package/esm/typings/conversion/prettify/renderPromptbookMermaid.d.ts +11 -0
  14. package/esm/typings/execution/ExecutionTools.d.ts +5 -2
  15. package/esm/typings/execution/{NaturalExecutionTools.d.ts → LlmExecutionTools.d.ts} +2 -2
  16. package/{umd/typings/execution/plugins/natural-execution-tools → esm/typings/execution/plugins/llm-execution-tools}/langtail/LangtailExecutionTools.d.ts +2 -2
  17. package/{umd/typings/execution/plugins/natural-execution-tools/mocked/MockedEchoNaturalExecutionTools.d.ts → esm/typings/execution/plugins/llm-execution-tools/mocked/MockedEchoLlmExecutionTools.d.ts} +2 -2
  18. package/{umd/typings/execution/plugins/natural-execution-tools/mocked/MockedFackedNaturalExecutionTools.d.ts → esm/typings/execution/plugins/llm-execution-tools/mocked/MockedFackedLlmExecutionTools.d.ts} +2 -2
  19. package/{umd/typings/execution/plugins/natural-execution-tools → esm/typings/execution/plugins/llm-execution-tools}/mocked/fakeTextToExpectations.d.ts +1 -1
  20. package/esm/typings/execution/plugins/{natural-execution-tools → llm-execution-tools}/openai/OpenAiExecutionTools.d.ts +2 -2
  21. package/esm/typings/execution/plugins/{natural-execution-tools/remote/RemoteNaturalExecutionTools.d.ts → llm-execution-tools/remote/RemoteLlmExecutionTools.d.ts} +5 -5
  22. package/esm/typings/execution/plugins/{natural-execution-tools/remote/RemoteNaturalExecutionToolsOptions.d.ts → llm-execution-tools/remote/RemoteLlmExecutionToolsOptions.d.ts} +3 -3
  23. package/{umd/typings/execution/plugins/natural-execution-tools → esm/typings/execution/plugins/llm-execution-tools}/remote/interfaces/RemoteServerOptions.d.ts +3 -3
  24. package/esm/typings/types/PromptbookJson/PromptTemplateJson.d.ts +2 -2
  25. package/package.json +14 -4
  26. package/umd/index.umd.js +64 -50
  27. package/umd/index.umd.js.map +1 -1
  28. package/umd/typings/_packages/langtail.index.d.ts +2 -2
  29. package/umd/typings/_packages/mock.index.d.ts +3 -3
  30. package/umd/typings/_packages/openai.index.d.ts +2 -2
  31. package/umd/typings/_packages/remote-client.index.d.ts +4 -4
  32. package/umd/typings/_packages/remote-server.index.d.ts +2 -2
  33. package/umd/typings/_packages/types.index.d.ts +2 -2
  34. package/umd/typings/_packages/utils.index.d.ts +2 -0
  35. package/umd/typings/conversion/prettify/PrettifyOptions.d.ts +9 -3
  36. package/umd/typings/conversion/prettify/prettifyPromptbookString.d.ts +1 -1
  37. package/umd/typings/conversion/prettify/renderPromptbookMermaid.d.ts +11 -0
  38. package/umd/typings/execution/ExecutionTools.d.ts +5 -2
  39. package/umd/typings/execution/{NaturalExecutionTools.d.ts → LlmExecutionTools.d.ts} +2 -2
  40. package/{esm/typings/execution/plugins/natural-execution-tools → umd/typings/execution/plugins/llm-execution-tools}/langtail/LangtailExecutionTools.d.ts +2 -2
  41. package/{esm/typings/execution/plugins/natural-execution-tools/mocked/MockedEchoNaturalExecutionTools.d.ts → umd/typings/execution/plugins/llm-execution-tools/mocked/MockedEchoLlmExecutionTools.d.ts} +2 -2
  42. package/{esm/typings/execution/plugins/natural-execution-tools/mocked/MockedFackedNaturalExecutionTools.d.ts → umd/typings/execution/plugins/llm-execution-tools/mocked/MockedFackedLlmExecutionTools.d.ts} +2 -2
  43. package/{esm/typings/execution/plugins/natural-execution-tools → umd/typings/execution/plugins/llm-execution-tools}/mocked/fakeTextToExpectations.d.ts +1 -1
  44. package/umd/typings/execution/plugins/{natural-execution-tools → llm-execution-tools}/openai/OpenAiExecutionTools.d.ts +2 -2
  45. package/umd/typings/execution/plugins/{natural-execution-tools/remote/RemoteNaturalExecutionTools.d.ts → llm-execution-tools/remote/RemoteLlmExecutionTools.d.ts} +5 -5
  46. package/umd/typings/execution/plugins/{natural-execution-tools/remote/RemoteNaturalExecutionToolsOptions.d.ts → llm-execution-tools/remote/RemoteLlmExecutionToolsOptions.d.ts} +3 -3
  47. package/{esm/typings/execution/plugins/natural-execution-tools → umd/typings/execution/plugins/llm-execution-tools}/remote/interfaces/RemoteServerOptions.d.ts +3 -3
  48. package/umd/typings/types/PromptbookJson/PromptTemplateJson.d.ts +2 -2
  49. /package/esm/typings/execution/plugins/{natural-execution-tools → llm-execution-tools}/langtail/LangtailExecutionToolsOptions.d.ts +0 -0
  50. /package/esm/typings/execution/plugins/{natural-execution-tools → llm-execution-tools}/mocked/fakeTextToExpectations.test.d.ts +0 -0
  51. /package/esm/typings/execution/plugins/{natural-execution-tools → llm-execution-tools}/mocked/faked-completion.test.d.ts +0 -0
  52. /package/esm/typings/execution/plugins/{natural-execution-tools → llm-execution-tools}/mocked/joker.test.d.ts +0 -0
  53. /package/esm/typings/execution/plugins/{natural-execution-tools → llm-execution-tools}/mocked/mocked-chat.test.d.ts +0 -0
  54. /package/esm/typings/execution/plugins/{natural-execution-tools → llm-execution-tools}/mocked/mocked-completion.test.d.ts +0 -0
  55. /package/esm/typings/execution/plugins/{natural-execution-tools → llm-execution-tools}/openai/OpenAiExecutionToolsOptions.d.ts +0 -0
  56. /package/esm/typings/execution/plugins/{natural-execution-tools → llm-execution-tools}/openai/computeOpenaiUsage.d.ts +0 -0
  57. /package/esm/typings/execution/plugins/{natural-execution-tools → llm-execution-tools}/remote/interfaces/Promptbook_Server_Error.d.ts +0 -0
  58. /package/esm/typings/execution/plugins/{natural-execution-tools → llm-execution-tools}/remote/interfaces/Promptbook_Server_Progress.d.ts +0 -0
  59. /package/esm/typings/execution/plugins/{natural-execution-tools → llm-execution-tools}/remote/interfaces/Promptbook_Server_Request.d.ts +0 -0
  60. /package/esm/typings/execution/plugins/{natural-execution-tools → llm-execution-tools}/remote/interfaces/Promptbook_Server_Response.d.ts +0 -0
  61. /package/esm/typings/execution/plugins/{natural-execution-tools → llm-execution-tools}/remote/startRemoteServer.d.ts +0 -0
  62. /package/umd/typings/execution/plugins/{natural-execution-tools → llm-execution-tools}/langtail/LangtailExecutionToolsOptions.d.ts +0 -0
  63. /package/umd/typings/execution/plugins/{natural-execution-tools → llm-execution-tools}/mocked/fakeTextToExpectations.test.d.ts +0 -0
  64. /package/umd/typings/execution/plugins/{natural-execution-tools → llm-execution-tools}/mocked/faked-completion.test.d.ts +0 -0
  65. /package/umd/typings/execution/plugins/{natural-execution-tools → llm-execution-tools}/mocked/joker.test.d.ts +0 -0
  66. /package/umd/typings/execution/plugins/{natural-execution-tools → llm-execution-tools}/mocked/mocked-chat.test.d.ts +0 -0
  67. /package/umd/typings/execution/plugins/{natural-execution-tools → llm-execution-tools}/mocked/mocked-completion.test.d.ts +0 -0
  68. /package/umd/typings/execution/plugins/{natural-execution-tools → llm-execution-tools}/openai/OpenAiExecutionToolsOptions.d.ts +0 -0
  69. /package/umd/typings/execution/plugins/{natural-execution-tools → llm-execution-tools}/openai/computeOpenaiUsage.d.ts +0 -0
  70. /package/umd/typings/execution/plugins/{natural-execution-tools → llm-execution-tools}/remote/interfaces/Promptbook_Server_Error.d.ts +0 -0
  71. /package/umd/typings/execution/plugins/{natural-execution-tools → llm-execution-tools}/remote/interfaces/Promptbook_Server_Progress.d.ts +0 -0
  72. /package/umd/typings/execution/plugins/{natural-execution-tools → llm-execution-tools}/remote/interfaces/Promptbook_Server_Request.d.ts +0 -0
  73. /package/umd/typings/execution/plugins/{natural-execution-tools → llm-execution-tools}/remote/interfaces/Promptbook_Server_Response.d.ts +0 -0
  74. /package/umd/typings/execution/plugins/{natural-execution-tools → llm-execution-tools}/remote/startRemoteServer.d.ts +0 -0
@@ -0,0 +1,11 @@
1
+ import { PromptbookJson } from '../../_packages/types.index';
2
+ /**
3
+ * Creates a Mermaid graph based on the promptbook
4
+ *
5
+ * Note: The result is not wrapped in a Markdown code block
6
+ */
7
+ export declare function renderPromptbookMermaid(promptbookJson: PromptbookJson): string;
8
+ /**
9
+ * TODO: Maybe use some Mermaid library instead of string templating
10
+ * TODO: [🕌] When more than 2 functionalities, split into separate functions
11
+ */
@@ -1,4 +1,4 @@
1
- import type { NaturalExecutionTools } from './NaturalExecutionTools';
1
+ import type { LlmExecutionTools } from './LlmExecutionTools';
2
2
  import type { ScriptExecutionTools } from './ScriptExecutionTools';
3
3
  import type { UserInterfaceTools } from './UserInterfaceTools';
4
4
  /**
@@ -10,7 +10,7 @@ export type ExecutionTools = {
10
10
  /**
11
11
  * Tools for executing prompts to large language models like GPT-4
12
12
  */
13
- natural: NaturalExecutionTools;
13
+ llm: LlmExecutionTools;
14
14
  /**
15
15
  * Tools for executing scripts
16
16
  *
@@ -23,3 +23,6 @@ export type ExecutionTools = {
23
23
  */
24
24
  userInterface: UserInterfaceTools;
25
25
  };
26
+ /**
27
+ * TODO: !!!! Allow more
28
+ */
@@ -5,9 +5,9 @@ import type { PromptChatResult, PromptCompletionResult } from './PromptResult';
5
5
  * On its interface it exposes common methods for prompt execution.
6
6
  * Inside (in constructor) it calls OpenAI, Azure, GPU, proxy, cache, logging,...
7
7
  *
8
- * @see https://github.com/webgptorg/promptbook#natural-execution-tools
8
+ * @see https://github.com/webgptorg/promptbook#llm-execution-tools
9
9
  */
10
- export type NaturalExecutionTools = {
10
+ export type LlmExecutionTools = {
11
11
  /**
12
12
  * Use a chat model
13
13
  */
@@ -1,9 +1,9 @@
1
- import type { NaturalExecutionTools } from '../../../NaturalExecutionTools';
1
+ import type { LlmExecutionTools } from '../../../LlmExecutionTools';
2
2
  import { OpenAiExecutionTools } from '../openai/OpenAiExecutionTools';
3
3
  /**
4
4
  * Execution Tools for calling OpenAI API.
5
5
  */
6
- export declare class LangtailExecutionTools extends OpenAiExecutionTools implements NaturalExecutionTools {
6
+ export declare class LangtailExecutionTools extends OpenAiExecutionTools implements LlmExecutionTools {
7
7
  }
8
8
  /**
9
9
  * TODO: !!! Make lib which exports this
@@ -1,11 +1,11 @@
1
1
  import { Prompt } from '../../../../types/Prompt';
2
2
  import { CommonExecutionToolsOptions } from '../../../CommonExecutionToolsOptions';
3
- import { NaturalExecutionTools } from '../../../NaturalExecutionTools';
3
+ import { LlmExecutionTools } from '../../../LlmExecutionTools';
4
4
  import { PromptChatResult, PromptCompletionResult } from '../../../PromptResult';
5
5
  /**
6
6
  * Mocked execution Tools for just echoing the requests for testing purposes.
7
7
  */
8
- export declare class MockedEchoNaturalExecutionTools implements NaturalExecutionTools {
8
+ export declare class MockedEchoLlmExecutionTools implements LlmExecutionTools {
9
9
  private readonly options;
10
10
  constructor(options: CommonExecutionToolsOptions);
11
11
  /**
@@ -1,11 +1,11 @@
1
1
  import { Prompt } from '../../../../types/Prompt';
2
2
  import { CommonExecutionToolsOptions } from '../../../CommonExecutionToolsOptions';
3
- import { NaturalExecutionTools } from '../../../NaturalExecutionTools';
3
+ import { LlmExecutionTools } from '../../../LlmExecutionTools';
4
4
  import { PromptChatResult, PromptCompletionResult } from '../../../PromptResult';
5
5
  /**
6
6
  * Mocked execution Tools for just faking expected responses for testing purposes
7
7
  */
8
- export declare class MockedFackedNaturalExecutionTools implements NaturalExecutionTools {
8
+ export declare class MockedFackedLlmExecutionTools implements LlmExecutionTools {
9
9
  private readonly options;
10
10
  constructor(options: CommonExecutionToolsOptions);
11
11
  /**
@@ -6,7 +6,7 @@ import { PostprocessingFunction } from '../../script-execution-tools/javascript/
6
6
  * Note: You can provide postprocessing functions to modify the text before checking the expectations
7
7
  * The result will be the text BEFORE the postprocessing
8
8
  *
9
- * @private internal util for MockedFackedNaturalExecutionTools
9
+ * @private internal util for MockedFackedLlmExecutionTools
10
10
  */
11
11
  export declare function $fakeTextToExpectations(expectations: Expectations, postprocessing?: Array<PostprocessingFunction>): Promise<string>;
12
12
  /**
@@ -1,11 +1,11 @@
1
1
  import type { Prompt } from '../../../../types/Prompt';
2
- import type { NaturalExecutionTools } from '../../../NaturalExecutionTools';
2
+ import type { LlmExecutionTools } from '../../../LlmExecutionTools';
3
3
  import type { PromptChatResult, PromptCompletionResult } from '../../../PromptResult';
4
4
  import type { OpenAiExecutionToolsOptions } from './OpenAiExecutionToolsOptions';
5
5
  /**
6
6
  * Execution Tools for calling OpenAI API.
7
7
  */
8
- export declare class OpenAiExecutionTools implements NaturalExecutionTools {
8
+ export declare class OpenAiExecutionTools implements LlmExecutionTools {
9
9
  private readonly options;
10
10
  /**
11
11
  * OpenAI API client.
@@ -1,7 +1,7 @@
1
1
  import { Prompt } from '../../../../types/Prompt';
2
- import { NaturalExecutionTools } from '../../../NaturalExecutionTools';
2
+ import { LlmExecutionTools } from '../../../LlmExecutionTools';
3
3
  import { PromptChatResult, PromptCompletionResult } from '../../../PromptResult';
4
- import { RemoteNaturalExecutionToolsOptions } from './RemoteNaturalExecutionToolsOptions';
4
+ import { RemoteLlmExecutionToolsOptions } from './RemoteLlmExecutionToolsOptions';
5
5
  /**
6
6
  * Remote server is a proxy server that uses its execution tools internally and exposes the executor interface externally.
7
7
  *
@@ -10,9 +10,9 @@ import { RemoteNaturalExecutionToolsOptions } from './RemoteNaturalExecutionTool
10
10
  *
11
11
  * @see https://github.com/webgptorg/promptbook#remote-server
12
12
  */
13
- export declare class RemoteNaturalExecutionTools implements NaturalExecutionTools {
13
+ export declare class RemoteLlmExecutionTools implements LlmExecutionTools {
14
14
  private readonly options;
15
- constructor(options: RemoteNaturalExecutionToolsOptions);
15
+ constructor(options: RemoteLlmExecutionToolsOptions);
16
16
  /**
17
17
  * Creates a connection to the remote proxy server.
18
18
  */
@@ -31,5 +31,5 @@ export declare class RemoteNaturalExecutionTools implements NaturalExecutionTool
31
31
  private gptCommon;
32
32
  }
33
33
  /**
34
- * TODO: [🤹‍♂️] RemoteNaturalExecutionTools should extend Destroyable and implement IDestroyable
34
+ * TODO: [🤹‍♂️] RemoteLlmExecutionTools should extend Destroyable and implement IDestroyable
35
35
  */
@@ -1,9 +1,9 @@
1
- import type { client_id, string_uri } from '../../../.././types/typeAliases';
1
+ import type { client_id, string_uri } from '../../../../types/typeAliases';
2
2
  import type { CommonExecutionToolsOptions } from '../../../CommonExecutionToolsOptions';
3
3
  /**
4
- * Options for RemoteNaturalExecutionTools
4
+ * Options for RemoteLlmExecutionTools
5
5
  */
6
- export type RemoteNaturalExecutionToolsOptions = CommonExecutionToolsOptions & {
6
+ export type RemoteLlmExecutionToolsOptions = CommonExecutionToolsOptions & {
7
7
  /**
8
8
  * URL of the remote PROMPTBOOK server
9
9
  * On this server will be connected to the socket.io server
@@ -1,7 +1,7 @@
1
1
  import type { PromptbookLibrary } from '../../../../../library/PromptbookLibrary';
2
2
  import type { client_id, string_uri } from '../../../../../types/typeAliases';
3
3
  import type { CommonExecutionToolsOptions } from '../../../../CommonExecutionToolsOptions';
4
- import type { NaturalExecutionTools } from '../../../../NaturalExecutionTools';
4
+ import type { LlmExecutionTools } from '../../../../LlmExecutionTools';
5
5
  export type RemoteServerOptions = CommonExecutionToolsOptions & {
6
6
  /**
7
7
  * Port on which the server will listen
@@ -21,7 +21,7 @@ export type RemoteServerOptions = CommonExecutionToolsOptions & {
21
21
  */
22
22
  readonly library: PromptbookLibrary;
23
23
  /**
24
- * Creates natural execution tools for each client
24
+ * Creates llm execution tools for each client
25
25
  */
26
- createNaturalExecutionTools(clientId: client_id): NaturalExecutionTools;
26
+ createLlmExecutionTools(clientId: client_id): LlmExecutionTools;
27
27
  };
@@ -6,11 +6,11 @@ import type { number_integer, number_positive_or_zero, string_javascript, string
6
6
  /**
7
7
  * Describes one prompt template in the promptbook
8
8
  */
9
- export type PromptTemplateJson = NaturalTemplateJson | SimpleTemplateJson | ScriptTemplateJson | PromptDialogJson;
9
+ export type PromptTemplateJson = LlmTemplateJson | SimpleTemplateJson | ScriptTemplateJson | PromptDialogJson;
10
10
  /**
11
11
  * Template for prompt to LLM
12
12
  */
13
- export type NaturalTemplateJson = PromptTemplateJsonCommon & {
13
+ export type LlmTemplateJson = PromptTemplateJsonCommon & {
14
14
  readonly executionType: 'PROMPT_TEMPLATE';
15
15
  /**
16
16
  * Requirements for the model
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@promptbook/cli",
3
- "version": "0.46.0",
3
+ "version": "0.47.0",
4
4
  "description": "Library to supercharge your use of large language models",
5
5
  "private": false,
6
6
  "sideEffects": false,
@@ -38,11 +38,21 @@
38
38
  "commander": "12.0.0",
39
39
  "glob-promise": "6.0.5",
40
40
  "prettier": "2.8.1",
41
- "spacetrim": "0.11.20",
42
- "waitasecond": "1.11.33"
41
+ "spacetrim": "0.11.23",
42
+ "waitasecond": "1.11.67"
43
43
  },
44
+ "funding": [
45
+ {
46
+ "type": "individual",
47
+ "url": "https://buymeacoffee.com/hejny"
48
+ },
49
+ {
50
+ "type": "github",
51
+ "url": "https://github.com/webgptorg/promptbook/blob/main/README.md#%EF%B8%8F-contributing"
52
+ }
53
+ ],
44
54
  "peerDependencies": {
45
- "@promptbook/core": "0.46.0"
55
+ "@promptbook/core": "0.47.0"
46
56
  },
47
57
  "main": "./umd/index.umd.js",
48
58
  "module": "./esm/index.es.js",
package/umd/index.umd.js CHANGED
@@ -146,7 +146,67 @@
146
146
  /**
147
147
  * The version of the Promptbook library
148
148
  */
149
- var PROMPTBOOK_VERSION = '0.46.0-4';
149
+ var PROMPTBOOK_VERSION = '0.47.0-0';
150
+
151
+ /**
152
+ * This error type indicates that the error should not happen and its last check before crashing with some other error
153
+ */
154
+ var UnexpectedError = /** @class */ (function (_super) {
155
+ __extends(UnexpectedError, _super);
156
+ function UnexpectedError(message) {
157
+ var _this = _super.call(this, spacetrim.spaceTrim(function (block) { return "\n ".concat(block(message), "\n\n Note: This error should not happen.\n It's probbably a bug in the promptbook library\n\n Please report issue:\n https://github.com/webgptorg/promptbook/issues\n\n Or contact us on me@pavolhejny.com\n\n "); })) || this;
158
+ _this.name = 'UnexpectedError';
159
+ Object.setPrototypeOf(_this, UnexpectedError.prototype);
160
+ return _this;
161
+ }
162
+ return UnexpectedError;
163
+ }(Error));
164
+
165
+ /**
166
+ * Creates a Mermaid graph based on the promptbook
167
+ *
168
+ * Note: The result is not wrapped in a Markdown code block
169
+ */
170
+ function renderPromptbookMermaid(promptbookJson) {
171
+ var parameterNameToTemplateName = function (parameterName) {
172
+ var parameter = promptbookJson.parameters.find(function (parameter) { return parameter.name === parameterName; });
173
+ if (!parameter) {
174
+ throw new UnexpectedError("Could not find {".concat(parameterName, "}"));
175
+ }
176
+ if (parameter.isInput) {
177
+ return 'input';
178
+ }
179
+ var template = promptbookJson.promptTemplates.find(function (template) { return template.resultingParameterName === parameterName; });
180
+ if (!template) {
181
+ throw new Error("Could not find template for {".concat(parameterName, "}"));
182
+ }
183
+ return 'template' + normalizeTo_PascalCase(template.title);
184
+ };
185
+ var promptbookMermaid = spacetrim.spaceTrim(function (block) { return "\n\n %% \uD83D\uDD2E Tip: Open this on GitHub or in the VSCode website to see the Mermaid graph visually\n\n flowchart LR\n subgraph \"".concat(promptbookJson.title, "\"\n\n direction TB\n\n input((Input)):::input\n ").concat(block(promptbookJson.promptTemplates
186
+ .flatMap(function (_a) {
187
+ var title = _a.title, dependentParameterNames = _a.dependentParameterNames, resultingParameterName = _a.resultingParameterName;
188
+ return __spreadArray([
189
+ "".concat(parameterNameToTemplateName(resultingParameterName), "(\"").concat(title, "\")")
190
+ ], __read(dependentParameterNames.map(function (dependentParameterName) {
191
+ return "".concat(parameterNameToTemplateName(dependentParameterName), "--\"{").concat(dependentParameterName, "}\"-->").concat(parameterNameToTemplateName(resultingParameterName));
192
+ })), false);
193
+ })
194
+ .join('\n')), "\n\n ").concat(block(promptbookJson.parameters
195
+ .filter(function (_a) {
196
+ var isOutput = _a.isOutput;
197
+ return isOutput;
198
+ })
199
+ .map(function (_a) {
200
+ var name = _a.name;
201
+ return "".concat(parameterNameToTemplateName(name), "--\"{").concat(name, "}\"-->output");
202
+ })
203
+ .join('\n')), "\n output((Output)):::output\n\n classDef input color: grey;\n classDef output color: grey;\n\n end;\n\n "); });
204
+ return promptbookMermaid;
205
+ }
206
+ /**
207
+ * TODO: Maybe use some Mermaid library instead of string templating
208
+ * TODO: [🕌] When more than 2 functionalities, split into separate functions
209
+ */
150
210
 
151
211
  /**
152
212
  * This error indicates that the promptbook in a markdown format cannot be parsed into a valid promptbook object
@@ -524,20 +584,6 @@
524
584
  return TemplateError;
525
585
  })(Error));
526
586
 
527
- /**
528
- * This error type indicates that the error should not happen and its last check before crashing with some other error
529
- */
530
- var UnexpectedError = /** @class */ (function (_super) {
531
- __extends(UnexpectedError, _super);
532
- function UnexpectedError(message) {
533
- var _this = _super.call(this, spacetrim.spaceTrim(function (block) { return "\n ".concat(block(message), "\n\n Note: This error should not happen.\n It's probbably a bug in the promptbook library\n\n Please report issue:\n https://github.com/webgptorg/promptbook/issues\n\n Or contact us on me@pavolhejny.com\n\n "); })) || this;
534
- _this.name = 'UnexpectedError';
535
- Object.setPrototypeOf(_this, UnexpectedError.prototype);
536
- return _this;
537
- }
538
- return UnexpectedError;
539
- }(Error));
540
-
541
587
  /**
542
588
  * Prettify the html code
543
589
  *
@@ -1606,45 +1652,13 @@
1606
1652
  }
1607
1653
 
1608
1654
  /**
1609
- * !!!
1655
+ * Prettyfies Promptbook string and adds Mermaid graph
1610
1656
  */
1611
1657
  function prettifyPromptbookString(promptbookString, options) {
1612
1658
  var isGraphAdded = options.isGraphAdded, isPrettifyed = options.isPrettifyed;
1613
1659
  if (isGraphAdded) {
1614
- var promptbookJson_1 = promptbookStringToJson(promptbookString);
1615
- var parameterNameToTemplateName_1 = function (parameterName) {
1616
- var parameter = promptbookJson_1.parameters.find(function (parameter) { return parameter.name === parameterName; });
1617
- if (!parameter) {
1618
- throw new UnexpectedError("Could not find {".concat(parameterName, "}"));
1619
- }
1620
- if (parameter.isInput) {
1621
- return 'input';
1622
- }
1623
- var template = promptbookJson_1.promptTemplates.find(function (template) { return template.resultingParameterName === parameterName; });
1624
- if (!template) {
1625
- throw new Error("Could not find template for {".concat(parameterName, "}"));
1626
- }
1627
- return 'template' + normalizeTo_PascalCase(template.title);
1628
- };
1629
- var promptbookMermaid_1 = spacetrim.spaceTrim(function (block) { return "\n\n %% \uD83D\uDD2E Tip: Open this on GitHub or in the VSCode website to see the Mermaid graph visually\n\n flowchart LR\n subgraph \"".concat(promptbookJson_1.title, "\"\n\n direction TB\n\n input((Input)):::input\n ").concat(block(promptbookJson_1.promptTemplates
1630
- .flatMap(function (_a) {
1631
- var title = _a.title, dependentParameterNames = _a.dependentParameterNames, resultingParameterName = _a.resultingParameterName;
1632
- return __spreadArray([
1633
- "".concat(parameterNameToTemplateName_1(resultingParameterName), "(\"").concat(title, "\")")
1634
- ], __read(dependentParameterNames.map(function (dependentParameterName) {
1635
- return "".concat(parameterNameToTemplateName_1(dependentParameterName), "--\"{").concat(dependentParameterName, "}\"-->").concat(parameterNameToTemplateName_1(resultingParameterName));
1636
- })), false);
1637
- })
1638
- .join('\n')), "\n\n ").concat(block(promptbookJson_1.parameters
1639
- .filter(function (_a) {
1640
- var isOutput = _a.isOutput;
1641
- return isOutput;
1642
- })
1643
- .map(function (_a) {
1644
- var name = _a.name;
1645
- return "".concat(parameterNameToTemplateName_1(name), "--\"{").concat(name, "}\"-->output");
1646
- })
1647
- .join('\n')), "\n output((Output)):::output\n\n classDef input color: grey;\n classDef output color: grey;\n\n end;\n\n\n\n "); });
1660
+ var promptbookJson = promptbookStringToJson(promptbookString);
1661
+ var promptbookMermaid_1 = renderPromptbookMermaid(promptbookJson);
1648
1662
  var promptbookMermaidBlock = spacetrim.spaceTrim(function (block) { return "\n ```mermaid\n ".concat(block(promptbookMermaid_1), "\n ```\n "); });
1649
1663
  promptbookString = addAutoGeneratedSection(promptbookString, {
1650
1664
  sectionName: 'Graph',