From 047ec4bafa5eb8798bf3c744bfd8ef8c5f58a649 Mon Sep 17 00:00:00 2001 From: Pavol Hejny Date: Sun, 15 Dec 2024 16:02:09 +0100 Subject: [PATCH] New features into mermaid graph --- .../pipelines/25-simple-knowledge.book.md | 6 + src/_packages/types.index.ts | 868 +++++++++--------- src/_packages/utils.index.ts | 2 +- .../prettify/prettifyPipelineString.ts | 2 +- ...dOptions.ts => renderPromptbookMermaid.ts} | 90 +- 5 files changed, 495 insertions(+), 473 deletions(-) rename src/conversion/prettify/{renderPipelineMermaidOptions.ts => renderPromptbookMermaid.ts} (58%) diff --git a/examples/pipelines/25-simple-knowledge.book.md b/examples/pipelines/25-simple-knowledge.book.md index c48a575b28..a22616138e 100644 --- a/examples/pipelines/25-simple-knowledge.book.md +++ b/examples/pipelines/25-simple-knowledge.book.md @@ -89,6 +89,12 @@ You are writing a bio for Pavol Hejný for the event {eventTitle}. - Write plain text without any formatting (like markdown) - {rules} +## Knowledge + +{knowledge} + + + ## {eventTitle} > {eventDescription} diff --git a/src/_packages/types.index.ts b/src/_packages/types.index.ts index 791c54658f..b72b344551 100644 --- a/src/_packages/types.index.ts +++ b/src/_packages/types.index.ts @@ -3,17 +3,19 @@ import type { PipelineCollection } from '../collection/PipelineCollection'; import type { Command } from '../commands/_common/types/Command'; -import type { CommandParser } from '../commands/_common/types/CommandParser'; -import type { PipelineBothCommandParser } from '../commands/_common/types/CommandParser'; -import type { PipelineHeadCommandParser } from '../commands/_common/types/CommandParser'; -import type { PipelineTaskCommandParser } from '../commands/_common/types/CommandParser'; -import type { CommandParserInput } from '../commands/_common/types/CommandParser'; +import type { + CommandParser, + CommandParserInput, + PipelineBothCommandParser, + PipelineHeadCommandParser, + PipelineTaskCommandParser, +} from '../commands/_common/types/CommandParser'; import type { CommandUsagePlace } from '../commands/_common/types/CommandUsagePlaces'; import type { ExpectCommand } from '../commands/EXPECT/ExpectCommand'; import type { ForeachJson } from '../commands/FOREACH/ForeachJson'; import type { FormatCommand } from '../commands/FORMAT/FormatCommand'; import type { PrettifyOptions } from '../conversion/prettify/PrettifyOptions'; -import type { renderPipelineMermaidOptions } from '../conversion/prettify/renderPipelineMermaidOptions'; +import type { renderPipelineMermaidOptions } from '../conversion/prettify/renderPromptbookMermaid'; import type { CallbackInterfaceToolsOptions } from '../dialogs/callback/CallbackInterfaceToolsOptions'; import type { ErrorJson } from '../errors/utils/ErrorJson'; import type { LocateAppOptions } from '../executables/locateApp'; @@ -32,17 +34,16 @@ import type { LlmExecutionTools } from '../execution/LlmExecutionTools'; import type { LlmExecutionToolsConstructor } from '../execution/LlmExecutionToolsConstructor'; import type { PipelineExecutor } from '../execution/PipelineExecutor'; import type { PipelineExecutorResult } from '../execution/PipelineExecutorResult'; -import type { PromptResult } from '../execution/PromptResult'; -import type { CompletionPromptResult } from '../execution/PromptResult'; -import type { ChatPromptResult } from '../execution/PromptResult'; -import type { EmbeddingPromptResult } from '../execution/PromptResult'; -import type { PromptResultUsage } from '../execution/PromptResultUsage'; -import type { PromptResultUsageCounts } from '../execution/PromptResultUsage'; -import type { ScriptExecutionTools } from '../execution/ScriptExecutionTools'; -import type { ScriptExecutionToolsExecuteOptions } from '../execution/ScriptExecutionTools'; +import type { + ChatPromptResult, + CompletionPromptResult, + EmbeddingPromptResult, + PromptResult, +} from '../execution/PromptResult'; +import type { PromptResultUsage, PromptResultUsageCounts } from '../execution/PromptResultUsage'; +import type { ScriptExecutionTools, ScriptExecutionToolsExecuteOptions } from '../execution/ScriptExecutionTools'; import type { UncertainNumber } from '../execution/UncertainNumber'; -import type { UserInterfaceTools } from '../execution/UserInterfaceTools'; -import type { UserInterfaceToolsPromptDialogOptions } from '../execution/UserInterfaceTools'; +import type { UserInterfaceTools, UserInterfaceToolsPromptDialogOptions } from '../execution/UserInterfaceTools'; import type { FormatSubvalueDefinition } from '../formats/_common/FormatSubvalueDefinition'; import type { CsvSettings } from '../formats/csv/CsvSettings'; import type { AbstractFormfactorDefinition } from '../formfactors/_common/AbstractFormfactorDefinition'; @@ -54,47 +55,53 @@ import type { LlmToolsOptions } from '../llm-providers/_common/register/LlmTools import type { CacheItem } from '../llm-providers/_common/utils/cache/CacheItem'; import type { CacheLlmToolsOptions } from '../llm-providers/_common/utils/cache/CacheLlmToolsOptions'; import type { LlmExecutionToolsWithTotalUsage } from '../llm-providers/_common/utils/count-total-usage/LlmExecutionToolsWithTotalUsage'; -import type { AnthropicClaudeExecutionToolsOptions } from '../llm-providers/anthropic-claude/AnthropicClaudeExecutionToolsOptions'; -import type { AnthropicClaudeExecutionToolsDirectOptions } from '../llm-providers/anthropic-claude/AnthropicClaudeExecutionToolsOptions'; -import type { AnthropicClaudeExecutionToolsProxiedOptions } from '../llm-providers/anthropic-claude/AnthropicClaudeExecutionToolsOptions'; +import type { + AnthropicClaudeExecutionToolsDirectOptions, + AnthropicClaudeExecutionToolsOptions, + AnthropicClaudeExecutionToolsProxiedOptions, +} from '../llm-providers/anthropic-claude/AnthropicClaudeExecutionToolsOptions'; import type { AzureOpenAiExecutionToolsOptions } from '../llm-providers/azure-openai/AzureOpenAiExecutionToolsOptions'; import type { GoogleExecutionToolsOptions } from '../llm-providers/google/GoogleExecutionToolsOptions'; import type { OpenAiAssistantExecutionToolsOptions } from '../llm-providers/openai/OpenAiAssistantExecutionToolsOptions'; import type { OpenAiExecutionToolsOptions } from '../llm-providers/openai/OpenAiExecutionToolsOptions'; import type { PromptbookServer_Error } from '../llm-providers/remote/interfaces/PromptbookServer_Error'; -import type { PromptbookServer_ListModels_Request } from '../llm-providers/remote/interfaces/PromptbookServer_ListModels_Request'; -import type { PromptbookServer_ListModels_CollectionRequest } from '../llm-providers/remote/interfaces/PromptbookServer_ListModels_Request'; -import type { PromptbookServer_ListModels_AnonymousRequest } from '../llm-providers/remote/interfaces/PromptbookServer_ListModels_Request'; +import type { + PromptbookServer_ListModels_AnonymousRequest, + PromptbookServer_ListModels_CollectionRequest, + PromptbookServer_ListModels_Request, +} from '../llm-providers/remote/interfaces/PromptbookServer_ListModels_Request'; import type { PromptbookServer_ListModels_Response } from '../llm-providers/remote/interfaces/PromptbookServer_ListModels_Response'; import type { PromptbookServer_Prompt_Progress } from '../llm-providers/remote/interfaces/PromptbookServer_Prompt_Progress'; -import type { PromptbookServer_Prompt_Request } from '../llm-providers/remote/interfaces/PromptbookServer_Prompt_Request'; -import type { PromptbookServer_Prompt_CollectionRequest } from '../llm-providers/remote/interfaces/PromptbookServer_Prompt_Request'; -import type { PromptbookServer_Prompt_AnonymousRequest } from '../llm-providers/remote/interfaces/PromptbookServer_Prompt_Request'; +import type { + PromptbookServer_Prompt_AnonymousRequest, + PromptbookServer_Prompt_CollectionRequest, + PromptbookServer_Prompt_Request, +} from '../llm-providers/remote/interfaces/PromptbookServer_Prompt_Request'; import type { PromptbookServer_Prompt_Response } from '../llm-providers/remote/interfaces/PromptbookServer_Prompt_Response'; import type { RemoteLlmExecutionToolsOptions } from '../llm-providers/remote/interfaces/RemoteLlmExecutionToolsOptions'; -import type { RemoteServerOptions } from '../llm-providers/remote/interfaces/RemoteServerOptions'; -import type { AnonymousRemoteServerOptions } from '../llm-providers/remote/interfaces/RemoteServerOptions'; -import type { CollectionRemoteServerOptions } from '../llm-providers/remote/interfaces/RemoteServerOptions'; -import type { CollectionRemoteServerClientOptions } from '../llm-providers/remote/interfaces/RemoteServerOptions'; +import type { + AnonymousRemoteServerOptions, + CollectionRemoteServerClientOptions, + CollectionRemoteServerOptions, + RemoteServerOptions, +} from '../llm-providers/remote/interfaces/RemoteServerOptions'; import type { VercelExecutionToolsOptions } from '../llm-providers/vercel/VercelExecutionToolsOptions'; import type { VercelProvider } from '../llm-providers/vercel/VercelProvider'; import type { IsPipelineImplementingInterfaceOptions } from '../pipeline/PipelineInterface/isPipelineImplementingInterface'; import type { PipelineInterface } from '../pipeline/PipelineInterface/PipelineInterface'; import type { CommonTaskJson } from '../pipeline/PipelineJson/CommonTaskJson'; import type { DialogTaskJson } from '../pipeline/PipelineJson/DialogTaskJson'; -import type { Expectations } from '../pipeline/PipelineJson/Expectations'; -import type { ExpectationUnit } from '../pipeline/PipelineJson/Expectations'; -import type { ExpectationAmount } from '../pipeline/PipelineJson/Expectations'; +import type { ExpectationAmount, Expectations, ExpectationUnit } from '../pipeline/PipelineJson/Expectations'; import type { KnowledgePiecePreparedJson } from '../pipeline/PipelineJson/KnowledgePieceJson'; -import type { KnowledgeSourceJson } from '../pipeline/PipelineJson/KnowledgeSourceJson'; -import type { KnowledgeSourcePreparedJson } from '../pipeline/PipelineJson/KnowledgeSourceJson'; -import type { ParameterJson } from '../pipeline/PipelineJson/ParameterJson'; -import type { InputParameterJson } from '../pipeline/PipelineJson/ParameterJson'; -import type { IntermediateParameterJson } from '../pipeline/PipelineJson/ParameterJson'; -import type { OutputParameterJson } from '../pipeline/PipelineJson/ParameterJson'; -import type { CommonParameterJson } from '../pipeline/PipelineJson/ParameterJson'; -import type { PersonaJson } from '../pipeline/PipelineJson/PersonaJson'; -import type { PersonaPreparedJson } from '../pipeline/PipelineJson/PersonaJson'; +import type { KnowledgeSourceJson, KnowledgeSourcePreparedJson } from '../pipeline/PipelineJson/KnowledgeSourceJson'; +import type { + CommonParameterJson, + InputParameterJson, + IntermediateParameterJson, + OutputParameterJson, + ParameterJson, +} from '../pipeline/PipelineJson/ParameterJson'; +import type { PersonaJson, PersonaPreparedJson } from '../pipeline/PipelineJson/PersonaJson'; import type { PipelineJson } from '../pipeline/PipelineJson/PipelineJson'; import type { PreparationJson } from '../pipeline/PipelineJson/PreparationJson'; import type { PromptTaskJson } from '../pipeline/PipelineJson/PromptTaskJson'; @@ -106,150 +113,149 @@ import type { PrepareAndScrapeOptions } from '../prepare/PrepareAndScrapeOptions import type { Converter } from '../scrapers/_common/Converter'; import type { ScraperAndConverterMetadata } from '../scrapers/_common/register/ScraperAndConverterMetadata'; import type { ScraperConstructor } from '../scrapers/_common/register/ScraperConstructor'; -import type { Scraper } from '../scrapers/_common/Scraper'; -import type { ScraperSourceHandler } from '../scrapers/_common/Scraper'; +import type { Scraper, ScraperSourceHandler } from '../scrapers/_common/Scraper'; import type { ScraperIntermediateSource } from '../scrapers/_common/ScraperIntermediateSource'; -import type { JavascriptExecutionToolsOptions } from '../scripting/javascript/JavascriptExecutionToolsOptions'; -import type { PostprocessingFunction } from '../scripting/javascript/JavascriptExecutionToolsOptions'; +import type { + JavascriptExecutionToolsOptions, + PostprocessingFunction, +} from '../scripting/javascript/JavascriptExecutionToolsOptions'; import type { PromptbookStorage } from '../storage/_common/PromptbookStorage'; import type { FileCacheStorageOptions } from '../storage/file-cache-storage/FileCacheStorageOptions'; import type { IntermediateFilesStrategy } from '../types/IntermediateFilesStrategy'; -import type { ModelRequirements } from '../types/ModelRequirements'; -import type { CompletionModelRequirements } from '../types/ModelRequirements'; -import type { ChatModelRequirements } from '../types/ModelRequirements'; -import type { EmbeddingModelRequirements } from '../types/ModelRequirements'; +import type { + ChatModelRequirements, + CompletionModelRequirements, + EmbeddingModelRequirements, + ModelRequirements, +} from '../types/ModelRequirements'; import type { ModelVariant } from '../types/ModelVariant'; -import type { Prompt } from '../types/Prompt'; -import type { CompletionPrompt } from '../types/Prompt'; -import type { ChatPrompt } from '../types/Prompt'; -import type { EmbeddingPrompt } from '../types/Prompt'; +import type { ChatPrompt, CompletionPrompt, EmbeddingPrompt, Prompt } from '../types/Prompt'; import type { ScriptLanguage } from '../types/ScriptLanguage'; import type { SectionType } from '../types/SectionType'; import type { TaskProgress } from '../types/TaskProgress'; import type { TaskType } from '../types/TaskType'; import type { string_char_emoji } from '../types/typeAliasEmoji'; -import type { string_business_category_name } from '../types/typeAliases'; -import type { string_model_name } from '../types/typeAliases'; -import type { string_prompt } from '../types/typeAliases'; -import type { string_template } from '../types/typeAliases'; -import type { string_text_prompt } from '../types/typeAliases'; -import type { string_chat_prompt } from '../types/typeAliases'; -import type { string_system_message } from '../types/typeAliases'; -import type { string_completion_prompt } from '../types/typeAliases'; -import type { string_page } from '../types/typeAliases'; -import type { string_mime_type } from '../types/typeAliases'; -import type { string_mime_type_with_wildcard } from '../types/typeAliases'; -import type { string_char } from '../types/typeAliases'; -import type { string_name } from '../types/typeAliases'; -import type { string_parameter_name } from '../types/typeAliases'; -import type { string_parameter_value } from '../types/typeAliases'; -import type { Parameters } from '../types/typeAliases'; -import type { string_reserved_parameter_name } from '../types/typeAliases'; -import type { ReservedParameters } from '../types/typeAliases'; -import type { string_title } from '../types/typeAliases'; -import type { string_persona_description } from '../types/typeAliases'; -import type { string_model_description } from '../types/typeAliases'; -import type { string_knowledge_source_content } from '../types/typeAliases'; -import type { string_knowledge_source_link } from '../types/typeAliases'; -import type { string_html } from '../types/typeAliases'; -import type { string_xml } from '../types/typeAliases'; -import type { string_markdown } from '../types/typeAliases'; -import type { string_markdown_section } from '../types/typeAliases'; -import type { string_markdown_section_content } from '../types/typeAliases'; -import type { string_markdown_text } from '../types/typeAliases'; -import type { string_markdown_codeblock_language } from '../types/typeAliases'; -import type { string_promptbook_documentation_url } from '../types/typeAliases'; -import type { string_domain } from '../types/typeAliases'; -import type { string_tdl } from '../types/typeAliases'; -import type { string_css } from '../types/typeAliases'; -import type { string_svg } from '../types/typeAliases'; -import type { string_script } from '../types/typeAliases'; -import type { string_javascript } from '../types/typeAliases'; -import type { string_json } from '../types/typeAliases'; -import type { string_css_class } from '../types/typeAliases'; -import type { string_css_property } from '../types/typeAliases'; -import type { string_css_value } from '../types/typeAliases'; -import type { string_css_selector } from '../types/typeAliases'; -import type { string_url } from '../types/typeAliases'; -import type { string_base_url } from '../types/typeAliases'; -import type { string_pipeline_url } from '../types/typeAliases'; -import type { string_pipeline_url_with_task_hash } from '../types/typeAliases'; -import type { string_data_url } from '../types/typeAliases'; -import type { string_base64 } from '../types/typeAliases'; -import type { string_href } from '../types/typeAliases'; -import type { string_url_image } from '../types/typeAliases'; -import type { string_executable_path } from '../types/typeAliases'; -import type { string_uri } from '../types/typeAliases'; -import type { string_uri_part } from '../types/typeAliases'; -import type { string_hostname } from '../types/typeAliases'; -import type { string_host } from '../types/typeAliases'; -import type { string_protocol } from '../types/typeAliases'; -import type { string_email } from '../types/typeAliases'; -import type { string_emails } from '../types/typeAliases'; -import type { string_uuid } from '../types/typeAliases'; -import type { string_app_id } from '../types/typeAliases'; -import type { string_user_id } from '../types/typeAliases'; -import type { string_sha256 } from '../types/typeAliases'; -import type { string_semantic_version } from '../types/typeAliases'; -import type { string_version_dependency } from '../types/typeAliases'; -import type { string_file_extension } from '../types/typeAliases'; -import type { string_absolute_filename } from '../types/typeAliases'; -import type { string_relative_filename } from '../types/typeAliases'; -import type { string_filename } from '../types/typeAliases'; -import type { string_absolute_dirname } from '../types/typeAliases'; -import type { string_relative_dirname } from '../types/typeAliases'; -import type { string_dirname } from '../types/typeAliases'; -import type { string_person_fullname } from '../types/typeAliases'; -import type { string_person_profile } from '../types/typeAliases'; -import type { string_license } from '../types/typeAliases'; -import type { string_attribute } from '../types/typeAliases'; -import type { string_attribute_value_scope } from '../types/typeAliases'; -import type { string_color } from '../types/typeAliases'; -import type { string_translate_name } from '../types/typeAliases'; -import type { string_translate_name_not_normalized } from '../types/typeAliases'; -import type { string_translate_language } from '../types/typeAliases'; -import type { string_javascript_name } from '../types/typeAliases'; -import type { string_postprocessing_function_name } from '../types/typeAliases'; -import type { id } from '../types/typeAliases'; -import type { string_token } from '../types/typeAliases'; -import type { string_license_token } from '../types/typeAliases'; -import type { string_password } from '../types/typeAliases'; -import type { string_ssh_key } from '../types/typeAliases'; -import type { string_pgp_key } from '../types/typeAliases'; -import type { string_date_iso8601 } from '../types/typeAliases'; -import type { number_usd } from '../types/typeAliases'; -import type { number_id } from '../types/typeAliases'; -import type { number_linecol_number } from '../types/typeAliases'; -import type { number_tokens } from '../types/typeAliases'; -import type { number_positive } from '../types/typeAliases'; -import type { number_negative } from '../types/typeAliases'; -import type { number_integer } from '../types/typeAliases'; -import type { number_percent } from '../types/typeAliases'; -import type { number_model_temperature } from '../types/typeAliases'; -import type { number_seed } from '../types/typeAliases'; -import type { number_likeness } from '../types/typeAliases'; -import type { number_miliseconds } from '../types/typeAliases'; -import type { number_seconds } from '../types/typeAliases'; -import type { number_minutes } from '../types/typeAliases'; -import type { number_hours } from '../types/typeAliases'; -import type { number_days } from '../types/typeAliases'; -import type { number_weeks } from '../types/typeAliases'; -import type { number_months } from '../types/typeAliases'; -import type { number_years } from '../types/typeAliases'; -import type { number_bytes } from '../types/typeAliases'; -import type { number_kilobytes } from '../types/typeAliases'; -import type { number_megabytes } from '../types/typeAliases'; -import type { number_gigabytes } from '../types/typeAliases'; -import type { number_terabytes } from '../types/typeAliases'; -import type { Registered } from '../utils/$Register'; -import type { Registration } from '../utils/$Register'; -import type { ExecCommandOptions } from '../utils/execCommand/ExecCommandOptions'; -import type { ExecCommandOptionsAdvanced } from '../utils/execCommand/ExecCommandOptions'; +import type { + id, + number_bytes, + number_days, + number_gigabytes, + number_hours, + number_id, + number_integer, + number_kilobytes, + number_likeness, + number_linecol_number, + number_megabytes, + number_miliseconds, + number_minutes, + number_model_temperature, + number_months, + number_negative, + number_percent, + number_positive, + number_seconds, + number_seed, + number_terabytes, + number_tokens, + number_usd, + number_weeks, + number_years, + Parameters, + ReservedParameters, + string_absolute_dirname, + string_absolute_filename, + string_app_id, + string_attribute, + string_attribute_value_scope, + string_base64, + string_base_url, + string_business_category_name, + string_char, + string_chat_prompt, + string_color, + string_completion_prompt, + string_css, + string_css_class, + string_css_property, + string_css_selector, + string_css_value, + string_data_url, + string_date_iso8601, + string_dirname, + string_domain, + string_email, + string_emails, + string_executable_path, + string_file_extension, + string_filename, + string_host, + string_hostname, + string_href, + string_html, + string_javascript, + string_javascript_name, + string_json, + string_knowledge_source_content, + string_knowledge_source_link, + string_license, + string_license_token, + string_markdown, + string_markdown_codeblock_language, + string_markdown_section, + string_markdown_section_content, + string_markdown_text, + string_mime_type, + string_mime_type_with_wildcard, + string_model_description, + string_model_name, + string_name, + string_page, + string_parameter_name, + string_parameter_value, + string_password, + string_person_fullname, + string_person_profile, + string_persona_description, + string_pgp_key, + string_pipeline_url, + string_pipeline_url_with_task_hash, + string_postprocessing_function_name, + string_prompt, + string_promptbook_documentation_url, + string_protocol, + string_relative_dirname, + string_relative_filename, + string_reserved_parameter_name, + string_script, + string_semantic_version, + string_sha256, + string_ssh_key, + string_svg, + string_system_message, + string_tdl, + string_template, + string_text_prompt, + string_title, + string_token, + string_translate_language, + string_translate_name, + string_translate_name_not_normalized, + string_uri, + string_uri_part, + string_url, + string_url_image, + string_user_id, + string_uuid, + string_version_dependency, + string_xml, +} from '../types/typeAliases'; +import type { Registered, Registration } from '../utils/$Register'; +import type { ExecCommandOptions, ExecCommandOptionsAdvanced } from '../utils/execCommand/ExecCommandOptions'; import type { FromtoItems } from '../utils/FromtoItems'; import type { CodeBlock } from '../utils/markdown/extractAllBlocksFromMarkdown'; import type { MarkdownSection } from '../utils/markdown/parseMarkdownSection'; -import type { string_keyword } from '../utils/normalization/IKeywords'; -import type { Keywords } from '../utils/normalization/IKeywords'; +import type { Keywords, string_keyword } from '../utils/normalization/IKeywords'; import type { string_kebab_case } from '../utils/normalization/normalize-to-kebab-case'; import type { string_camelCase } from '../utils/normalization/normalizeTo_camelCase'; import type { string_PascalCase } from '../utils/normalization/normalizeTo_PascalCase'; @@ -261,261 +267,263 @@ import type { TODO_any } from '../utils/organization/TODO_any'; import type { string_promptbook_version } from '../version'; // Note: Entities of the `@promptbook/types` -export type { PipelineCollection }; -export type { Command }; -export type { CommandParser }; -export type { PipelineBothCommandParser }; -export type { PipelineHeadCommandParser }; -export type { PipelineTaskCommandParser }; -export type { CommandParserInput }; -export type { CommandUsagePlace }; -export type { ExpectCommand }; -export type { ForeachJson }; -export type { FormatCommand }; -export type { PrettifyOptions }; -export type { renderPipelineMermaidOptions }; -export type { CallbackInterfaceToolsOptions }; -export type { ErrorJson }; -export type { LocateAppOptions }; -export type { AvailableModel }; -export type { CommonToolsOptions }; -export type { CreatePipelineExecutorOptions }; -export type { EmbeddingVector }; -export type { Executables }; -export type { ExecutionPromptReportJson }; -export type { ExecutionReportJson }; -export type { ExecutionReportString }; -export type { ExecutionReportStringOptions }; -export type { ExecutionTools }; -export type { FilesystemTools }; -export type { LlmExecutionTools }; -export type { LlmExecutionToolsConstructor }; -export type { PipelineExecutor }; -export type { PipelineExecutorResult }; -export type { PromptResult }; -export type { CompletionPromptResult }; -export type { ChatPromptResult }; -export type { EmbeddingPromptResult }; -export type { PromptResultUsage }; -export type { PromptResultUsageCounts }; -export type { ScriptExecutionTools }; -export type { ScriptExecutionToolsExecuteOptions }; -export type { UncertainNumber }; -export type { UserInterfaceTools }; -export type { UserInterfaceToolsPromptDialogOptions }; -export type { FormatSubvalueDefinition }; -export type { CsvSettings }; -export type { AbstractFormfactorDefinition }; -export type { FormfactorDefinition }; -export type { string_formfactor_name }; -export type { LlmToolsConfiguration }; -export type { LlmToolsMetadata }; -export type { LlmToolsOptions }; -export type { CacheItem }; -export type { CacheLlmToolsOptions }; -export type { LlmExecutionToolsWithTotalUsage }; -export type { AnthropicClaudeExecutionToolsOptions }; -export type { AnthropicClaudeExecutionToolsDirectOptions }; -export type { AnthropicClaudeExecutionToolsProxiedOptions }; -export type { AzureOpenAiExecutionToolsOptions }; -export type { GoogleExecutionToolsOptions }; -export type { OpenAiAssistantExecutionToolsOptions }; -export type { OpenAiExecutionToolsOptions }; -export type { PromptbookServer_Error }; -export type { PromptbookServer_ListModels_Request }; -export type { PromptbookServer_ListModels_CollectionRequest }; -export type { PromptbookServer_ListModels_AnonymousRequest }; -export type { PromptbookServer_ListModels_Response }; -export type { PromptbookServer_Prompt_Progress }; -export type { PromptbookServer_Prompt_Request }; -export type { PromptbookServer_Prompt_CollectionRequest }; -export type { PromptbookServer_Prompt_AnonymousRequest }; -export type { PromptbookServer_Prompt_Response }; -export type { RemoteLlmExecutionToolsOptions }; -export type { RemoteServerOptions }; -export type { AnonymousRemoteServerOptions }; -export type { CollectionRemoteServerOptions }; -export type { CollectionRemoteServerClientOptions }; -export type { VercelExecutionToolsOptions }; -export type { VercelProvider }; -export type { IsPipelineImplementingInterfaceOptions }; -export type { PipelineInterface }; -export type { CommonTaskJson }; -export type { DialogTaskJson }; -export type { Expectations }; -export type { ExpectationUnit }; -export type { ExpectationAmount }; -export type { KnowledgePiecePreparedJson }; -export type { KnowledgeSourceJson }; -export type { KnowledgeSourcePreparedJson }; -export type { ParameterJson }; -export type { InputParameterJson }; -export type { IntermediateParameterJson }; -export type { OutputParameterJson }; -export type { CommonParameterJson }; -export type { PersonaJson }; -export type { PersonaPreparedJson }; -export type { PipelineJson }; -export type { PreparationJson }; -export type { PromptTaskJson }; -export type { ScriptTaskJson }; -export type { SimpleTaskJson }; -export type { TaskJson }; -export type { PipelineString }; -export type { PrepareAndScrapeOptions }; -export type { Converter }; -export type { ScraperAndConverterMetadata }; -export type { ScraperConstructor }; -export type { Scraper }; -export type { ScraperSourceHandler }; -export type { ScraperIntermediateSource }; -export type { JavascriptExecutionToolsOptions }; -export type { PostprocessingFunction }; -export type { PromptbookStorage }; -export type { FileCacheStorageOptions }; -export type { IntermediateFilesStrategy }; -export type { ModelRequirements }; -export type { CompletionModelRequirements }; -export type { ChatModelRequirements }; -export type { EmbeddingModelRequirements }; -export type { ModelVariant }; -export type { Prompt }; -export type { CompletionPrompt }; -export type { ChatPrompt }; -export type { EmbeddingPrompt }; -export type { ScriptLanguage }; -export type { SectionType }; -export type { TaskProgress }; -export type { TaskType }; -export type { string_char_emoji }; -export type { string_business_category_name }; -export type { string_model_name }; -export type { string_prompt }; -export type { string_template }; -export type { string_text_prompt }; -export type { string_chat_prompt }; -export type { string_system_message }; -export type { string_completion_prompt }; -export type { string_page }; -export type { string_mime_type }; -export type { string_mime_type_with_wildcard }; -export type { string_char }; -export type { string_name }; -export type { string_parameter_name }; -export type { string_parameter_value }; -export type { Parameters }; -export type { string_reserved_parameter_name }; -export type { ReservedParameters }; -export type { string_title }; -export type { string_persona_description }; -export type { string_model_description }; -export type { string_knowledge_source_content }; -export type { string_knowledge_source_link }; -export type { string_html }; -export type { string_xml }; -export type { string_markdown }; -export type { string_markdown_section }; -export type { string_markdown_section_content }; -export type { string_markdown_text }; -export type { string_markdown_codeblock_language }; -export type { string_promptbook_documentation_url }; -export type { string_domain }; -export type { string_tdl }; -export type { string_css }; -export type { string_svg }; -export type { string_script }; -export type { string_javascript }; -export type { string_json }; -export type { string_css_class }; -export type { string_css_property }; -export type { string_css_value }; -export type { string_css_selector }; -export type { string_url }; -export type { string_base_url }; -export type { string_pipeline_url }; -export type { string_pipeline_url_with_task_hash }; -export type { string_data_url }; -export type { string_base64 }; -export type { string_href }; -export type { string_url_image }; -export type { string_executable_path }; -export type { string_uri }; -export type { string_uri_part }; -export type { string_hostname }; -export type { string_host }; -export type { string_protocol }; -export type { string_email }; -export type { string_emails }; -export type { string_uuid }; -export type { string_app_id }; -export type { string_user_id }; -export type { string_sha256 }; -export type { string_semantic_version }; -export type { string_version_dependency }; -export type { string_file_extension }; -export type { string_absolute_filename }; -export type { string_relative_filename }; -export type { string_filename }; -export type { string_absolute_dirname }; -export type { string_relative_dirname }; -export type { string_dirname }; -export type { string_person_fullname }; -export type { string_person_profile }; -export type { string_license }; -export type { string_attribute }; -export type { string_attribute_value_scope }; -export type { string_color }; -export type { string_translate_name }; -export type { string_translate_name_not_normalized }; -export type { string_translate_language }; -export type { string_javascript_name }; -export type { string_postprocessing_function_name }; -export type { id }; -export type { string_token }; -export type { string_license_token }; -export type { string_password }; -export type { string_ssh_key }; -export type { string_pgp_key }; -export type { string_date_iso8601 }; -export type { number_usd }; -export type { number_id }; -export type { number_linecol_number }; -export type { number_tokens }; -export type { number_positive }; -export type { number_negative }; -export type { number_integer }; -export type { number_percent }; -export type { number_model_temperature }; -export type { number_seed }; -export type { number_likeness }; -export type { number_miliseconds }; -export type { number_seconds }; -export type { number_minutes }; -export type { number_hours }; -export type { number_days }; -export type { number_weeks }; -export type { number_months }; -export type { number_years }; -export type { number_bytes }; -export type { number_kilobytes }; -export type { number_megabytes }; -export type { number_gigabytes }; -export type { number_terabytes }; -export type { Registered }; -export type { Registration }; -export type { ExecCommandOptions }; -export type { ExecCommandOptionsAdvanced }; -export type { FromtoItems }; -export type { CodeBlock }; -export type { MarkdownSection }; -export type { string_keyword }; -export type { Keywords }; -export type { string_kebab_case }; -export type { string_camelCase }; -export type { string_PascalCase }; -export type { string_SCREAMING_CASE }; -export type { string_snake_case }; -export type { empty_object }; -export type { really_any }; -export type { TODO_any }; -export type { string_promptbook_version }; +export type { + AbstractFormfactorDefinition, + AnonymousRemoteServerOptions, + AnthropicClaudeExecutionToolsDirectOptions, + AnthropicClaudeExecutionToolsOptions, + AnthropicClaudeExecutionToolsProxiedOptions, + AvailableModel, + AzureOpenAiExecutionToolsOptions, + CacheItem, + CacheLlmToolsOptions, + CallbackInterfaceToolsOptions, + ChatModelRequirements, + ChatPrompt, + ChatPromptResult, + CodeBlock, + CollectionRemoteServerClientOptions, + CollectionRemoteServerOptions, + Command, + CommandParser, + CommandParserInput, + CommandUsagePlace, + CommonParameterJson, + CommonTaskJson, + CommonToolsOptions, + CompletionModelRequirements, + CompletionPrompt, + CompletionPromptResult, + Converter, + CreatePipelineExecutorOptions, + CsvSettings, + DialogTaskJson, + EmbeddingModelRequirements, + EmbeddingPrompt, + EmbeddingPromptResult, + EmbeddingVector, + empty_object, + ErrorJson, + ExecCommandOptions, + ExecCommandOptionsAdvanced, + Executables, + ExecutionPromptReportJson, + ExecutionReportJson, + ExecutionReportString, + ExecutionReportStringOptions, + ExecutionTools, + ExpectationAmount, + Expectations, + ExpectationUnit, + ExpectCommand, + FileCacheStorageOptions, + FilesystemTools, + ForeachJson, + FormatCommand, + FormatSubvalueDefinition, + FormfactorDefinition, + FromtoItems, + GoogleExecutionToolsOptions, + id, + InputParameterJson, + IntermediateFilesStrategy, + IntermediateParameterJson, + IsPipelineImplementingInterfaceOptions, + JavascriptExecutionToolsOptions, + Keywords, + KnowledgePiecePreparedJson, + KnowledgeSourceJson, + KnowledgeSourcePreparedJson, + LlmExecutionTools, + LlmExecutionToolsConstructor, + LlmExecutionToolsWithTotalUsage, + LlmToolsConfiguration, + LlmToolsMetadata, + LlmToolsOptions, + LocateAppOptions, + MarkdownSection, + ModelRequirements, + ModelVariant, + number_bytes, + number_days, + number_gigabytes, + number_hours, + number_id, + number_integer, + number_kilobytes, + number_likeness, + number_linecol_number, + number_megabytes, + number_miliseconds, + number_minutes, + number_model_temperature, + number_months, + number_negative, + number_percent, + number_positive, + number_seconds, + number_seed, + number_terabytes, + number_tokens, + number_usd, + number_weeks, + number_years, + OpenAiAssistantExecutionToolsOptions, + OpenAiExecutionToolsOptions, + OutputParameterJson, + ParameterJson, + Parameters, + PersonaJson, + PersonaPreparedJson, + PipelineBothCommandParser, + PipelineCollection, + PipelineExecutor, + PipelineExecutorResult, + PipelineHeadCommandParser, + PipelineInterface, + PipelineJson, + PipelineString, + PipelineTaskCommandParser, + PostprocessingFunction, + PreparationJson, + PrepareAndScrapeOptions, + PrettifyOptions, + Prompt, + PromptbookServer_Error, + PromptbookServer_ListModels_AnonymousRequest, + PromptbookServer_ListModels_CollectionRequest, + PromptbookServer_ListModels_Request, + PromptbookServer_ListModels_Response, + PromptbookServer_Prompt_AnonymousRequest, + PromptbookServer_Prompt_CollectionRequest, + PromptbookServer_Prompt_Progress, + PromptbookServer_Prompt_Request, + PromptbookServer_Prompt_Response, + PromptbookStorage, + PromptResult, + PromptResultUsage, + PromptResultUsageCounts, + PromptTaskJson, + really_any, + Registered, + Registration, + RemoteLlmExecutionToolsOptions, + RemoteServerOptions, + renderPipelineMermaidOptions, + ReservedParameters, + Scraper, + ScraperAndConverterMetadata, + ScraperConstructor, + ScraperIntermediateSource, + ScraperSourceHandler, + ScriptExecutionTools, + ScriptExecutionToolsExecuteOptions, + ScriptLanguage, + ScriptTaskJson, + SectionType, + SimpleTaskJson, + string_absolute_dirname, + string_absolute_filename, + string_app_id, + string_attribute, + string_attribute_value_scope, + string_base64, + string_base_url, + string_business_category_name, + string_camelCase, + string_char, + string_char_emoji, + string_chat_prompt, + string_color, + string_completion_prompt, + string_css, + string_css_class, + string_css_property, + string_css_selector, + string_css_value, + string_data_url, + string_date_iso8601, + string_dirname, + string_domain, + string_email, + string_emails, + string_executable_path, + string_file_extension, + string_filename, + string_formfactor_name, + string_host, + string_hostname, + string_href, + string_html, + string_javascript, + string_javascript_name, + string_json, + string_kebab_case, + string_keyword, + string_knowledge_source_content, + string_knowledge_source_link, + string_license, + string_license_token, + string_markdown, + string_markdown_codeblock_language, + string_markdown_section, + string_markdown_section_content, + string_markdown_text, + string_mime_type, + string_mime_type_with_wildcard, + string_model_description, + string_model_name, + string_name, + string_page, + string_parameter_name, + string_parameter_value, + string_PascalCase, + string_password, + string_person_fullname, + string_person_profile, + string_persona_description, + string_pgp_key, + string_pipeline_url, + string_pipeline_url_with_task_hash, + string_postprocessing_function_name, + string_prompt, + string_promptbook_documentation_url, + string_promptbook_version, + string_protocol, + string_relative_dirname, + string_relative_filename, + string_reserved_parameter_name, + string_SCREAMING_CASE, + string_script, + string_semantic_version, + string_sha256, + string_snake_case, + string_ssh_key, + string_svg, + string_system_message, + string_tdl, + string_template, + string_text_prompt, + string_title, + string_token, + string_translate_language, + string_translate_name, + string_translate_name_not_normalized, + string_uri, + string_uri_part, + string_url, + string_url_image, + string_user_id, + string_uuid, + string_version_dependency, + string_xml, + TaskJson, + TaskProgress, + TaskType, + TODO_any, + UncertainNumber, + UserInterfaceTools, + UserInterfaceToolsPromptDialogOptions, + VercelExecutionToolsOptions, + VercelProvider, +}; diff --git a/src/_packages/utils.index.ts b/src/_packages/utils.index.ts index 2e1426f92d..1ec469bc31 100644 --- a/src/_packages/utils.index.ts +++ b/src/_packages/utils.index.ts @@ -1,7 +1,7 @@ // ⚠️ WARNING: This code has been generated so that any manual changes will be overwritten // `@promptbook/utils` -import { renderPromptbookMermaid } from '../conversion/prettify/renderPipelineMermaidOptions'; +import { renderPromptbookMermaid } from '../conversion/prettify/renderPromptbookMermaid'; import { extractParameterNamesFromTask } from '../conversion/utils/extractParameterNamesFromTask'; import { extractVariablesFromScript } from '../conversion/utils/extractVariablesFromScript'; import { renamePipelineParameter } from '../conversion/utils/renamePipelineParameter'; diff --git a/src/conversion/prettify/prettifyPipelineString.ts b/src/conversion/prettify/prettifyPipelineString.ts index bb6ad9dfb4..6142f34e1e 100644 --- a/src/conversion/prettify/prettifyPipelineString.ts +++ b/src/conversion/prettify/prettifyPipelineString.ts @@ -4,7 +4,7 @@ import { addAutoGeneratedSection } from '../../utils/markdown/addAutoGeneratedSe import { prettifyMarkdown } from '../../utils/markdown/prettifyMarkdown'; import { pipelineStringToJson } from '../pipelineStringToJson'; import type { PrettifyOptions } from './PrettifyOptions'; -import { renderPromptbookMermaid } from './renderPipelineMermaidOptions'; +import { renderPromptbookMermaid } from './renderPromptbookMermaid'; /** * Prettyfies Promptbook string and adds Mermaid graph diff --git a/src/conversion/prettify/renderPipelineMermaidOptions.ts b/src/conversion/prettify/renderPromptbookMermaid.ts similarity index 58% rename from src/conversion/prettify/renderPipelineMermaidOptions.ts rename to src/conversion/prettify/renderPromptbookMermaid.ts index 0c023afb4b..7430920462 100644 --- a/src/conversion/prettify/renderPipelineMermaidOptions.ts +++ b/src/conversion/prettify/renderPromptbookMermaid.ts @@ -1,4 +1,6 @@ import { spaceTrim } from 'spacetrim'; +import { really_any } from '../../_packages/types.index'; +import { RESERVED_PARAMETER_NAMES } from '../../config'; import { UnexpectedError } from '../../errors/UnexpectedError'; import type { PipelineJson } from '../../pipeline/PipelineJson/PipelineJson'; import type { TaskJson } from '../../pipeline/PipelineJson/TaskJson'; @@ -25,8 +27,16 @@ export type renderPipelineMermaidOptions = { */ export function renderPromptbookMermaid(pipelineJson: PipelineJson, options?: renderPipelineMermaidOptions): string { const { linkTask = () => null } = options || {}; + let isReservedParameterUsed = false; const parameterNameToTaskName = (parameterName: string_name) => { + const isReservedParameter = RESERVED_PARAMETER_NAMES.includes(parameterName as really_any); + + if (isReservedParameter) { + isReservedParameterUsed = true; + return 'knowledge'; + } + const parameter = pipelineJson.parameters.find((parameter) => parameter.name === parameterName); if (!parameter) { @@ -47,6 +57,40 @@ export function renderPromptbookMermaid(pipelineJson: PipelineJson, options?: re return task.name || normalizeTo_camelCase('task-' + titleToName(task.title)); }; + const tasksAndConnectionsMermaid = pipelineJson.tasks + .flatMap(({ title, dependentParameterNames, resultingParameterName }) => [ + `${parameterNameToTaskName(resultingParameterName)}("${title}")`, + ...dependentParameterNames.map( + (dependentParameterName) => + `${parameterNameToTaskName( + dependentParameterName, + )}--"{${dependentParameterName}}"-->${parameterNameToTaskName(resultingParameterName)}`, + ), + ]) + .join('\n'); + + const parametersMermaid = pipelineJson.parameters + .filter(({ isOutput }) => isOutput) + .map(({ name }) => `${parameterNameToTaskName(name)}--"{${name}}"-->output`) + .join('\n'); + + const tasksLinksMermaid = pipelineJson.tasks + .map((task) => { + const link = linkTask(task); + + if (link === null) { + return ''; + } + + const { href, title } = link; + + const taskName = parameterNameToTaskName(task.resultingParameterName); + + return `click ${taskName} href "${href}" "${title}";`; + }) + .filter((line) => line !== '') + .join('\n'); + const promptbookMermaid = spaceTrim( (block) => ` @@ -57,49 +101,13 @@ export function renderPromptbookMermaid(pipelineJson: PipelineJson, options?: re direction TB - input((Input)):::input - ${block( - pipelineJson.tasks - .flatMap(({ title, dependentParameterNames, resultingParameterName }) => [ - `${parameterNameToTaskName(resultingParameterName)}("${title}")`, - ...dependentParameterNames.map( - (dependentParameterName) => - `${parameterNameToTaskName( - dependentParameterName, - )}--"{${dependentParameterName}}"-->${parameterNameToTaskName( - resultingParameterName, - )}`, - ), - ]) - .join('\n'), - )} - - ${block( - pipelineJson.parameters - .filter(({ isOutput }) => isOutput) - .map(({ name }) => `${parameterNameToTaskName(name)}--"{${name}}"-->output`) - .join('\n'), - )} - output((Output)):::output - - ${block( - pipelineJson.tasks - .map((task) => { - const link = linkTask(task); + input((Input)):::input${!isReservedParameterUsed ? '' : `\nreserved((Knowledge)):::reserved`} + ${block(tasksAndConnectionsMermaid)} - if (link === null) { - return ''; - } - - const { href, title } = link; - - const taskName = parameterNameToTaskName(task.resultingParameterName); + ${block(parametersMermaid)} + output((Output)):::output - return `click ${taskName} href "${href}" "${title}";`; - }) - .filter((line) => line !== '') - .join('\n'), - )} + ${block(tasksLinksMermaid)} classDef input color: grey; classDef output color: grey;