@promptbook/remote-client 0.112.0-72 → 0.112.0-79

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 (214) hide show
  1. package/README.md +9 -9
  2. package/esm/index.es.js +310 -204
  3. package/esm/index.es.js.map +1 -1
  4. package/esm/src/avatars/types/AvatarVisualDefinition.d.ts +1 -1
  5. package/esm/src/avatars/visuals/octopus3d2AvatarVisual.d.ts +7 -0
  6. package/esm/src/avatars/visuals/octopus3dAvatarVisualShared.d.ts +37 -0
  7. package/esm/src/book-components/Chat/save/_common/chatExportRendering.d.ts +75 -0
  8. package/esm/src/book-components/Chat/save/_common/getPromptbookExportBranding.d.ts +18 -0
  9. package/esm/src/book-components/Chat/save/html/htmlSaveFormatDefinition.d.ts +13 -1
  10. package/esm/src/book-components/Chat/save/html/htmlSaveFormatDefinition.test.d.ts +1 -0
  11. package/esm/src/book-components/Chat/save/index.d.ts +5 -5
  12. package/esm/src/book-components/Chat/save/markdown/mdSaveFormatDefinition.d.ts +5 -3
  13. package/esm/src/book-components/Chat/save/markdown/mdSaveFormatDefinition.test.d.ts +1 -0
  14. package/esm/src/book-components/Chat/save/pdf/buildChatPdf.d.ts +4 -3
  15. package/esm/src/book-components/Chat/save/pdf/pdfSaveFormatDefinition.d.ts +3 -3
  16. package/esm/src/book-components/Chat/save/pdf/pdfSaveFormatDefinition.test.d.ts +1 -0
  17. package/esm/src/book-components/Chat/save/react/reactSaveFormatDefinition.test.d.ts +1 -0
  18. package/esm/src/book-components/Chat/utils/renderMarkdown.d.ts +26 -0
  19. package/esm/src/cli/cli-commands/agent/agentProjectPaths.d.ts +8 -8
  20. package/esm/src/cli/cli-commands/agent/agentRunCliOptions.d.ts +2 -0
  21. package/esm/src/cli/cli-commands/agent/initializeAgentRunnerCommand.d.ts +1 -0
  22. package/esm/src/cli/cli-commands/agents-server/buildAgentsServer.d.ts +56 -0
  23. package/esm/src/cli/cli-commands/agents-server/buildAgentsServer.test.d.ts +1 -0
  24. package/esm/src/cli/cli-commands/agents-server/ensureAgentsServerEnvFile.d.ts +7 -0
  25. package/esm/src/cli/cli-commands/agents-server/ensureAgentsServerGitignoreFile.d.ts +7 -0
  26. package/esm/src/cli/cli-commands/agents-server/init.d.ts +9 -0
  27. package/esm/src/cli/cli-commands/agents-server/init.test.d.ts +1 -0
  28. package/esm/src/cli/cli-commands/agents-server/initializeAgentsServerProjectConfiguration.d.ts +17 -0
  29. package/esm/src/cli/cli-commands/agents-server/printAgentsServerInitializationSummary.d.ts +7 -0
  30. package/esm/src/cli/cli-commands/agents-server/run.d.ts +14 -0
  31. package/esm/src/cli/cli-commands/agents-server/run.test.d.ts +1 -0
  32. package/esm/src/cli/cli-commands/agents-server/startAgentsServer.d.ts +23 -0
  33. package/esm/src/cli/cli-commands/agents-server.d.ts +8 -0
  34. package/esm/src/cli/cli-commands/common/handleActionErrors.d.ts +9 -4
  35. package/esm/src/cli/cli-commands/common/projectInitialization.d.ts +65 -0
  36. package/esm/src/cli/cli-commands/common/promptRunnerCliOptions.d.ts +44 -0
  37. package/esm/src/cli/common/$deprecateCliCommand.d.ts +8 -0
  38. package/esm/src/cli/common/$deprecateCliCommand.test.d.ts +1 -0
  39. package/esm/src/conversion/pipelineJsonToString/appendMarkdownBlock.d.ts +7 -0
  40. package/esm/src/conversion/pipelineJsonToString/createPipelineCommands.d.ts +7 -0
  41. package/esm/src/conversion/pipelineJsonToString/createPipelineIntroduction.d.ts +8 -0
  42. package/esm/src/conversion/pipelineJsonToString/createTaskSerialization.d.ts +23 -0
  43. package/esm/src/conversion/pipelineJsonToString/stringifyCommands.d.ts +7 -0
  44. package/esm/src/conversion/pipelineJsonToString/stringifyTask.d.ts +8 -0
  45. package/esm/src/conversion/pipelineJsonToString.test.d.ts +1 -0
  46. package/esm/src/execution/createPipelineExecutor/executeSingleAttempt.d.ts +31 -0
  47. package/esm/src/execution/createPipelineExecutor/handleAttemptFailure.d.ts +40 -0
  48. package/esm/src/execution/createPipelineExecutor/reportPromptExecution.d.ts +34 -0
  49. package/esm/src/execution/resolveTaskTldr.d.ts +32 -0
  50. package/esm/src/execution/resolveTaskTldr.test.d.ts +1 -0
  51. package/esm/src/llm-providers/agent/AgentLlmExecutionTools.d.ts +22 -63
  52. package/esm/src/llm-providers/agent/AgentLlmExecutionToolsAgentKitRunner.d.ts +51 -0
  53. package/esm/src/llm-providers/agent/AgentLlmExecutionToolsOpenAiAssistantRunner.d.ts +43 -0
  54. package/esm/src/llm-providers/agent/AgentLlmExecutionToolsPromptPreparer.d.ts +41 -0
  55. package/esm/src/llm-providers/agent/emitAgentLlmExecutionToolsAssistantPreparationProgress.d.ts +26 -0
  56. package/esm/src/llm-providers/openai/OpenAiAgentKitExecutionTools.d.ts +16 -93
  57. package/esm/src/llm-providers/openai/OpenAiAgentKitExecutionToolsInputBuilder.d.ts +41 -0
  58. package/esm/src/llm-providers/openai/OpenAiAgentKitExecutionToolsOutputTypeMapper.d.ts +56 -0
  59. package/esm/src/llm-providers/openai/OpenAiAgentKitExecutionToolsToolBuilder.d.ts +99 -0
  60. package/esm/src/llm-providers/openai/OpenAiAssistantExecutionTools.d.ts +24 -120
  61. package/esm/src/llm-providers/openai/OpenAiAssistantExecutionToolsProgressReporter.d.ts +62 -0
  62. package/esm/src/llm-providers/openai/OpenAiAssistantExecutionToolsPromptBuilder.d.ts +29 -0
  63. package/esm/src/llm-providers/openai/OpenAiAssistantExecutionToolsStreamRunner.d.ts +63 -0
  64. package/esm/src/llm-providers/openai/OpenAiAssistantExecutionToolsToolRunner.d.ts +89 -0
  65. package/esm/src/llm-providers/openai/OpenAiCompatibleExecutionTools.d.ts +9 -28
  66. package/esm/src/llm-providers/openai/OpenAiCompatibleModelCatalog.d.ts +31 -0
  67. package/esm/src/llm-providers/openai/OpenAiCompatibleNonChatPromptCaller.d.ts +57 -0
  68. package/esm/src/llm-providers/openai/OpenAiCompatibleRequestManager.d.ts +29 -0
  69. package/esm/src/llm-providers/openai/OpenAiVectorStoreFileBatchHandler.d.ts +51 -0
  70. package/esm/src/llm-providers/openai/OpenAiVectorStoreFileBatchPoller.d.ts +75 -0
  71. package/esm/src/llm-providers/openai/OpenAiVectorStoreHandler.d.ts +1 -98
  72. package/esm/src/llm-providers/openai/OpenAiVectorStoreKnowledgeSourcePreparer.d.ts +44 -0
  73. package/esm/src/llm-providers/openai/utils/OpenAiCompatibleChatProgressReporter.d.ts +86 -0
  74. package/esm/src/llm-providers/openai/utils/OpenAiCompatibleChatPromptBuilder.d.ts +57 -0
  75. package/esm/src/llm-providers/openai/utils/OpenAiCompatibleChatToolCaller.d.ts +57 -0
  76. package/esm/src/remote-server/startRemoteServer/RemoteServerRuntime.d.ts +14 -0
  77. package/esm/src/remote-server/startRemoteServer/SocketResponse.d.ts +9 -0
  78. package/esm/src/remote-server/startRemoteServer/StartRemoteServerConfiguration.d.ts +18 -0
  79. package/esm/src/remote-server/startRemoteServer/createRemoteServerExpressApp.d.ts +7 -0
  80. package/esm/src/remote-server/startRemoteServer/createRemoteServerHandle.d.ts +11 -0
  81. package/esm/src/remote-server/startRemoteServer/createSocketServer.d.ts +9 -0
  82. package/esm/src/remote-server/startRemoteServer/getExecutionToolsFromIdentification.d.ts +12 -0
  83. package/esm/src/remote-server/startRemoteServer/registerBookRoutes.d.ts +7 -0
  84. package/esm/src/remote-server/startRemoteServer/registerExecutionRoutes.d.ts +7 -0
  85. package/esm/src/remote-server/startRemoteServer/registerListModelsSocketHandler.d.ts +8 -0
  86. package/esm/src/remote-server/startRemoteServer/registerLoginRoute.d.ts +7 -0
  87. package/esm/src/remote-server/startRemoteServer/registerNotFoundRoute.d.ts +7 -0
  88. package/esm/src/remote-server/startRemoteServer/registerOpenAiCompatibleChatCompletionsRoute.d.ts +7 -0
  89. package/esm/src/remote-server/startRemoteServer/registerOpenApiRoutes.d.ts +7 -0
  90. package/esm/src/remote-server/startRemoteServer/registerPreparePipelineSocketHandler.d.ts +8 -0
  91. package/esm/src/remote-server/startRemoteServer/registerPromptSocketHandler.d.ts +8 -0
  92. package/esm/src/remote-server/startRemoteServer/registerRemoteServerHttpRoutes.d.ts +7 -0
  93. package/esm/src/remote-server/startRemoteServer/registerRemoteServerSocketHandlers.d.ts +8 -0
  94. package/esm/src/remote-server/startRemoteServer/registerServerIndexRoute.d.ts +7 -0
  95. package/esm/src/remote-server/startRemoteServer/resolveStartRemoteServerConfiguration.d.ts +8 -0
  96. package/esm/src/remote-server/startRemoteServer/respondToSocketRequest.d.ts +8 -0
  97. package/esm/src/remote-server/startRemoteServer/startListening.d.ts +9 -0
  98. package/esm/src/scrapers/_common/utils/makeKnowledgeSourceHandler.d.ts +14 -1
  99. package/esm/src/utils/color/Color.d.ts +4 -44
  100. package/esm/src/utils/color/ColorValue.d.ts +55 -0
  101. package/esm/src/utils/color/isHexColorString.d.ts +10 -0
  102. package/esm/src/utils/color/parseColorString.d.ts +11 -0
  103. package/esm/src/utils/serialization/serializeToPromptbookJavascript.d.ts +2 -0
  104. package/esm/src/utils/serialization/serializeToPromptbookJavascript.test.d.ts +1 -0
  105. package/esm/src/version.d.ts +1 -1
  106. package/package.json +2 -2
  107. package/umd/index.umd.js +310 -204
  108. package/umd/index.umd.js.map +1 -1
  109. package/umd/src/avatars/types/AvatarVisualDefinition.d.ts +1 -1
  110. package/umd/src/avatars/visuals/octopus3d2AvatarVisual.d.ts +7 -0
  111. package/umd/src/avatars/visuals/octopus3dAvatarVisualShared.d.ts +37 -0
  112. package/umd/src/book-components/Chat/save/_common/chatExportRendering.d.ts +75 -0
  113. package/umd/src/book-components/Chat/save/_common/getPromptbookExportBranding.d.ts +18 -0
  114. package/umd/src/book-components/Chat/save/html/htmlSaveFormatDefinition.d.ts +13 -1
  115. package/umd/src/book-components/Chat/save/html/htmlSaveFormatDefinition.test.d.ts +1 -0
  116. package/umd/src/book-components/Chat/save/index.d.ts +5 -5
  117. package/umd/src/book-components/Chat/save/markdown/mdSaveFormatDefinition.d.ts +5 -3
  118. package/umd/src/book-components/Chat/save/markdown/mdSaveFormatDefinition.test.d.ts +1 -0
  119. package/umd/src/book-components/Chat/save/pdf/buildChatPdf.d.ts +4 -3
  120. package/umd/src/book-components/Chat/save/pdf/pdfSaveFormatDefinition.d.ts +3 -3
  121. package/umd/src/book-components/Chat/save/pdf/pdfSaveFormatDefinition.test.d.ts +1 -0
  122. package/umd/src/book-components/Chat/save/react/reactSaveFormatDefinition.test.d.ts +1 -0
  123. package/umd/src/book-components/Chat/utils/renderMarkdown.d.ts +26 -0
  124. package/umd/src/cli/cli-commands/agent/agentProjectPaths.d.ts +8 -8
  125. package/umd/src/cli/cli-commands/agent/agentRunCliOptions.d.ts +2 -0
  126. package/umd/src/cli/cli-commands/agent/initializeAgentRunnerCommand.d.ts +1 -0
  127. package/umd/src/cli/cli-commands/agents-server/buildAgentsServer.d.ts +56 -0
  128. package/umd/src/cli/cli-commands/agents-server/buildAgentsServer.test.d.ts +1 -0
  129. package/umd/src/cli/cli-commands/agents-server/ensureAgentsServerEnvFile.d.ts +7 -0
  130. package/umd/src/cli/cli-commands/agents-server/ensureAgentsServerGitignoreFile.d.ts +7 -0
  131. package/umd/src/cli/cli-commands/agents-server/init.d.ts +9 -0
  132. package/umd/src/cli/cli-commands/agents-server/init.test.d.ts +1 -0
  133. package/umd/src/cli/cli-commands/agents-server/initializeAgentsServerProjectConfiguration.d.ts +17 -0
  134. package/umd/src/cli/cli-commands/agents-server/printAgentsServerInitializationSummary.d.ts +7 -0
  135. package/umd/src/cli/cli-commands/agents-server/run.d.ts +14 -0
  136. package/umd/src/cli/cli-commands/agents-server/run.test.d.ts +1 -0
  137. package/umd/src/cli/cli-commands/agents-server/startAgentsServer.d.ts +23 -0
  138. package/umd/src/cli/cli-commands/agents-server.d.ts +8 -0
  139. package/umd/src/cli/cli-commands/common/handleActionErrors.d.ts +9 -4
  140. package/umd/src/cli/cli-commands/common/projectInitialization.d.ts +65 -0
  141. package/umd/src/cli/cli-commands/common/promptRunnerCliOptions.d.ts +44 -0
  142. package/umd/src/cli/common/$deprecateCliCommand.d.ts +8 -0
  143. package/umd/src/cli/common/$deprecateCliCommand.test.d.ts +1 -0
  144. package/umd/src/conversion/pipelineJsonToString/appendMarkdownBlock.d.ts +7 -0
  145. package/umd/src/conversion/pipelineJsonToString/createPipelineCommands.d.ts +7 -0
  146. package/umd/src/conversion/pipelineJsonToString/createPipelineIntroduction.d.ts +8 -0
  147. package/umd/src/conversion/pipelineJsonToString/createTaskSerialization.d.ts +23 -0
  148. package/umd/src/conversion/pipelineJsonToString/stringifyCommands.d.ts +7 -0
  149. package/umd/src/conversion/pipelineJsonToString/stringifyTask.d.ts +8 -0
  150. package/umd/src/conversion/pipelineJsonToString.test.d.ts +1 -0
  151. package/umd/src/execution/createPipelineExecutor/executeSingleAttempt.d.ts +31 -0
  152. package/umd/src/execution/createPipelineExecutor/handleAttemptFailure.d.ts +40 -0
  153. package/umd/src/execution/createPipelineExecutor/reportPromptExecution.d.ts +34 -0
  154. package/umd/src/execution/resolveTaskTldr.d.ts +32 -0
  155. package/umd/src/execution/resolveTaskTldr.test.d.ts +1 -0
  156. package/umd/src/llm-providers/agent/AgentLlmExecutionTools.d.ts +22 -63
  157. package/umd/src/llm-providers/agent/AgentLlmExecutionToolsAgentKitRunner.d.ts +51 -0
  158. package/umd/src/llm-providers/agent/AgentLlmExecutionToolsOpenAiAssistantRunner.d.ts +43 -0
  159. package/umd/src/llm-providers/agent/AgentLlmExecutionToolsPromptPreparer.d.ts +41 -0
  160. package/umd/src/llm-providers/agent/emitAgentLlmExecutionToolsAssistantPreparationProgress.d.ts +26 -0
  161. package/umd/src/llm-providers/openai/OpenAiAgentKitExecutionTools.d.ts +16 -93
  162. package/umd/src/llm-providers/openai/OpenAiAgentKitExecutionToolsInputBuilder.d.ts +41 -0
  163. package/umd/src/llm-providers/openai/OpenAiAgentKitExecutionToolsOutputTypeMapper.d.ts +56 -0
  164. package/umd/src/llm-providers/openai/OpenAiAgentKitExecutionToolsToolBuilder.d.ts +99 -0
  165. package/umd/src/llm-providers/openai/OpenAiAssistantExecutionTools.d.ts +24 -120
  166. package/umd/src/llm-providers/openai/OpenAiAssistantExecutionToolsProgressReporter.d.ts +62 -0
  167. package/umd/src/llm-providers/openai/OpenAiAssistantExecutionToolsPromptBuilder.d.ts +29 -0
  168. package/umd/src/llm-providers/openai/OpenAiAssistantExecutionToolsStreamRunner.d.ts +63 -0
  169. package/umd/src/llm-providers/openai/OpenAiAssistantExecutionToolsToolRunner.d.ts +89 -0
  170. package/umd/src/llm-providers/openai/OpenAiCompatibleExecutionTools.d.ts +9 -28
  171. package/umd/src/llm-providers/openai/OpenAiCompatibleModelCatalog.d.ts +31 -0
  172. package/umd/src/llm-providers/openai/OpenAiCompatibleNonChatPromptCaller.d.ts +57 -0
  173. package/umd/src/llm-providers/openai/OpenAiCompatibleRequestManager.d.ts +29 -0
  174. package/umd/src/llm-providers/openai/OpenAiVectorStoreFileBatchHandler.d.ts +51 -0
  175. package/umd/src/llm-providers/openai/OpenAiVectorStoreFileBatchPoller.d.ts +75 -0
  176. package/umd/src/llm-providers/openai/OpenAiVectorStoreHandler.d.ts +1 -98
  177. package/umd/src/llm-providers/openai/OpenAiVectorStoreKnowledgeSourcePreparer.d.ts +44 -0
  178. package/umd/src/llm-providers/openai/utils/OpenAiCompatibleChatProgressReporter.d.ts +86 -0
  179. package/umd/src/llm-providers/openai/utils/OpenAiCompatibleChatPromptBuilder.d.ts +57 -0
  180. package/umd/src/llm-providers/openai/utils/OpenAiCompatibleChatToolCaller.d.ts +57 -0
  181. package/umd/src/remote-server/startRemoteServer/RemoteServerRuntime.d.ts +14 -0
  182. package/umd/src/remote-server/startRemoteServer/SocketResponse.d.ts +9 -0
  183. package/umd/src/remote-server/startRemoteServer/StartRemoteServerConfiguration.d.ts +18 -0
  184. package/umd/src/remote-server/startRemoteServer/createRemoteServerExpressApp.d.ts +7 -0
  185. package/umd/src/remote-server/startRemoteServer/createRemoteServerHandle.d.ts +11 -0
  186. package/umd/src/remote-server/startRemoteServer/createSocketServer.d.ts +9 -0
  187. package/umd/src/remote-server/startRemoteServer/getExecutionToolsFromIdentification.d.ts +12 -0
  188. package/umd/src/remote-server/startRemoteServer/registerBookRoutes.d.ts +7 -0
  189. package/umd/src/remote-server/startRemoteServer/registerExecutionRoutes.d.ts +7 -0
  190. package/umd/src/remote-server/startRemoteServer/registerListModelsSocketHandler.d.ts +8 -0
  191. package/umd/src/remote-server/startRemoteServer/registerLoginRoute.d.ts +7 -0
  192. package/umd/src/remote-server/startRemoteServer/registerNotFoundRoute.d.ts +7 -0
  193. package/umd/src/remote-server/startRemoteServer/registerOpenAiCompatibleChatCompletionsRoute.d.ts +7 -0
  194. package/umd/src/remote-server/startRemoteServer/registerOpenApiRoutes.d.ts +7 -0
  195. package/umd/src/remote-server/startRemoteServer/registerPreparePipelineSocketHandler.d.ts +8 -0
  196. package/umd/src/remote-server/startRemoteServer/registerPromptSocketHandler.d.ts +8 -0
  197. package/umd/src/remote-server/startRemoteServer/registerRemoteServerHttpRoutes.d.ts +7 -0
  198. package/umd/src/remote-server/startRemoteServer/registerRemoteServerSocketHandlers.d.ts +8 -0
  199. package/umd/src/remote-server/startRemoteServer/registerServerIndexRoute.d.ts +7 -0
  200. package/umd/src/remote-server/startRemoteServer/resolveStartRemoteServerConfiguration.d.ts +8 -0
  201. package/umd/src/remote-server/startRemoteServer/respondToSocketRequest.d.ts +8 -0
  202. package/umd/src/remote-server/startRemoteServer/startListening.d.ts +9 -0
  203. package/umd/src/scrapers/_common/utils/makeKnowledgeSourceHandler.d.ts +14 -1
  204. package/umd/src/utils/color/Color.d.ts +4 -44
  205. package/umd/src/utils/color/ColorValue.d.ts +55 -0
  206. package/umd/src/utils/color/isHexColorString.d.ts +10 -0
  207. package/umd/src/utils/color/parseColorString.d.ts +11 -0
  208. package/umd/src/utils/serialization/serializeToPromptbookJavascript.d.ts +2 -0
  209. package/umd/src/utils/serialization/serializeToPromptbookJavascript.test.d.ts +1 -0
  210. package/umd/src/version.d.ts +1 -1
  211. package/esm/src/cli/cli-commands/coder/appendBlock.d.ts +0 -6
  212. package/esm/src/cli/cli-commands/coder/readTextFileIfExists.d.ts +0 -6
  213. package/umd/src/cli/cli-commands/coder/appendBlock.d.ts +0 -6
  214. package/umd/src/cli/cli-commands/coder/readTextFileIfExists.d.ts +0 -6
