@promptbook/core 0.8.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 (190) hide show
  1. package/README.md +5 -0
  2. package/esm/index.es.js +1403 -0
  3. package/esm/index.es.js.map +1 -0
  4. package/esm/typings/_packages/core.index.d.ts +17 -0
  5. package/esm/typings/_packages/execute-javascript.index.d.ts +3 -0
  6. package/esm/typings/_packages/openai.index.d.ts +3 -0
  7. package/esm/typings/_packages/remote-client.index.d.ts +4 -0
  8. package/esm/typings/_packages/remote-server.index.d.ts +3 -0
  9. package/esm/typings/_packages/types.index.d.ts +20 -0
  10. package/esm/typings/_packages/utils.index.d.ts +6 -0
  11. package/esm/typings/_packages/wizzard.index.d.ts +2 -0
  12. package/esm/typings/classes/PromptTemplatePipeline.d.ts +68 -0
  13. package/esm/typings/classes/PromptTemplatePipelineLibrary.d.ts +55 -0
  14. package/esm/typings/config.d.ts +10 -0
  15. package/esm/typings/conversion/_importPtp.d.ts +12 -0
  16. package/esm/typings/conversion/parseCommand.d.ts +6 -0
  17. package/esm/typings/conversion/parseCommand.test.d.ts +1 -0
  18. package/esm/typings/conversion/promptTemplatePipelineStringToJson.d.ts +12 -0
  19. package/esm/typings/conversion/promptTemplatePipelineStringToJson.test.d.ts +1 -0
  20. package/esm/typings/conversion/validatePromptTemplatePipelineJson.d.ts +26 -0
  21. package/esm/typings/conversion/validatePromptTemplatePipelineJson.test.d.ts +1 -0
  22. package/esm/typings/execution/CommonExecutionToolsOptions.d.ts +6 -0
  23. package/esm/typings/execution/ExecutionTools.d.ts +25 -0
  24. package/esm/typings/execution/NaturalExecutionTools.d.ts +22 -0
  25. package/esm/typings/execution/PromptResult.d.ts +38 -0
  26. package/esm/typings/execution/PtpExecutor.d.ts +19 -0
  27. package/esm/typings/execution/ScriptExecutionTools.d.ts +34 -0
  28. package/esm/typings/execution/UserInterfaceTools.d.ts +30 -0
  29. package/esm/typings/execution/createPtpExecutor.d.ts +18 -0
  30. package/esm/typings/execution/plugins/natural-execution-tools/mocked/MockedEchoNaturalExecutionTools.d.ts +22 -0
  31. package/esm/typings/execution/plugins/natural-execution-tools/mocked/mocked-chat.test.d.ts +4 -0
  32. package/esm/typings/execution/plugins/natural-execution-tools/mocked/mocked-completion.test.d.ts +4 -0
  33. package/esm/typings/execution/plugins/natural-execution-tools/openai/OpenAiExecutionTools.d.ts +27 -0
  34. package/esm/typings/execution/plugins/natural-execution-tools/openai/OpenAiExecutionToolsOptions.d.ts +11 -0
  35. package/esm/typings/execution/plugins/natural-execution-tools/remote/RemoteNaturalExecutionTools.d.ts +35 -0
  36. package/esm/typings/execution/plugins/natural-execution-tools/remote/RemoteNaturalExecutionToolsOptions.d.ts +16 -0
  37. package/esm/typings/execution/plugins/natural-execution-tools/remote/createRemoteServer.d.ts +16 -0
  38. package/esm/typings/execution/plugins/natural-execution-tools/remote/interfaces/Ptps_Error.d.ts +3 -0
  39. package/esm/typings/execution/plugins/natural-execution-tools/remote/interfaces/Ptps_Progress.d.ts +4 -0
  40. package/esm/typings/execution/plugins/natural-execution-tools/remote/interfaces/Ptps_Request.d.ts +6 -0
  41. package/esm/typings/execution/plugins/natural-execution-tools/remote/interfaces/Ptps_Response.d.ts +4 -0
  42. package/esm/typings/execution/plugins/natural-execution-tools/remote/interfaces/RemoteServerOptions.d.ts +20 -0
  43. package/esm/typings/execution/plugins/script-execution-tools/javascript/JavascriptEvalExecutionTools.d.ts +19 -0
  44. package/esm/typings/execution/plugins/script-execution-tools/javascript/JavascriptEvalExecutionTools.test.d.ts +4 -0
  45. package/esm/typings/execution/plugins/script-execution-tools/javascript/JavascriptExecutionTools.d.ts +20 -0
  46. package/esm/typings/execution/plugins/script-execution-tools/javascript/utils/preserve.d.ts +11 -0
  47. package/esm/typings/execution/plugins/script-execution-tools/postprocessing.test.d.ts +4 -0
  48. package/esm/typings/execution/plugins/script-execution-tools/python/PythonExecutionTools.d.ts +15 -0
  49. package/esm/typings/execution/plugins/script-execution-tools/script-execution-errors.test.d.ts +1 -0
  50. package/esm/typings/execution/plugins/script-execution-tools/script-execution-tools.test.d.ts +1 -0
  51. package/esm/typings/execution/plugins/script-execution-tools/typescript/TypescriptExecutionTools.d.ts +15 -0
  52. package/esm/typings/execution/plugins/user-interface-execution-tools/callback/CallbackInterfaceTools.d.ts +14 -0
  53. package/esm/typings/execution/plugins/user-interface-execution-tools/callback/CallbackInterfaceToolsOptions.d.ts +12 -0
  54. package/esm/typings/execution/plugins/user-interface-execution-tools/simple-prompt/SimplePromptInterfaceTools.d.ts +16 -0
  55. package/esm/typings/execution/plugins/user-interface-execution-tools/user-interface-execution-tools.test.d.ts +1 -0
  56. package/esm/typings/types/Command.d.ts +65 -0
  57. package/esm/typings/types/ExecutionTypes.d.ts +13 -0
  58. package/esm/typings/types/ModelRequirements.d.ts +28 -0
  59. package/esm/typings/types/Parameters.d.ts +14 -0
  60. package/esm/typings/types/Prompt.d.ts +35 -0
  61. package/esm/typings/types/PromptTemplatePipelineJson/PromptTemplateJson.d.ts +82 -0
  62. package/esm/typings/types/PromptTemplatePipelineJson/PromptTemplateParameterJson.d.ts +23 -0
  63. package/esm/typings/types/PromptTemplatePipelineJson/PromptTemplatePipelineJson.d.ts +56 -0
  64. package/esm/typings/types/PromptTemplatePipelineString.d.ts +14 -0
  65. package/esm/typings/types/ScriptLanguage.d.ts +9 -0
  66. package/esm/typings/types/TaskProgress.d.ts +12 -0
  67. package/esm/typings/types/typeAliasEmoji.d.ts +9 -0
  68. package/esm/typings/types/typeAliases.d.ts +477 -0
  69. package/esm/typings/utils/emojis.d.ts +16 -0
  70. package/esm/typings/utils/just.d.ts +10 -0
  71. package/esm/typings/utils/markdown/extractAllListItemsFromMarkdown.d.ts +15 -0
  72. package/esm/typings/utils/markdown/extractAllListItemsFromMarkdown.test.d.ts +1 -0
  73. package/esm/typings/utils/markdown/extractBlocksFromMarkdown.d.ts +13 -0
  74. package/esm/typings/utils/markdown/extractBlocksFromMarkdown.test.d.ts +1 -0
  75. package/esm/typings/utils/markdown/extractOneBlockFromMarkdown.d.ts +16 -0
  76. package/esm/typings/utils/markdown/extractOneBlockFromMarkdown.test.d.ts +1 -0
  77. package/esm/typings/utils/markdown/removeContentComments.d.ts +8 -0
  78. package/esm/typings/utils/markdown/removeContentComments.test.d.ts +1 -0
  79. package/esm/typings/utils/markdown/removeMarkdownFormatting.d.ts +8 -0
  80. package/esm/typings/utils/markdown/removeMarkdownFormatting.test.d.ts +1 -0
  81. package/esm/typings/utils/markdown-json/MarkdownStructure.d.ts +25 -0
  82. package/esm/typings/utils/markdown-json/countMarkdownStructureDeepness.d.ts +7 -0
  83. package/esm/typings/utils/markdown-json/countMarkdownStructureDeepness.test.d.ts +1 -0
  84. package/esm/typings/utils/markdown-json/markdownToMarkdownStructure.d.ts +13 -0
  85. package/esm/typings/utils/markdown-json/markdownToMarkdownStructure.test.d.ts +1 -0
  86. package/esm/typings/utils/removeEmojis.d.ts +7 -0
  87. package/esm/typings/utils/removeEmojis.test.d.ts +1 -0
  88. package/esm/typings/utils/removeQuotes.d.ts +13 -0
  89. package/esm/typings/utils/removeQuotes.test.d.ts +1 -0
  90. package/esm/typings/utils/replaceParameters.d.ts +16 -0
  91. package/esm/typings/utils/replaceParameters.test.d.ts +1 -0
  92. package/esm/typings/utils/unwrapResult.d.ts +13 -0
  93. package/esm/typings/utils/unwrapResult.test.d.ts +1 -0
  94. package/esm/typings/wizzard/Wizzard.d.ts +1 -0
  95. package/esm/typings/wizzard/sample.d.ts +5 -0
  96. package/package.json +43 -0
  97. package/umd/index.umd.js +1423 -0
  98. package/umd/index.umd.js.map +1 -0
  99. package/umd/typings/_packages/core.index.d.ts +17 -0
  100. package/umd/typings/_packages/execute-javascript.index.d.ts +3 -0
  101. package/umd/typings/_packages/openai.index.d.ts +3 -0
  102. package/umd/typings/_packages/remote-client.index.d.ts +4 -0
  103. package/umd/typings/_packages/remote-server.index.d.ts +3 -0
  104. package/umd/typings/_packages/types.index.d.ts +20 -0
  105. package/umd/typings/_packages/utils.index.d.ts +6 -0
  106. package/umd/typings/_packages/wizzard.index.d.ts +2 -0
  107. package/umd/typings/classes/PromptTemplatePipeline.d.ts +68 -0
  108. package/umd/typings/classes/PromptTemplatePipelineLibrary.d.ts +55 -0
  109. package/umd/typings/config.d.ts +10 -0
  110. package/umd/typings/conversion/_importPtp.d.ts +12 -0
  111. package/umd/typings/conversion/parseCommand.d.ts +6 -0
  112. package/umd/typings/conversion/parseCommand.test.d.ts +1 -0
  113. package/umd/typings/conversion/promptTemplatePipelineStringToJson.d.ts +12 -0
  114. package/umd/typings/conversion/promptTemplatePipelineStringToJson.test.d.ts +1 -0
  115. package/umd/typings/conversion/validatePromptTemplatePipelineJson.d.ts +26 -0
  116. package/umd/typings/conversion/validatePromptTemplatePipelineJson.test.d.ts +1 -0
  117. package/umd/typings/execution/CommonExecutionToolsOptions.d.ts +6 -0
  118. package/umd/typings/execution/ExecutionTools.d.ts +25 -0
  119. package/umd/typings/execution/NaturalExecutionTools.d.ts +22 -0
  120. package/umd/typings/execution/PromptResult.d.ts +38 -0
  121. package/umd/typings/execution/PtpExecutor.d.ts +19 -0
  122. package/umd/typings/execution/ScriptExecutionTools.d.ts +34 -0
  123. package/umd/typings/execution/UserInterfaceTools.d.ts +30 -0
  124. package/umd/typings/execution/createPtpExecutor.d.ts +18 -0
  125. package/umd/typings/execution/plugins/natural-execution-tools/mocked/MockedEchoNaturalExecutionTools.d.ts +22 -0
  126. package/umd/typings/execution/plugins/natural-execution-tools/mocked/mocked-chat.test.d.ts +4 -0
  127. package/umd/typings/execution/plugins/natural-execution-tools/mocked/mocked-completion.test.d.ts +4 -0
  128. package/umd/typings/execution/plugins/natural-execution-tools/openai/OpenAiExecutionTools.d.ts +27 -0
  129. package/umd/typings/execution/plugins/natural-execution-tools/openai/OpenAiExecutionToolsOptions.d.ts +11 -0
  130. package/umd/typings/execution/plugins/natural-execution-tools/remote/RemoteNaturalExecutionTools.d.ts +35 -0
  131. package/umd/typings/execution/plugins/natural-execution-tools/remote/RemoteNaturalExecutionToolsOptions.d.ts +16 -0
  132. package/umd/typings/execution/plugins/natural-execution-tools/remote/createRemoteServer.d.ts +16 -0
  133. package/umd/typings/execution/plugins/natural-execution-tools/remote/interfaces/Ptps_Error.d.ts +3 -0
  134. package/umd/typings/execution/plugins/natural-execution-tools/remote/interfaces/Ptps_Progress.d.ts +4 -0
  135. package/umd/typings/execution/plugins/natural-execution-tools/remote/interfaces/Ptps_Request.d.ts +6 -0
  136. package/umd/typings/execution/plugins/natural-execution-tools/remote/interfaces/Ptps_Response.d.ts +4 -0
  137. package/umd/typings/execution/plugins/natural-execution-tools/remote/interfaces/RemoteServerOptions.d.ts +20 -0
  138. package/umd/typings/execution/plugins/script-execution-tools/javascript/JavascriptEvalExecutionTools.d.ts +19 -0
  139. package/umd/typings/execution/plugins/script-execution-tools/javascript/JavascriptEvalExecutionTools.test.d.ts +4 -0
  140. package/umd/typings/execution/plugins/script-execution-tools/javascript/JavascriptExecutionTools.d.ts +20 -0
  141. package/umd/typings/execution/plugins/script-execution-tools/javascript/utils/preserve.d.ts +11 -0
  142. package/umd/typings/execution/plugins/script-execution-tools/postprocessing.test.d.ts +4 -0
  143. package/umd/typings/execution/plugins/script-execution-tools/python/PythonExecutionTools.d.ts +15 -0
  144. package/umd/typings/execution/plugins/script-execution-tools/script-execution-errors.test.d.ts +1 -0
  145. package/umd/typings/execution/plugins/script-execution-tools/script-execution-tools.test.d.ts +1 -0
  146. package/umd/typings/execution/plugins/script-execution-tools/typescript/TypescriptExecutionTools.d.ts +15 -0
  147. package/umd/typings/execution/plugins/user-interface-execution-tools/callback/CallbackInterfaceTools.d.ts +14 -0
  148. package/umd/typings/execution/plugins/user-interface-execution-tools/callback/CallbackInterfaceToolsOptions.d.ts +12 -0
  149. package/umd/typings/execution/plugins/user-interface-execution-tools/simple-prompt/SimplePromptInterfaceTools.d.ts +16 -0
  150. package/umd/typings/execution/plugins/user-interface-execution-tools/user-interface-execution-tools.test.d.ts +1 -0
  151. package/umd/typings/types/Command.d.ts +65 -0
  152. package/umd/typings/types/ExecutionTypes.d.ts +13 -0
  153. package/umd/typings/types/ModelRequirements.d.ts +28 -0
  154. package/umd/typings/types/Parameters.d.ts +14 -0
  155. package/umd/typings/types/Prompt.d.ts +35 -0
  156. package/umd/typings/types/PromptTemplatePipelineJson/PromptTemplateJson.d.ts +82 -0
  157. package/umd/typings/types/PromptTemplatePipelineJson/PromptTemplateParameterJson.d.ts +23 -0
  158. package/umd/typings/types/PromptTemplatePipelineJson/PromptTemplatePipelineJson.d.ts +56 -0
  159. package/umd/typings/types/PromptTemplatePipelineString.d.ts +14 -0
  160. package/umd/typings/types/ScriptLanguage.d.ts +9 -0
  161. package/umd/typings/types/TaskProgress.d.ts +12 -0
  162. package/umd/typings/types/typeAliasEmoji.d.ts +9 -0
  163. package/umd/typings/types/typeAliases.d.ts +477 -0
  164. package/umd/typings/utils/emojis.d.ts +16 -0
  165. package/umd/typings/utils/just.d.ts +10 -0
  166. package/umd/typings/utils/markdown/extractAllListItemsFromMarkdown.d.ts +15 -0
  167. package/umd/typings/utils/markdown/extractAllListItemsFromMarkdown.test.d.ts +1 -0
  168. package/umd/typings/utils/markdown/extractBlocksFromMarkdown.d.ts +13 -0
  169. package/umd/typings/utils/markdown/extractBlocksFromMarkdown.test.d.ts +1 -0
  170. package/umd/typings/utils/markdown/extractOneBlockFromMarkdown.d.ts +16 -0
  171. package/umd/typings/utils/markdown/extractOneBlockFromMarkdown.test.d.ts +1 -0
  172. package/umd/typings/utils/markdown/removeContentComments.d.ts +8 -0
  173. package/umd/typings/utils/markdown/removeContentComments.test.d.ts +1 -0
  174. package/umd/typings/utils/markdown/removeMarkdownFormatting.d.ts +8 -0
  175. package/umd/typings/utils/markdown/removeMarkdownFormatting.test.d.ts +1 -0
  176. package/umd/typings/utils/markdown-json/MarkdownStructure.d.ts +25 -0
  177. package/umd/typings/utils/markdown-json/countMarkdownStructureDeepness.d.ts +7 -0
  178. package/umd/typings/utils/markdown-json/countMarkdownStructureDeepness.test.d.ts +1 -0
  179. package/umd/typings/utils/markdown-json/markdownToMarkdownStructure.d.ts +13 -0
  180. package/umd/typings/utils/markdown-json/markdownToMarkdownStructure.test.d.ts +1 -0
  181. package/umd/typings/utils/removeEmojis.d.ts +7 -0
  182. package/umd/typings/utils/removeEmojis.test.d.ts +1 -0
  183. package/umd/typings/utils/removeQuotes.d.ts +13 -0
  184. package/umd/typings/utils/removeQuotes.test.d.ts +1 -0
  185. package/umd/typings/utils/replaceParameters.d.ts +16 -0
  186. package/umd/typings/utils/replaceParameters.test.d.ts +1 -0
  187. package/umd/typings/utils/unwrapResult.d.ts +13 -0
  188. package/umd/typings/utils/unwrapResult.test.d.ts +1 -0
  189. package/umd/typings/wizzard/Wizzard.d.ts +1 -0
  190. package/umd/typings/wizzard/sample.d.ts +5 -0
@@ -0,0 +1,22 @@
1
+ import { Prompt } from '../../../../types/Prompt';
2
+ import { CommonExecutionToolsOptions } from '../../../CommonExecutionToolsOptions';
3
+ import { NaturalExecutionTools } from '../../../NaturalExecutionTools';
4
+ import { PromptChatResult, PromptCompletionResult } from '../../../PromptResult';
5
+ /**
6
+ * Mocked execution Tools for just echoing the requests for testing purposes.
7
+ */
8
+ export declare class MockedEchoNaturalExecutionTools implements NaturalExecutionTools {
9
+ private readonly options;
10
+ constructor(options: CommonExecutionToolsOptions);
11
+ /**
12
+ * Mocks chat model
13
+ */
14
+ gptChat(prompt: Prompt): Promise<PromptChatResult>;
15
+ /**
16
+ * Mocks completion model
17
+ */
18
+ gptComplete(prompt: Prompt): Promise<PromptCompletionResult>;
19
+ }
20
+ /**
21
+ * TODO: Allow in spaceTrim: nesting with > ${block(prompt.request)}
22
+ */
@@ -0,0 +1,4 @@
1
+ export {};
2
+ /**
3
+ * TODO: [🧠] What should be name of this test "MockedEchoExecutionTools.test.ts" or "createPtpExecutor.test.ts"
4
+ */
@@ -0,0 +1,4 @@
1
+ export {};
2
+ /**
3
+ * TODO: [🧠] What should be name of this test "MockedEchoExecutionTools.test.ts" or "createPtpExecutor.test.ts"
4
+ */
@@ -0,0 +1,27 @@
1
+ import { Prompt } from '../../../../types/Prompt';
2
+ import { NaturalExecutionTools } from '../../../NaturalExecutionTools';
3
+ import { PromptChatResult, PromptCompletionResult } from '../../../PromptResult';
4
+ import { OpenAiExecutionToolsOptions } from './OpenAiExecutionToolsOptions';
5
+ /**
6
+ * Execution Tools for calling OpenAI API.
7
+ */
8
+ export declare class OpenAiExecutionTools implements NaturalExecutionTools {
9
+ private readonly options;
10
+ /**
11
+ * OpenAI API client.
12
+ */
13
+ private readonly openai;
14
+ constructor(options: OpenAiExecutionToolsOptions);
15
+ /**
16
+ * Calls OpenAI API to use a chat model.
17
+ */
18
+ gptChat(prompt: Prompt): Promise<PromptChatResult>;
19
+ /**
20
+ * Calls OpenAI API to use a complete model.
21
+ */
22
+ gptComplete(prompt: Prompt): Promise<PromptCompletionResult>;
23
+ }
24
+ /**
25
+ * TODO: Maybe Create some common util for gptChat and gptComplete
26
+ * TODO: Maybe make custom OpenaiError
27
+ */
@@ -0,0 +1,11 @@
1
+ import { string_token } from '../../../.././types/typeAliases';
2
+ import { CommonExecutionToolsOptions } from '../../../CommonExecutionToolsOptions';
3
+ /**
4
+ * Options for OpenAiExecutionTools
5
+ */
6
+ export interface OpenAiExecutionToolsOptions extends CommonExecutionToolsOptions {
7
+ /**
8
+ * OpenAI API key
9
+ */
10
+ openAiApiKey: string_token;
11
+ }
@@ -0,0 +1,35 @@
1
+ import { Prompt } from '../../../../types/Prompt';
2
+ import { NaturalExecutionTools } from '../../../NaturalExecutionTools';
3
+ import { PromptChatResult, PromptCompletionResult } from '../../../PromptResult';
4
+ import { RemoteNaturalExecutionToolsOptions } from './RemoteNaturalExecutionToolsOptions';
5
+ /**
6
+ * Remote server is a proxy server that uses its execution tools internally and exposes the executor interface externally.
7
+ *
8
+ * You can simply use `RemoteExecutionTools` on client-side javascript and connect to your remote server.
9
+ * This is useful to make all logic on browser side but not expose your API keys or no need to use customer's GPU.
10
+ *
11
+ * @see https://github.com/webgptorg/promptbook#remote-server
12
+ */
13
+ export declare class RemoteNaturalExecutionTools implements NaturalExecutionTools {
14
+ private readonly options;
15
+ constructor(options: RemoteNaturalExecutionToolsOptions);
16
+ /**
17
+ * Creates a connection to the remote proxy server.
18
+ */
19
+ private makeConnection;
20
+ /**
21
+ * Calls remote proxy server to use a chat model.
22
+ */
23
+ gptChat(prompt: Prompt): Promise<PromptChatResult>;
24
+ /**
25
+ * Calls remote proxy server to use a completion model.
26
+ */
27
+ gptComplete(prompt: Prompt): Promise<PromptCompletionResult>;
28
+ /**
29
+ * Calls remote proxy server to use both completion or chat model.
30
+ */
31
+ private gptCommon;
32
+ }
33
+ /**
34
+ * TODO: [🤹‍♂️] RemoteNaturalExecutionTools should extend Destroyable and implement IDestroyable
35
+ */
@@ -0,0 +1,16 @@
1
+ import { uuid } from '../../../.././types/typeAliases';
2
+ import { CommonExecutionToolsOptions } from '../../../CommonExecutionToolsOptions';
3
+ /**
4
+ * Options for RemoteNaturalExecutionTools
5
+ */
6
+ export interface RemoteNaturalExecutionToolsOptions extends CommonExecutionToolsOptions {
7
+ /**
8
+ * URL of the remote PTP server
9
+ * On this server will be connected to the socket.io server
10
+ */
11
+ readonly remoteUrl: URL;
12
+ /**
13
+ * Your client ID
14
+ */
15
+ readonly clientId: uuid;
16
+ }
@@ -0,0 +1,16 @@
1
+ import { RemoteServerOptions } from './interfaces/RemoteServerOptions';
2
+ /**
3
+ * Remote server is a proxy server that uses its execution tools internally and exposes the executor interface externally.
4
+ *
5
+ * You can simply use `RemoteExecutionTools` on client-side javascript and connect to your remote server.
6
+ * This is useful to make all logic on browser side but not expose your API keys or no need to use customer's GPU.
7
+ *
8
+ * @see https://github.com/webgptorg/promptbook#remote-server
9
+ */
10
+ export declare function createRemoteServer(options: RemoteServerOptions): void;
11
+ /**
12
+ * TODO: Handle progress - support streaming
13
+ * TODO: [🤹‍♂️] Do not hang up immediately but wait until client closes OR timeout
14
+ * TODO: [🤹‍♂️] Timeout on chat to free up resources
15
+ * TODO: [🃏] Pass here some security token to prevent DDoS
16
+ */
@@ -0,0 +1,3 @@
1
+ export interface Ptps_Error {
2
+ readonly errorMessage: string;
3
+ }
@@ -0,0 +1,4 @@
1
+ import { TaskProgress } from '../../../../../types/TaskProgress';
2
+ export interface Ptps_Progress {
3
+ readonly taskProgress: TaskProgress;
4
+ }
@@ -0,0 +1,6 @@
1
+ import { uuid } from '../../../../.././types/typeAliases';
2
+ import { Prompt } from '../../../../../types/Prompt';
3
+ export interface Ptps_Request {
4
+ readonly clientId: uuid;
5
+ readonly prompt: Prompt;
6
+ }
@@ -0,0 +1,4 @@
1
+ import { PromptResult } from '../../../../../execution/PromptResult';
2
+ export interface Ptps_Response {
3
+ promptResult: PromptResult;
4
+ }
@@ -0,0 +1,20 @@
1
+ import { PromptTemplatePipelineLibrary } from '../../../../../classes/PromptTemplatePipelineLibrary';
2
+ import { uuid } from '../../../../../types/typeAliases';
3
+ import { CommonExecutionToolsOptions } from '../../../../CommonExecutionToolsOptions';
4
+ import { NaturalExecutionTools } from '../../../../NaturalExecutionTools';
5
+ export interface RemoteServerOptions extends CommonExecutionToolsOptions {
6
+ /**
7
+ * Port on which the server will listen
8
+ */
9
+ readonly port: number;
10
+ /**
11
+ * Prompt template pipeline library to use
12
+ *
13
+ * This is used to checkl validity of the prompt to prevent DDoS
14
+ */
15
+ readonly ptpLibrary: PromptTemplatePipelineLibrary;
16
+ /**
17
+ * Creates natural execution tools for each client
18
+ */
19
+ createNaturalExecutionTools(clientId: uuid): NaturalExecutionTools;
20
+ }
@@ -0,0 +1,19 @@
1
+ import { CommonExecutionToolsOptions } from '../../../CommonExecutionToolsOptions';
2
+ import { ScriptExecutionTools, ScriptExecutionToolsExecuteOptions } from '../../../ScriptExecutionTools';
3
+ /**
4
+ * ScriptExecutionTools for JavaScript implemented via eval
5
+ *
6
+ * Warning: It is used for testing and mocking
7
+ * **NOT intended to use in the production** due to its unsafe nature, use `JavascriptExecutionTools` instead.
8
+ */
9
+ export declare class JavascriptEvalExecutionTools implements ScriptExecutionTools {
10
+ private readonly options;
11
+ constructor(options: CommonExecutionToolsOptions);
12
+ /**
13
+ * Executes a JavaScript
14
+ */
15
+ execute(options: ScriptExecutionToolsExecuteOptions): Promise<string>;
16
+ }
17
+ /**
18
+ * TODO: Put predefined functions (like removeQuotes, spaceTrim, etc.) into annotation OR pass into constructor
19
+ */
@@ -0,0 +1,4 @@
1
+ export {};
2
+ /**
3
+ * TODO: !! Make shared test between JavascriptEvalExecutionTools and JavascriptExecutionTools to test the same functionality when implemented via vm2
4
+ */
@@ -0,0 +1,20 @@
1
+ import { CommonExecutionToolsOptions } from '../../../CommonExecutionToolsOptions';
2
+ import { ScriptExecutionTools, ScriptExecutionToolsExecuteOptions } from '../../../ScriptExecutionTools';
3
+ /**
4
+ * ScriptExecutionTools for JavaScript implemented via vm2
5
+ *
6
+ * Warning: This is not implemented yet
7
+ */
8
+ export declare class JavascriptExecutionTools implements ScriptExecutionTools {
9
+ private readonly options;
10
+ constructor(options: CommonExecutionToolsOptions);
11
+ /**
12
+ * Executes a JavaScript
13
+ */
14
+ execute(options: ScriptExecutionToolsExecuteOptions): Promise<string>;
15
+ }
16
+ /**
17
+ * TODO: !! Pass isVerbose to constructor and use it
18
+ * TODO: !! Probbably make some common util createStatementToEvaluate
19
+ * TODO: !! Implement via vm2
20
+ */
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Does nothing, but preserves the function in the bundle
3
+ * Compiler is tricked into thinking the function is used
4
+ *
5
+ * @param value any function to preserve
6
+ * @returns nothing
7
+ */
8
+ export declare function preserve(func: (...params: Array<any>) => unknown): void;
9
+ /**
10
+ * TODO: !! [1] This maybe does memory leak
11
+ */
@@ -0,0 +1,4 @@
1
+ export {};
2
+ /**
3
+ * TODO: What is the ideal folder for this test?
4
+ */
@@ -0,0 +1,15 @@
1
+ import { CommonExecutionToolsOptions } from '../../../CommonExecutionToolsOptions';
2
+ import { ScriptExecutionTools, ScriptExecutionToolsExecuteOptions } from '../../../ScriptExecutionTools';
3
+ /**
4
+ * ScriptExecutionTools for Python
5
+ *
6
+ * Warning: This is not implemented yet
7
+ */
8
+ export declare class PythonExecutionTools implements ScriptExecutionTools {
9
+ private readonly options;
10
+ constructor(options: CommonExecutionToolsOptions);
11
+ /**
12
+ * Executes a Python
13
+ */
14
+ execute(options: ScriptExecutionToolsExecuteOptions): Promise<string>;
15
+ }
@@ -0,0 +1,15 @@
1
+ import { CommonExecutionToolsOptions } from '../../../CommonExecutionToolsOptions';
2
+ import { ScriptExecutionTools, ScriptExecutionToolsExecuteOptions } from '../../../ScriptExecutionTools';
3
+ /**
4
+ * ScriptExecutionTools for TypeScript
5
+ *
6
+ * Warning: This is not implemented yet
7
+ */
8
+ export declare class TypescriptExecutionTools implements ScriptExecutionTools {
9
+ private readonly options;
10
+ constructor(options: CommonExecutionToolsOptions);
11
+ /**
12
+ * Executes a TypeScript
13
+ */
14
+ execute(options: ScriptExecutionToolsExecuteOptions): Promise<string>;
15
+ }
@@ -0,0 +1,14 @@
1
+ import { UserInterfaceTools, UserInterfaceToolsPromptDialogOptions } from '../../../UserInterfaceTools';
2
+ import { CallbackInterfaceToolsOptions } from './CallbackInterfaceToolsOptions';
3
+ /**
4
+ * Delagates the user interaction to a async callback function
5
+ * You need to provide your own implementation of this callback function and its bind to UI.
6
+ */
7
+ export declare class CallbackInterfaceTools implements UserInterfaceTools {
8
+ private readonly options;
9
+ constructor(options: CallbackInterfaceToolsOptions);
10
+ /**
11
+ * Trigger the custom callback function
12
+ */
13
+ promptDialog(options: UserInterfaceToolsPromptDialogOptions): Promise<string>;
14
+ }
@@ -0,0 +1,12 @@
1
+ import { Promisable } from 'type-fest';
2
+ import { CommonExecutionToolsOptions } from '../../../CommonExecutionToolsOptions';
3
+ import { UserInterfaceToolsPromptDialogOptions } from '../../../UserInterfaceTools';
4
+ /**
5
+ * Options for CallbackInterfaceTools
6
+ */
7
+ export interface CallbackInterfaceToolsOptions extends CommonExecutionToolsOptions {
8
+ /**
9
+ * The callback function to be called when promptDialog is called
10
+ */
11
+ callback(prompt: UserInterfaceToolsPromptDialogOptions): Promisable<string>;
12
+ }
@@ -0,0 +1,16 @@
1
+ import { CommonExecutionToolsOptions } from '../../../CommonExecutionToolsOptions';
2
+ import { UserInterfaceTools, UserInterfaceToolsPromptDialogOptions } from '../../../UserInterfaceTools';
3
+ /**
4
+ * Wrapper around `window.prompt` synchronous function that interacts with the user via browser prompt
5
+ *
6
+ * Warning: It is used for testing and mocking
7
+ * **NOT intended to use in the production** due to its synchronous nature.
8
+ */
9
+ export declare class SimplePromptInterfaceTools implements UserInterfaceTools {
10
+ private readonly options;
11
+ constructor(options: CommonExecutionToolsOptions);
12
+ /**
13
+ * Trigger window.prompt dialog
14
+ */
15
+ promptDialog(options: UserInterfaceToolsPromptDialogOptions): Promise<string>;
16
+ }
@@ -0,0 +1,65 @@
1
+ import { string_markdown_text, string_name, string_version } from '.././types/typeAliases';
2
+ import { ExecutionType } from './ExecutionTypes';
3
+ import { ModelRequirements } from './ModelRequirements';
4
+ /**
5
+ * Command is one piece of the prompt template which adds some logic to the prompt template or the whole pipeline.
6
+ * It is parsed from the markdown from ul/ol items - one command per one item.
7
+ */
8
+ export type Command = PtpUrlCommand | PtpVersionCommand | ExecuteCommand | UseCommand | ParameterCommand | PostprocessCommand;
9
+ /**
10
+ * PtpVersion command tells which version is .ptp file using
11
+ *
12
+ * - It is used for backward compatibility
13
+ * - It is defined per whole .ptp file in the header
14
+ */
15
+ export interface PtpUrlCommand {
16
+ readonly type: 'PTP_URL';
17
+ readonly ptpUrl: URL;
18
+ }
19
+ /**
20
+ * PtpVersion command tells which version is .ptp file using
21
+ *
22
+ * - It is used for backward compatibility
23
+ * - It is defined per whole .ptp file in the header
24
+ */
25
+ export interface PtpVersionCommand {
26
+ readonly type: 'PTP_VERSION';
27
+ readonly ptpVersion: string_version;
28
+ }
29
+ /**
30
+ * Execute command tells how to execute the section
31
+ * It can be either prompt template, script or simple template etc.
32
+ */
33
+ export interface ExecuteCommand {
34
+ readonly type: 'EXECUTE';
35
+ readonly executionType: ExecutionType;
36
+ }
37
+ /**
38
+ * Use command tells which model and modelRequirements to use for the prompt template. execution
39
+ */
40
+ export interface UseCommand {
41
+ readonly type: 'USE';
42
+ readonly key: keyof ModelRequirements;
43
+ readonly value: any;
44
+ }
45
+ /**
46
+ * Parameter command describes one parameter of the prompt template
47
+ *
48
+ * - It can tell if it is input or output parameter
49
+ * - It can have description
50
+ * - In description it can have simple formatting BUT not markdown structure or reference to other parameters
51
+ */
52
+ export interface ParameterCommand {
53
+ readonly type: 'PARAMETER';
54
+ readonly isInputParameter: boolean;
55
+ readonly parameterName: string_name;
56
+ readonly parameterDescription: string_markdown_text | null;
57
+ }
58
+ /**
59
+ * Postprocess command describes which function to use for postprocessing
60
+ * This will be created as separate execute script block bellow
61
+ */
62
+ export interface PostprocessCommand {
63
+ readonly type: 'POSTPROCESS';
64
+ readonly functionName: string_name;
65
+ }
@@ -0,0 +1,13 @@
1
+ import { TupleToUnion } from 'type-fest';
2
+ /**
3
+ * Execution type describes the way how the block is executed
4
+ *
5
+ * @see https://github.com/webgptorg/promptbook#execution-type
6
+ */
7
+ export type ExecutionType = TupleToUnion<typeof ExecutionTypes>;
8
+ /**
9
+ * Execution type describes the way how the block is executed
10
+ *
11
+ * @see https://github.com/webgptorg/promptbook#execution-type
12
+ */
13
+ export declare const ExecutionTypes: readonly ["PROMPT_TEMPLATE", "SIMPLE_TEMPLATE", "SCRIPT", "PROMPT_DIALOG"];
@@ -0,0 +1,28 @@
1
+ export declare const MODEL_VARIANTS: readonly ["COMPLETION", "CHAT"];
2
+ /**
3
+ * Model variant describes the very general type of the model
4
+ *
5
+ * There are two variants:
6
+ * - **COMPLETION** - model that takes prompt and writes the rest of the text
7
+ * - **CHAT** - model that takes prompt and previous messages and returns response
8
+ */
9
+ export type ModelVariant = (typeof MODEL_VARIANTS)[number];
10
+ /**
11
+ * Abstract way to specify the LLM. It does not specify the LLM with concrete version itself, only the requirements for the LLM.
12
+ *
13
+ * @see https://github.com/webgptorg/promptbook#model-requirements
14
+ */
15
+ export interface ModelRequirements {
16
+ /**
17
+ * Model variant describes the very general type of the model
18
+ *
19
+ * There are two variants:
20
+ * - **COMPLETION** - model that takes prompt and writes the rest of the text
21
+ * - **CHAT** - model that takes prompt and previous messages and returns response
22
+ */
23
+ readonly variant: ModelVariant;
24
+ }
25
+ /**
26
+ * TODO: Maybe figure out better word than "variant"
27
+ * TODO: Add here more requirement options like max context size, max tokens, etc.
28
+ */
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Parameters of the prompt template (pipeline)
3
+ *
4
+ * There are three types of parameters:
5
+ * - **Input parameters** are required to execute the prompt template pipeline.
6
+ * - **Intermediate parameters** are used internally in the prompt template pipeline.
7
+ * - **Output parameters** are not used internally in the prompt template pipeline, but are returned as the result of the prompt template pipeline execution.
8
+ *
9
+ * @see https://github.com/webgptorg/promptbook#parameters
10
+ */
11
+ export type Parameters = object;
12
+ /**
13
+ * TODO: Constrain type to Simple key-value object, only string keys and string values and no index signature + only camelCase keys and spaceTrimmed values
14
+ */
@@ -0,0 +1,35 @@
1
+ import { string_name, string_prompt, string_ptp_url_with_hashtemplate } from '.././types/typeAliases';
2
+ import { ModelRequirements } from './ModelRequirements';
3
+ /**
4
+ * Prompt in a text along with model requirements, but without any execution or templating logic.
5
+ *
6
+ * @see https://github.com/webgptorg/promptbook#prompt
7
+ */
8
+ export interface Prompt {
9
+ /**
10
+ * The text of the prompt
11
+ *
12
+ * Note: This is not a template, this is exactly the text that will be sent to the model
13
+ * @example "What is the capital of France?"
14
+ */
15
+ readonly content: string_prompt;
16
+ /**
17
+ * Requirements for the model
18
+ */
19
+ readonly modelRequirements: ModelRequirements;
20
+ /**
21
+ * Unique identifier of the prompt template pipeline with specific template name as hash
22
+ *
23
+ * @example https://ptp.webgpt.com/cs/write-wallpaper-content.ptp.md@v2.4.15#keywords
24
+ */
25
+ readonly ptpUrl: string_ptp_url_with_hashtemplate;
26
+ /**
27
+ * Parameters used in the prompt
28
+ *
29
+ * Note: This is redundant (same information is in ptpUrl+content) but useful for logging and debugging
30
+ */
31
+ readonly parameters: Record<string_name, string>;
32
+ }
33
+ /**
34
+ * TODO: [✔] Check ModelRequirements in runtime
35
+ */
@@ -0,0 +1,82 @@
1
+ import { string_javascript, string_markdown, string_name, string_prompt, string_template } from '../.././types/typeAliases';
2
+ import { ExecutionType } from '../ExecutionTypes';
3
+ import { ModelRequirements } from '../ModelRequirements';
4
+ import { ScriptLanguage } from '../ScriptLanguage';
5
+ /**
6
+ * Describes one prompt template in the prompt template pipeline
7
+ */
8
+ export type PromptTemplateJson = NaturalTemplateJson | SimpleTemplateJson | ScriptTemplateJson | PromptDialogJson;
9
+ /**
10
+ * Template for prompt to LLM
11
+ */
12
+ interface NaturalTemplateJson extends PromptTemplateJsonCommon {
13
+ readonly executionType: 'PROMPT_TEMPLATE';
14
+ /**
15
+ * Requirements for the model
16
+ * - This is required only for executionType PROMPT_TEMPLATE
17
+ */
18
+ readonly modelRequirements?: ModelRequirements;
19
+ }
20
+ /**
21
+ * Template for simple concatenation of strings
22
+ */
23
+ interface SimpleTemplateJson extends PromptTemplateJsonCommon {
24
+ readonly executionType: 'SIMPLE_TEMPLATE';
25
+ }
26
+ /**
27
+ * Template for script execution
28
+ */
29
+ interface ScriptTemplateJson extends PromptTemplateJsonCommon {
30
+ readonly executionType: 'SCRIPT';
31
+ /**
32
+ * Language of the script
33
+ * - This is required only for executionType SCRIPT
34
+ *
35
+ */
36
+ readonly contentLanguage?: ScriptLanguage;
37
+ }
38
+ /**
39
+ * Template for prompt to user
40
+ */
41
+ interface PromptDialogJson extends PromptTemplateJsonCommon {
42
+ readonly executionType: 'PROMPT_DIALOG';
43
+ }
44
+ /**
45
+ * Common properties of all prompt templates
46
+ */
47
+ interface PromptTemplateJsonCommon {
48
+ /**
49
+ * Name of the template
50
+ * - It must be unique across the pipeline
51
+ * - It should start uppercase and contain letters and numbers
52
+ * - The ptpUrl together with hash and name are used to identify the prompt template in the pipeline
53
+ */
54
+ readonly name: string_name;
55
+ /**
56
+ * Title of the prompt template
57
+ * It can use simple markdown formatting like **bold**, *italic*, [link](https://example.com), ... BUT not code blocks and structure
58
+ */
59
+ readonly title: string;
60
+ /**
61
+ * Description of the prompt template
62
+ * It can use multiple paragraphs of simple markdown formatting like **bold**, *italic*, [link](https://example.com), ... BUT not code blocks and structure
63
+ */
64
+ readonly description?: string;
65
+ /**
66
+ * Type of the execution
67
+ * This determines if the prompt template is send to LLM, user or some scripting evaluation
68
+ */
69
+ readonly executionType: ExecutionType;
70
+ /**
71
+ * Content of the template with {placeholders} for parameters
72
+ */
73
+ readonly content: (string_prompt | string_javascript | string_markdown) & string_template;
74
+ /**
75
+ * Name of the parameter that is the result of the prompt template
76
+ */
77
+ readonly resultingParameterName: string;
78
+ }
79
+ export {};
80
+ /**
81
+ * TODO: use one helper type> (string_prompt | string_javascript | string_markdown) & string_template
82
+ */
@@ -0,0 +1,23 @@
1
+ import { string_name } from '../.././types/typeAliases';
2
+ /**
3
+ * Describes one parameter of the prompt template pipeline
4
+ */
5
+ export interface PromptTemplateParameterJson {
6
+ /**
7
+ * Name of the parameter
8
+ * - It must be unique across the pipeline
9
+ * - It should start lowercase and contain letters and numbers
10
+ */
11
+ readonly name: string_name;
12
+ /**
13
+ * The parameter is input of the pipeline
14
+ *
15
+ * Note: Output parameter is every parameter including input one
16
+ */
17
+ readonly isInput: boolean;
18
+ /**
19
+ * Description of the parameter
20
+ * - It can use simple markdown formatting like **bold**, *italic*, [link](https://example.com), ... BUT not code blocks and structure
21
+ */
22
+ readonly description?: string;
23
+ }