package/umd/index.umd.js CHANGED
@@ -22,7 +22,7 @@
22
22
  * @generated
23
23
  * @see https://github.com/webgptorg/promptbook
24
24
  */
25
- const PROMPTBOOK_ENGINE_VERSION = '0.112.0-72';
25
+ const PROMPTBOOK_ENGINE_VERSION = '0.112.0-79';
26
26
  /**
27
27
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
28
28
  * Note: [💞] Ignore a discrepancy between file name and entity name
@@ -564,6 +564,111 @@
564
564
  }
565
565
  }
566
566
 
567
+ /**
568
+ * Shared immutable channel storage and serialization helpers for `Color`.
569
+ *
570
+ * @private base class of Color
571
+ */
572
+ class ColorValue {
573
+ constructor(red, green, blue, alpha = 255) {
574
+ this.red = red;
575
+ this.green = green;
576
+ this.blue = blue;
577
+ this.alpha = alpha;
578
+ checkChannelValue('Red', red);
579
+ checkChannelValue('Green', green);
580
+ checkChannelValue('Blue', blue);
581
+ checkChannelValue('Alpha', alpha);
582
+ }
583
+ /**
584
+ * Shortcut for `red` property
585
+ * Number from 0 to 255
586
+ * @alias red
587
+ */
588
+ get r() {
589
+ return this.red;
590
+ }
591
+ /**
592
+ * Shortcut for `green` property
593
+ * Number from 0 to 255
594
+ * @alias green
595
+ */
596
+ get g() {
597
+ return this.green;
598
+ }
599
+ /**
600
+ * Shortcut for `blue` property
601
+ * Number from 0 to 255
602
+ * @alias blue
603
+ */
604
+ get b() {
605
+ return this.blue;
606
+ }
607
+ /**
608
+ * Shortcut for `alpha` property
609
+ * Number from 0 (transparent) to 255 (opaque)
610
+ * @alias alpha
611
+ */
612
+ get a() {
613
+ return this.alpha;
614
+ }
615
+ /**
616
+ * Shortcut for `alpha` property
617
+ * Number from 0 (transparent) to 255 (opaque)
618
+ * @alias alpha
619
+ */
620
+ get opacity() {
621
+ return this.alpha;
622
+ }
623
+ /**
624
+ * Shortcut for 1-`alpha` property
625
+ */
626
+ get transparency() {
627
+ return 255 - this.alpha;
628
+ }
629
+ clone() {
630
+ return take(this.createColor(this.red, this.green, this.blue, this.alpha));
631
+ }
632
+ toString() {
633
+ return this.toHex();
634
+ }
635
+ toHex() {
636
+ if (this.alpha === 255) {
637
+ return `#${this.red.toString(16).padStart(2, '0')}${this.green.toString(16).padStart(2, '0')}${this.blue
638
+ .toString(16)
639
+ .padStart(2, '0')}`;
640
+ }
641
+ else {
642
+ return `#${this.red.toString(16).padStart(2, '0')}${this.green.toString(16).padStart(2, '0')}${this.blue
643
+ .toString(16)
644
+ .padStart(2, '0')}${this.alpha.toString(16).padStart(2, '0')}`;
645
+ }
646
+ }
647
+ toRgb() {
648
+ if (this.alpha === 255) {
649
+ return `rgb(${this.red}, ${this.green}, ${this.blue})`;
650
+ }
651
+ else {
652
+ return `rgba(${this.red}, ${this.green}, ${this.blue}, ${Math.round((this.alpha / 255) * 100)}%)`;
653
+ }
654
+ }
655
+ toHsl() {
656
+ throw new Error(`Getting HSL is not implemented`);
657
+ }
658
+ }
659
+
660
+ /**
661
+ * Checks if the given value is a valid hex color string
662
+ *
663
+ * @param value - value to check
664
+ * @returns true if the value is a valid hex color string (e.g., `#009edd`, `#fff`, etc.)
665
+ *
666
+ * @private function of Color
667
+ */
668
+ function isHexColorString(value) {
669
+ return (typeof value === 'string' && /^#(?:[0-9a-fA-F]{3}|[0-9a-fA-F]{4}|[0-9a-fA-F]{6}|[0-9a-fA-F]{8})$/.test(value));
670
+ }
671
+
567
672
  /**
568
673
  * Constant for short hex lengths.
569
674
  */
@@ -775,16 +880,53 @@
775
880
 
776
881
  /**
777
882
  * Pattern matching hsl regex.
883
+ *
884
+ * @private function of Color
778
885
  */
779
886
  const HSL_REGEX_PATTERN = /^hsl\(\s*([0-9.]+)\s*,\s*([0-9.]+)%\s*,\s*([0-9.]+)%\s*\)$/;
780
887
  /**
781
888
  * Pattern matching RGB regex.
889
+ *
890
+ * @private function of Color
782
891
  */
783
892
  const RGB_REGEX_PATTERN = /^rgb\(\s*([0-9.%-]+)\s*,\s*([0-9.%-]+)\s*,\s*([0-9.%-]+)\s*\)$/;
784
893
  /**
785
894
  * Pattern matching rgba regex.
895
+ *
896
+ * @private function of Color
786
897
  */
787
898
  const RGBA_REGEX_PATTERN = /^rgba\(\s*([0-9.%-]+)\s*,\s*([0-9.%-]+)\s*,\s*([0-9.%-]+)\s*,\s*([0-9.%-]+)\s*\)$/;
899
+ /**
900
+ * Parses a supported color string into RGBA channels.
901
+ *
902
+ * @param color as a string for example `#009edd`, `rgb(0,158,221)`, `rgb(0%,62%,86.7%)`, `hsl(197.1,100%,43.3%)`, `red`, `darkgrey`,...
903
+ * @returns RGBA channel values.
904
+ *
905
+ * @private function of Color
906
+ */
907
+ function parseColorString(color) {
908
+ const trimmed = color.trim();
909
+ const cssColor = CSS_COLORS[trimmed];
910
+ if (cssColor) {
911
+ return parseColorString(cssColor);
912
+ }
913
+ else if (isHexColorString(trimmed)) {
914
+ return parseHexColor(trimmed);
915
+ }
916
+ if (HSL_REGEX_PATTERN.test(trimmed)) {
917
+ return parseHslColor(trimmed);
918
+ }
919
+ else if (RGB_REGEX_PATTERN.test(trimmed)) {
920
+ return parseRgbColor(trimmed);
921
+ }
922
+ else if (RGBA_REGEX_PATTERN.test(trimmed)) {
923
+ return parseRgbaColor(trimmed);
924
+ }
925
+ else {
926
+ throw new Error(`Can not create a new Color instance from string "${trimmed}".`);
927
+ }
928
+ }
929
+
788
930
  /**
789
931
  * Color object represents an RGB color with alpha channel
790
932
  *
@@ -792,7 +934,7 @@
792
934
  *
793
935
  * @public exported from `@promptbook/color`
794
936
  */
795
- class Color {
937
+ class Color extends ColorValue {
796
938
  /**
797
939
  * Creates a new Color instance from miscellaneous formats
798
940
  * - It can receive Color instance and just return the same instance
@@ -865,25 +1007,7 @@
865
1007
  * @returns Color object
866
1008
  */
867
1009
  static fromString(color) {
868
- const trimmed = color.trim();
869
- if (CSS_COLORS[trimmed]) {
870
- return Color.fromString(CSS_COLORS[trimmed]);
871
- }
872
- else if (Color.isHexColorString(trimmed)) {
873
- return Color.fromHex(trimmed);
874
- }
875
- if (HSL_REGEX_PATTERN.test(trimmed)) {
876
- return Color.fromHsl(trimmed);
877
- }
878
- else if (RGB_REGEX_PATTERN.test(trimmed)) {
879
- return Color.fromRgbString(trimmed);
880
- }
881
- else if (RGBA_REGEX_PATTERN.test(trimmed)) {
882
- return Color.fromRgbaString(trimmed);
883
- }
884
- else {
885
- throw new Error(`Can not create a new Color instance from string "${trimmed}".`);
886
- }
1010
+ return Color.fromColorChannels(parseColorString(color));
887
1011
  }
888
1012
  /**
889
1013
  * Gets common color
@@ -913,8 +1037,7 @@
913
1037
  * @returns Color object
914
1038
  */
915
1039
  static fromHex(hex) {
916
- const { red, green, blue, alpha } = parseHexColor(hex);
917
- return take(new Color(red, green, blue, alpha));
1040
+ return Color.fromColorChannels(parseHexColor(hex));
918
1041
  }
919
1042
  /**
920
1043
  * Creates a new Color instance from color in hsl format
@@ -923,8 +1046,7 @@
923
1046
  * @returns Color object
924
1047
  */
925
1048
  static fromHsl(hsl) {
926
- const { red, green, blue, alpha } = parseHslColor(hsl);
927
- return take(new Color(red, green, blue, alpha));
1049
+ return Color.fromColorChannels(parseHslColor(hsl));
928
1050
  }
929
1051
  /**
930
1052
  * Creates a new Color instance from color in rgb format
@@ -933,8 +1055,7 @@
933
1055
  * @returns Color object
934
1056
  */
935
1057
  static fromRgbString(rgb) {
936
- const { red, green, blue, alpha } = parseRgbColor(rgb);
937
- return take(new Color(red, green, blue, alpha));
1058
+ return Color.fromColorChannels(parseRgbColor(rgb));
938
1059
  }
939
1060
  /**
940
1061
  * Creates a new Color instance from color in rbga format
@@ -943,8 +1064,7 @@
943
1064
  * @returns Color object
944
1065
  */
945
1066
  static fromRgbaString(rgba) {
946
- const { red, green, blue, alpha } = parseRgbaColor(rgba);
947
- return take(new Color(red, green, blue, alpha));
1067
+ return Color.fromColorChannels(parseRgbaColor(rgba));
948
1068
  }
949
1069
  /**
950
1070
  * Creates a new Color for color channels values
@@ -956,7 +1076,7 @@
956
1076
  * @returns Color object
957
1077
  */
958
1078
  static fromValues(red, green, blue, alpha = 255) {
959
- return take(new Color(red, green, blue, alpha));
1079
+ return Color.fromColorChannels({ red, green, blue, alpha });
960
1080
  }
961
1081
  /**
962
1082
  * Checks if the given value is a valid Color object.
@@ -989,8 +1109,7 @@
989
1109
  * @returns true if the value is a valid hex color string (e.g., `#009edd`, `#fff`, etc.)
990
1110
  */
991
1111
  static isHexColorString(value) {
992
- return (typeof value === 'string' &&
993
- /^#(?:[0-9a-fA-F]{3}|[0-9a-fA-F]{4}|[0-9a-fA-F]{6}|[0-9a-fA-F]{8})$/.test(value));
1112
+ return isHexColorString(value);
994
1113
  }
995
1114
  /**
996
1115
  * Creates new Color object
@@ -1003,89 +1122,13 @@
1003
1122
  * @param alpha number from 0 (transparent) to 255 (opaque)
1004
1123
  */
1005
1124
  constructor(red, green, blue, alpha = 255) {
1006
- this.red = red;
1007
- this.green = green;
1008
- this.blue = blue;
1009
- this.alpha = alpha;
1010
- checkChannelValue('Red', red);
1011
- checkChannelValue('Green', green);
1012
- checkChannelValue('Blue', blue);
1013
- checkChannelValue('Alpha', alpha);
1014
- }
1015
- /**
1016
- * Shortcut for `red` property
1017
- * Number from 0 to 255
1018
- * @alias red
1019
- */
1020
- get r() {
1021
- return this.red;
1022
- }
1023
- /**
1024
- * Shortcut for `green` property
1025
- * Number from 0 to 255
1026
- * @alias green
1027
- */
1028
- get g() {
1029
- return this.green;
1030
- }
1031
- /**
1032
- * Shortcut for `blue` property
1033
- * Number from 0 to 255
1034
- * @alias blue
1035
- */
1036
- get b() {
1037
- return this.blue;
1038
- }
1039
- /**
1040
- * Shortcut for `alpha` property
1041
- * Number from 0 (transparent) to 255 (opaque)
1042
- * @alias alpha
1043
- */
1044
- get a() {
1045
- return this.alpha;
1125
+ super(red, green, blue, alpha);
1046
1126
  }
1047
- /**
1048
- * Shortcut for `alpha` property
1049
- * Number from 0 (transparent) to 255 (opaque)
1050
- * @alias alpha
1051
- */
1052
- get opacity() {
1053
- return this.alpha;
1127
+ createColor(red, green, blue, alpha) {
1128
+ return new Color(red, green, blue, alpha);
1054
1129
  }
1055
- /**
1056
- * Shortcut for 1-`alpha` property
1057
- */
1058
- get transparency() {
1059
- return 255 - this.alpha;
1060
- }
1061
- clone() {
1062
- return take(new Color(this.red, this.green, this.blue, this.alpha));
1063
- }
1064
- toString() {
1065
- return this.toHex();
1066
- }
1067
- toHex() {
1068
- if (this.alpha === 255) {
1069
- return `#${this.red.toString(16).padStart(2, '0')}${this.green.toString(16).padStart(2, '0')}${this.blue
1070
- .toString(16)
1071
- .padStart(2, '0')}`;
1072
- }
1073
- else {
1074
- return `#${this.red.toString(16).padStart(2, '0')}${this.green.toString(16).padStart(2, '0')}${this.blue
1075
- .toString(16)
1076
- .padStart(2, '0')}${this.alpha.toString(16).padStart(2, '0')}`;
1077
- }
1078
- }
1079
- toRgb() {
1080
- if (this.alpha === 255) {
1081
- return `rgb(${this.red}, ${this.green}, ${this.blue})`;
1082
- }
1083
- else {
1084
- return `rgba(${this.red}, ${this.green}, ${this.blue}, ${Math.round((this.alpha / 255) * 100)}%)`;
1085
- }
1086
- }
1087
- toHsl() {
1088
- throw new Error(`Getting HSL is not implemented`);
1130
+ static fromColorChannels({ red, green, blue, alpha }) {
1131
+ return take(new Color(red, green, blue, alpha));
1089
1132
  }
1090
1133
  }
1091
1134
 
@@ -2618,120 +2661,183 @@
2618
2661
  * @public exported from `@promptbook/utils`
2619
2662
  */
2620
2663
  function checkSerializableAsJson(options) {
2621
- const { value, name, message } = options;
2664
+ checkSerializableValue(options);
2665
+ }
2666
+ // TODO: Can be return type more type-safe? like `asserts options.value is JsonValue`
2667
+ // TODO: [🧠][main] !!3 In-memory cache of same values to prevent multiple checks
2668
+ // Note: [🐠] This is how `checkSerializableAsJson` + `isSerializableAsJson` together can just retun true/false or rich error message
2669
+ /**
2670
+ * Checks one value and dispatches to the appropriate specialized validator.
2671
+ *
2672
+ * @private function of `checkSerializableAsJson`
2673
+ */
2674
+ function checkSerializableValue(options) {
2675
+ const { value } = options;
2676
+ if (isSerializablePrimitive(value)) {
2677
+ return;
2678
+ }
2622
2679
  if (value === undefined) {
2623
- throw new UnexpectedError(`${name} is undefined`);
2680
+ throw new UnexpectedError(`${options.name} is undefined`);
2624
2681
  }
2625
- else if (value === null) {
2626
- return;
2682
+ if (typeof value === 'symbol') {
2683
+ throw new UnexpectedError(`${options.name} is symbol`);
2627
2684
  }
2628
- else if (typeof value === 'boolean') {
2629
- return;
2685
+ if (typeof value === 'function') {
2686
+ throw new UnexpectedError(`${options.name} is function`);
2630
2687
  }
2631
- else if (typeof value === 'number' && !isNaN(value)) {
2688
+ if (Array.isArray(value)) {
2689
+ checkSerializableArray(options, value);
2632
2690
  return;
2633
2691
  }
2634
- else if (typeof value === 'string') {
2692
+ if (value !== null && typeof value === 'object') {
2693
+ checkSerializableObject(options, value);
2635
2694
  return;
2636
2695
  }
2637
- else if (typeof value === 'symbol') {
2638
- throw new UnexpectedError(`${name} is symbol`);
2639
- }
2640
- else if (typeof value === 'function') {
2641
- throw new UnexpectedError(`${name} is function`);
2642
- }
2643
- else if (typeof value === 'object' && Array.isArray(value)) {
2644
- for (let i = 0; i < value.length; i++) {
2645
- checkSerializableAsJson({ name: `${name}[${i}]`, value: value[i], message });
2646
- }
2696
+ throwUnknownTypeError(options);
2697
+ }
2698
+ /**
2699
+ * Checks the primitive values that are directly JSON serializable.
2700
+ *
2701
+ * @private function of `checkSerializableAsJson`
2702
+ */
2703
+ function isSerializablePrimitive(value) {
2704
+ return (value === null ||
2705
+ typeof value === 'boolean' ||
2706
+ (typeof value === 'number' && !isNaN(value)) ||
2707
+ typeof value === 'string');
2708
+ }
2709
+ /**
2710
+ * Recursively checks JSON array items.
2711
+ *
2712
+ * @private function of `checkSerializableAsJson`
2713
+ */
2714
+ function checkSerializableArray(context, arrayValue) {
2715
+ for (let index = 0; index < arrayValue.length; index++) {
2716
+ checkSerializableAsJson({
2717
+ ...context,
2718
+ name: `${context.name}[${index}]`,
2719
+ value: arrayValue[index],
2720
+ });
2647
2721
  }
2648
- else if (typeof value === 'object') {
2649
- if (value instanceof Date) {
2650
- throw new UnexpectedError(spacetrim.spaceTrim((block) => `
2651
- \`${name}\` is Date
2722
+ }
2723
+ /**
2724
+ * Checks object-like values and dispatches special unsupported built-ins.
2725
+ *
2726
+ * @private function of `checkSerializableAsJson`
2727
+ */
2728
+ function checkSerializableObject(context, objectValue) {
2729
+ checkUnsupportedObjectType(context, objectValue);
2730
+ checkSerializableObjectEntries(context, objectValue);
2731
+ assertJsonStringificationSucceeds(context, objectValue);
2732
+ }
2733
+ /**
2734
+ * Rejects built-in objects that must be converted before JSON serialization.
2735
+ *
2736
+ * @private function of `checkSerializableAsJson`
2737
+ */
2738
+ function checkUnsupportedObjectType(context, objectValue) {
2739
+ if (objectValue instanceof Date) {
2740
+ throw new UnexpectedError(spacetrim.spaceTrim((block) => `
2741
+ \`${context.name}\` is Date
2652
2742
 
2653
- Use \`string_date_iso8601\` instead
2743
+ Use \`string_date_iso8601\` instead
2654
2744
 
2655
- Additional message for \`${name}\`:
2656
- ${block(message || '(nothing)')}
2657
- `));
2658
- }
2659
- else if (value instanceof Map) {
2660
- throw new UnexpectedError(`${name} is Map`);
2661
- }
2662
- else if (value instanceof Set) {
2663
- throw new UnexpectedError(`${name} is Set`);
2664
- }
2665
- else if (value instanceof RegExp) {
2666
- throw new UnexpectedError(`${name} is RegExp`);
2667
- }
2668
- else if (value instanceof Error) {
2669
- throw new UnexpectedError(spacetrim.spaceTrim((block) => `
2670
- \`${name}\` is unserialized Error
2745
+ Additional message for \`${context.name}\`:
2746
+ ${block(context.message || '(nothing)')}
2747
+ `));
2748
+ }
2749
+ if (objectValue instanceof Map) {
2750
+ throw new UnexpectedError(`${context.name} is Map`);
2751
+ }
2752
+ if (objectValue instanceof Set) {
2753
+ throw new UnexpectedError(`${context.name} is Set`);
2754
+ }
2755
+ if (objectValue instanceof RegExp) {
2756
+ throw new UnexpectedError(`${context.name} is RegExp`);
2757
+ }
2758
+ if (objectValue instanceof Error) {
2759
+ throw new UnexpectedError(spacetrim.spaceTrim((block) => `
2760
+ \`${context.name}\` is unserialized Error
2671
2761
 
2672
- Use function \`serializeError\`
2762
+ Use function \`serializeError\`
2673
2763
 
2674
- Additional message for \`${name}\`:
2675
- ${block(message || '(nothing)')}
2764
+ Additional message for \`${context.name}\`:
2765
+ ${block(context.message || '(nothing)')}
2676
2766
 
2677
- `));
2767
+ `));
2768
+ }
2769
+ }
2770
+ /**
2771
+ * Recursively checks object properties while preserving omitted `undefined` keys.
2772
+ *
2773
+ * @private function of `checkSerializableAsJson`
2774
+ */
2775
+ function checkSerializableObjectEntries(context, objectValue) {
2776
+ for (const [subName, subValue] of Object.entries(objectValue)) {
2777
+ if (subValue === undefined) {
2778
+ // Note: undefined in object is serializable - it is just omitted
2779
+ continue;
2678
2780
  }
2679
- else {
2680
- for (const [subName, subValue] of Object.entries(value)) {
2681
- if (subValue === undefined) {
2682
- // Note: undefined in object is serializable - it is just omitted
2683
- continue;
2684
- }
2685
- checkSerializableAsJson({ name: `${name}.${subName}`, value: subValue, message });
2686
- }
2687
- try {
2688
- JSON.stringify(value); // <- TODO: [0]
2689
- }
2690
- catch (error) {
2691
- assertsError(error);
2692
- throw new UnexpectedError(spacetrim.spaceTrim((block) => `
2693
- \`${name}\` is not serializable
2781
+ checkSerializableAsJson({
2782
+ ...context,
2783
+ name: `${context.name}.${subName}`,
2784
+ value: subValue,
2785
+ });
2786
+ }
2787
+ }
2788
+ /**
2789
+ * Uses `JSON.stringify` as the final guard for cases like circular references.
2790
+ *
2791
+ * @private function of `checkSerializableAsJson`
2792
+ */
2793
+ function assertJsonStringificationSucceeds(context, objectValue) {
2794
+ try {
2795
+ JSON.stringify(objectValue); // <- TODO: [0]
2796
+ }
2797
+ catch (error) {
2798
+ assertsError(error);
2799
+ throw new UnexpectedError(spacetrim.spaceTrim((block) => `
2800
+ \`${context.name}\` is not serializable
2694
2801
 
2695
- ${block(error.stack || error.message)}
2802
+ ${block(error.stack || error.message)}
2696
2803
 
2697
- Additional message for \`${name}\`:
2698
- ${block(message || '(nothing)')}
2699
- `));
2804
+ Additional message for \`${context.name}\`:
2805
+ ${block(context.message || '(nothing)')}
2806
+ `));
2807
+ }
2808
+ /*
2809
+ TODO: [0] Is there some more elegant way to check circular references?
2810
+ const seen = new Set();
2811
+ const stack = [{ value }];
2812
+ while (stack.length > 0) {
2813
+ const { value } = stack.pop()!;
2814
+ if (typeof value === 'object' && value !== null) {
2815
+ if (seen.has(value)) {
2816
+ throw new UnexpectedError(`${name} has circular reference`);
2700
2817
  }
2701
- /*
2702
- TODO: [0] Is there some more elegant way to check circular references?
2703
- const seen = new Set();
2704
- const stack = [{ value }];
2705
- while (stack.length > 0) {
2706
- const { value } = stack.pop()!;
2707
- if (typeof value === 'object' && value !== null) {
2708
- if (seen.has(value)) {
2709
- throw new UnexpectedError(`${name} has circular reference`);
2710
- }
2711
- seen.add(value);
2712
- if (Array.isArray(value)) {
2713
- stack.push(...value.map((value) => ({ value })));
2714
- } else {
2715
- stack.push(...Object.values(value).map((value) => ({ value })));
2716
- }
2717
- }
2818
+ seen.add(value);
2819
+ if (Array.isArray(value)) {
2820
+ stack.push(...value.map((value) => ({ value })));
2821
+ } else {
2822
+ stack.push(...Object.values(value).map((value) => ({ value })));
2718
2823
  }
2719
- */
2720
- return;
2721
2824
  }
2722
2825
  }
2723
- else {
2724
- throw new UnexpectedError(spacetrim.spaceTrim((block) => `
2725
- \`${name}\` is unknown type
2826
+ */
2827
+ }
2828
+ /**
2829
+ * Throws the fallback error for unsupported value types like `bigint` and `NaN`.
2830
+ *
2831
+ * @private function of `checkSerializableAsJson`
2832
+ */
2833
+ function throwUnknownTypeError(context) {
2834
+ throw new UnexpectedError(spacetrim.spaceTrim((block) => `
2835
+ \`${context.name}\` is unknown type
2726
2836
 
2727
- Additional message for \`${name}\`:
2728
- ${block(message || '(nothing)')}
2729
- `));
2730
- }
2837
+ Additional message for \`${context.name}\`:
2838
+ ${block(context.message || '(nothing)')}
2839
+ `));
2731
2840
  }
2732
- // TODO: Can be return type more type-safe? like `asserts options.value is JsonValue`
2733
- // TODO: [🧠][main] !!3 In-memory cache of same values to prevent multiple checks
2734
- // Note: [🐠] This is how `checkSerializableAsJson` + `isSerializableAsJson` together can just retun true/false or rich error message
2735
2841
 
2736
2842
  /**
2737
2843
  * Creates a deep clone of the given object