@promptbook/markdown-utils 0.103.0-41 → 0.103.0-43
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.
- package/esm/index.es.js +40 -113
- package/esm/index.es.js.map +1 -1
- package/esm/typings/src/_packages/core.index.d.ts +6 -0
- package/esm/typings/src/_packages/node.index.d.ts +0 -2
- package/esm/typings/src/_packages/types.index.d.ts +14 -0
- package/esm/typings/src/_packages/utils.index.d.ts +2 -0
- package/esm/typings/src/book-2.0/agent-source/AgentBasicInformation.d.ts +2 -4
- package/esm/typings/src/book-2.0/agent-source/padBook.d.ts +1 -1
- package/esm/typings/src/book-2.0/agent-source/string_book.d.ts +1 -0
- package/esm/typings/src/book-components/AvatarProfile/AvatarProfile/AvatarProfile.d.ts +1 -1
- package/esm/typings/src/book-components/BookEditor/BookEditor.d.ts +1 -1
- package/esm/typings/src/book-components/Chat/save/_common/ChatSaveFormatDefinition.d.ts +1 -1
- package/esm/typings/src/book-components/Chat/types/ChatParticipant.d.ts +1 -1
- package/esm/typings/src/book-components/Qr/BrandedQrCode.d.ts +1 -1
- package/esm/typings/src/book-components/Qr/useQrCode.d.ts +1 -1
- package/esm/typings/src/cli/cli-commands/_boilerplate.d.ts +1 -1
- package/esm/typings/src/cli/cli-commands/about.d.ts +1 -1
- package/esm/typings/src/cli/cli-commands/hello.d.ts +1 -1
- package/esm/typings/src/cli/cli-commands/list-models.d.ts +1 -1
- package/esm/typings/src/cli/cli-commands/list-scrapers.d.ts +1 -1
- package/esm/typings/src/cli/cli-commands/login.d.ts +1 -1
- package/esm/typings/src/cli/cli-commands/make.d.ts +1 -1
- package/esm/typings/src/cli/cli-commands/prettify.d.ts +1 -1
- package/esm/typings/src/cli/cli-commands/run.d.ts +1 -1
- package/esm/typings/src/cli/cli-commands/start-agents-server.d.ts +1 -1
- package/esm/typings/src/cli/cli-commands/start-pipelines-server.d.ts +1 -1
- package/esm/typings/src/cli/cli-commands/test-command.d.ts +1 -1
- package/esm/typings/src/cli/common/$addGlobalOptionsToCommand.d.ts +1 -1
- package/esm/typings/src/collection/agent-collection/AgentCollection.d.ts +14 -12
- package/esm/typings/src/collection/agent-collection/constructors/agent-collection-in-supabase/AgentCollectionInSupabase.d.ts +55 -0
- package/esm/typings/src/collection/agent-collection/constructors/agent-collection-in-supabase/AgentsDatabaseSchema.d.ts +129 -0
- package/esm/typings/src/commands/_common/types/CommandParser.d.ts +1 -1
- package/esm/typings/src/config.d.ts +1 -1
- package/esm/typings/src/errors/0-index.d.ts +3 -0
- package/esm/typings/src/errors/DatabaseError.d.ts +9 -0
- package/esm/typings/src/execution/createPipelineExecutor/40-executeAttempts.d.ts +1 -1
- package/esm/typings/src/high-level-abstractions/_common/HighLevelAbstraction.d.ts +1 -1
- package/esm/typings/src/llm-providers/_common/register/$registeredLlmToolsMessage.d.ts +1 -1
- package/esm/typings/src/llm-providers/_common/register/LlmToolsMetadata.d.ts +1 -1
- package/esm/typings/src/llm-providers/agent/Agent.d.ts +5 -2
- package/esm/typings/src/llm-providers/agent/AgentLlmExecutionTools.d.ts +1 -1
- package/esm/typings/src/llm-providers/agent/AgentOptions.d.ts +4 -2
- package/esm/typings/src/llm-providers/agent/CreateAgentLlmExecutionToolsOptions.d.ts +2 -2
- package/esm/typings/src/llm-providers/agent/createAgentLlmExecutionTools.d.ts +1 -1
- package/esm/typings/src/prepare/PrepareAndScrapeOptions.d.ts +1 -0
- package/esm/typings/src/remote-server/startAgentServer.d.ts +2 -2
- package/esm/typings/src/remote-server/types/RemoteServerOptions.d.ts +0 -19
- package/esm/typings/src/storage/env-storage/$EnvStorage.d.ts +1 -1
- package/esm/typings/src/transpilers/_common/BookTranspiler.d.ts +5 -1
- package/esm/typings/src/transpilers/_common/BookTranspilerOptions.d.ts +1 -1
- package/esm/typings/src/transpilers/_common/register/$bookTranspilersRegister.d.ts +1 -1
- package/esm/typings/src/transpilers/formatted-book-in-markdown/FormattedBookInMarkdownTranspiler.d.ts +4 -1
- package/esm/typings/src/transpilers/formatted-book-in-markdown/register.d.ts +1 -1
- package/esm/typings/src/transpilers/openai-sdk/OpenAiSdkTranspiler.d.ts +4 -1
- package/esm/typings/src/transpilers/openai-sdk/register.d.ts +1 -1
- package/esm/typings/src/utils/color/operators/darken.d.ts +1 -1
- package/esm/typings/src/utils/color/operators/grayscale.d.ts +1 -1
- package/esm/typings/src/utils/color/operators/lighten.d.ts +1 -1
- package/esm/typings/src/utils/color/operators/mixWithColor.d.ts +1 -1
- package/esm/typings/src/utils/color/operators/saturate.d.ts +1 -1
- package/esm/typings/src/utils/environment/$detectRuntimeEnvironment.d.ts +16 -0
- package/esm/typings/src/utils/execCommand/$execCommand.d.ts +1 -1
- package/esm/typings/src/utils/execCommand/$execCommands.d.ts +1 -1
- package/esm/typings/src/utils/files/$induceBookDownload.d.ts +2 -2
- package/esm/typings/src/utils/files/$induceFileDownload.d.ts +2 -2
- package/esm/typings/src/utils/files/ObjectUrl.d.ts +1 -1
- package/esm/typings/src/utils/misc/aboutPromptbookInformation.d.ts +6 -0
- package/esm/typings/src/utils/organization/$side_effect.d.ts +1 -1
- package/esm/typings/src/utils/random/$generateBookBoilerplate.d.ts +22 -0
- package/esm/typings/src/utils/random/$randomToken.d.ts +1 -0
- package/esm/typings/src/utils/serialization/$deepFreeze.d.ts +1 -1
- package/esm/typings/src/utils/serialization/serializeToPromptbookJavascript.d.ts +2 -2
- package/esm/typings/src/version.d.ts +1 -1
- package/package.json +1 -1
- package/umd/index.umd.js +40 -113
- package/umd/index.umd.js.map +1 -1
- package/esm/typings/src/collection/agent-collection/constructors/AgentCollectionInDirectory.d.ts +0 -88
- package/esm/typings/src/collection/agent-collection/constructors/AgentCollectionInDirectory.test.d.ts +0 -1
- package/esm/typings/src/execution/utils/logLlmCall.d.ts +0 -8
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { BehaviorSubject } from 'rxjs';
|
|
2
|
-
import { AgentBasicInformation, BookParameter
|
|
3
|
-
import {
|
|
2
|
+
import type { AgentBasicInformation, BookParameter } from '../../book-2.0/agent-source/AgentBasicInformation';
|
|
3
|
+
import type { string_book } from '../../book-2.0/agent-source/string_book';
|
|
4
|
+
import type { LlmExecutionTools } from '../../execution/LlmExecutionTools';
|
|
5
|
+
import type { string_agent_name, string_url_image } from '../../types/typeAliases';
|
|
6
|
+
import type { AgentOptions } from './AgentOptions';
|
|
4
7
|
/**
|
|
5
8
|
* Represents one AI Agent
|
|
6
9
|
*
|
|
@@ -5,7 +5,7 @@ import type { LlmExecutionTools } from '../../execution/LlmExecutionTools';
|
|
|
5
5
|
import type { ChatPromptResult } from '../../execution/PromptResult';
|
|
6
6
|
import type { Prompt } from '../../types/Prompt';
|
|
7
7
|
import type { string_markdown, string_markdown_text, string_model_name, string_title } from '../../types/typeAliases';
|
|
8
|
-
import { CreateAgentLlmExecutionToolsOptions } from './CreateAgentLlmExecutionToolsOptions';
|
|
8
|
+
import type { CreateAgentLlmExecutionToolsOptions } from './CreateAgentLlmExecutionToolsOptions';
|
|
9
9
|
/**
|
|
10
10
|
* Execution Tools for calling LLM models with a predefined agent "soul"
|
|
11
11
|
* This wraps underlying LLM execution tools and applies agent-specific system prompts and requirements
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import type { string_book } from '../../book-2.0/agent-source/string_book';
|
|
2
|
+
import type { CommonToolsOptions } from '../../execution/CommonToolsOptions';
|
|
3
|
+
import type { ExecutionTools } from '../../execution/ExecutionTools';
|
|
4
|
+
import type { Updatable } from '../../types/Updatable';
|
|
3
5
|
/**
|
|
4
6
|
* Options for creating an Agent
|
|
5
7
|
*/
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { string_book } from '../../
|
|
1
|
+
import type { string_book } from '../../book-2.0/agent-source/string_book';
|
|
2
2
|
import type { LlmExecutionTools } from '../../execution/LlmExecutionTools';
|
|
3
|
-
import
|
|
3
|
+
import { OpenAiAssistantExecutionTools } from '../openai/OpenAiAssistantExecutionTools';
|
|
4
4
|
/**
|
|
5
5
|
* Options for creating AgentLlmExecutionTools
|
|
6
6
|
*/
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { AgentLlmExecutionTools } from './AgentLlmExecutionTools';
|
|
2
|
-
import { CreateAgentLlmExecutionToolsOptions } from './CreateAgentLlmExecutionToolsOptions';
|
|
2
|
+
import type { CreateAgentLlmExecutionToolsOptions } from './CreateAgentLlmExecutionToolsOptions';
|
|
3
3
|
/**
|
|
4
4
|
* Creates new AgentLlmExecutionTools that wrap underlying LLM tools with agent-specific behavior
|
|
5
5
|
*
|
|
@@ -47,5 +47,6 @@ export type PrepareAndScrapeOptions = {
|
|
|
47
47
|
readonly isVerbose?: boolean;
|
|
48
48
|
};
|
|
49
49
|
/**
|
|
50
|
+
* TODO: [🧠] Maybe extend from `CommonToolsOptions`
|
|
50
51
|
* TODO: [🧠] Maybe split `PrepareAndScrapeOptions` and `ScrapeOptions` (`ScrapeOptions` should be extended from `PrepareAndScrapeOptions`)
|
|
51
52
|
*/
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import type { number_port } from '../types/typeAliases';
|
|
2
|
+
import type { TODO_any } from '../utils/organization/TODO_any';
|
|
3
3
|
type AgentsServerOptions = {
|
|
4
4
|
/**
|
|
5
5
|
* !!!
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import type { Request, Response } from 'express';
|
|
2
2
|
import type { Promisable } from 'type-fest';
|
|
3
|
-
import { really_any } from '../../_packages/types.index';
|
|
4
3
|
import type { PipelineCollection } from '../../collection/pipeline-collection/PipelineCollection';
|
|
5
4
|
import { AuthenticationError } from '../../errors/AuthenticationError';
|
|
6
5
|
import type { CommonToolsOptions } from '../../execution/CommonToolsOptions';
|
|
@@ -27,24 +26,6 @@ export type RemoteServerOptions<TCustomOptions> = CommonToolsOptions & {
|
|
|
27
26
|
* @property {number} port The port number the server will listen on.
|
|
28
27
|
*/
|
|
29
28
|
readonly port: number;
|
|
30
|
-
/**
|
|
31
|
-
* CORS options to apply to all endpoints (REST, UI, socket.io, etc.).
|
|
32
|
-
* Accepts the same options as the `cors` npm package and socket.io's CORS config.
|
|
33
|
-
* If not provided, defaults to permissive CORS (origin: '*').
|
|
34
|
-
* @see https://www.npmjs.com/package/cors
|
|
35
|
-
* @see https://socket.io/docs/v4/server-options/#cors
|
|
36
|
-
*/
|
|
37
|
-
readonly cors?: {
|
|
38
|
-
origin?: string | string[] | boolean;
|
|
39
|
-
methods?: string | string[];
|
|
40
|
-
allowedHeaders?: string | string[];
|
|
41
|
-
exposedHeaders?: string | string[];
|
|
42
|
-
credentials?: boolean;
|
|
43
|
-
maxAge?: number;
|
|
44
|
-
preflightContinue?: boolean;
|
|
45
|
-
optionsSuccessStatus?: number;
|
|
46
|
-
[key: string]: really_any;
|
|
47
|
-
};
|
|
48
29
|
/**
|
|
49
30
|
* Enable rich UI (React + Tailwind) at `/` path.
|
|
50
31
|
* Default: true
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import { Promisable } from 'type-fest';
|
|
2
|
-
import {
|
|
2
|
+
import type { string_book } from '../../book-2.0/agent-source/string_book';
|
|
3
|
+
import type { ExecutionTools } from '../../execution/ExecutionTools';
|
|
4
|
+
import type { string_name, string_script, string_title } from '../../types/typeAliases';
|
|
5
|
+
import type { Registered } from '../../utils/misc/$Register';
|
|
6
|
+
import type { BookTranspilerOptions } from './BookTranspilerOptions';
|
|
3
7
|
/**
|
|
4
8
|
* Transpiler takes a book and transpiles it into another format (e.g., Langchain).
|
|
5
9
|
*/
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { string_book } from '../../book-2.0/agent-source/string_book';
|
|
2
|
+
import type { ExecutionTools } from '../../execution/ExecutionTools';
|
|
3
|
+
import type { string_markdown } from '../../types/typeAliases';
|
|
4
|
+
import type { BookTranspilerOptions } from '../_common/BookTranspilerOptions';
|
|
2
5
|
/**
|
|
3
6
|
* Converts a book into a 1:1 formatted markdown
|
|
4
7
|
*
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { string_book } from '../../book-2.0/agent-source/string_book';
|
|
2
|
+
import type { ExecutionTools } from '../../execution/ExecutionTools';
|
|
3
|
+
import type { string_script } from '../../types/typeAliases';
|
|
4
|
+
import type { BookTranspilerOptions } from '../_common/BookTranspilerOptions';
|
|
2
5
|
/**
|
|
3
6
|
* Transpiler to Javascript code using OpenAI SDK.
|
|
4
7
|
*
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import type { number_percent } from '../../../types/typeAliases';
|
|
1
2
|
import { Color } from '../Color';
|
|
2
3
|
import type { ColorTransformer } from './ColorTransformer';
|
|
3
|
-
import { number_percent } from '../../../types/typeAliases';
|
|
4
4
|
/**
|
|
5
5
|
* Makes color transformer which returns a mix of two colors based on a ratio
|
|
6
6
|
*
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns information about the current runtime environment
|
|
3
|
+
*
|
|
4
|
+
* Note: `$` is used to indicate that this function is not a pure function - it looks at the global object to determine the environments
|
|
5
|
+
*
|
|
6
|
+
* @public exported from `@promptbook/utils`
|
|
7
|
+
*/
|
|
8
|
+
export declare function $detectRuntimeEnvironment(): {
|
|
9
|
+
isRunningInBrowser: any;
|
|
10
|
+
isRunningInJest: any;
|
|
11
|
+
isRunningInNode: any;
|
|
12
|
+
isRunningInWebWorker: any;
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* TODO: [🎺] Also detect and report node version here
|
|
16
|
+
*/
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { string_book } from '../../
|
|
2
|
-
import { $side_effect } from '../organization/$side_effect';
|
|
1
|
+
import type { string_book } from '../../book-2.0/agent-source/string_book';
|
|
2
|
+
import type { $side_effect } from '../organization/$side_effect';
|
|
3
3
|
/**
|
|
4
4
|
* Download a Book in a browser
|
|
5
5
|
*
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { string_url } from '../../types/typeAliases';
|
|
2
|
-
import { $side_effect } from '../organization/$side_effect';
|
|
1
|
+
import type { string_url } from '../../types/typeAliases';
|
|
2
|
+
import type { $side_effect } from '../organization/$side_effect';
|
|
3
3
|
/**
|
|
4
4
|
* Download a File in a browser
|
|
5
5
|
*
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { IDestroyable, Registration } from 'destroyable';
|
|
2
|
-
import { string_mime_type, string_url } from '../../types/typeAliases';
|
|
2
|
+
import type { string_mime_type, string_url } from '../../types/typeAliases';
|
|
3
3
|
/**
|
|
4
4
|
* Converts Blob, File or MediaSource to url using URL.createObjectURL
|
|
5
5
|
*
|
|
@@ -6,6 +6,12 @@ export type AboutPromptbookInformationOptions = {
|
|
|
6
6
|
* @default true
|
|
7
7
|
*/
|
|
8
8
|
isServersInfoIncluded?: boolean;
|
|
9
|
+
/**
|
|
10
|
+
* Include information about runtime environment
|
|
11
|
+
*
|
|
12
|
+
* @default true
|
|
13
|
+
*/
|
|
14
|
+
isRuntimeEnvironmentInfoIncluded?: boolean;
|
|
9
15
|
};
|
|
10
16
|
/**
|
|
11
17
|
* Provide information about Promptbook, engine version, book language version, servers, ...
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { PartialDeep } from 'type-fest';
|
|
2
|
+
import type { AgentBasicInformation } from '../../book-2.0/agent-source/AgentBasicInformation';
|
|
3
|
+
import { string_book } from '../../book-2.0/agent-source/string_book';
|
|
4
|
+
import { string_agent_name } from '../../types/typeAliases';
|
|
5
|
+
type GenerateBookBoilerplateOptions = PartialDeep<Omit<AgentBasicInformation, 'parameters'>> & {
|
|
6
|
+
/**
|
|
7
|
+
* Name of the parent agent to inherit from
|
|
8
|
+
*
|
|
9
|
+
* @default 'Adam'
|
|
10
|
+
*/
|
|
11
|
+
parentAgentName?: string_agent_name;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* Generates boilerplate for a new agent book
|
|
15
|
+
*
|
|
16
|
+
* Note: `$` is used to indicate that this function is not a pure function - it is not deterministic
|
|
17
|
+
* Note: This function is using cryptographically secure components internally
|
|
18
|
+
*
|
|
19
|
+
* @public exported from `@promptbook/core`
|
|
20
|
+
*/
|
|
21
|
+
export declare function $generateBookBoilerplate(options?: GenerateBookBoilerplateOptions): string_book;
|
|
22
|
+
export {};
|
|
@@ -2,6 +2,7 @@ import type { string_token } from '../../types/typeAliases';
|
|
|
2
2
|
/**
|
|
3
3
|
* Generates random token
|
|
4
4
|
*
|
|
5
|
+
* Note: `$` is used to indicate that this function is not a pure function - it is not deterministic
|
|
5
6
|
* Note: This function is cryptographically secure (it uses crypto.randomBytes internally)
|
|
6
7
|
*
|
|
7
8
|
* @private internal helper function
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { string_javascript } from '../../types/typeAliases';
|
|
2
|
-
import { TODO_any } from '../organization/TODO_any';
|
|
1
|
+
import type { string_javascript } from '../../types/typeAliases';
|
|
2
|
+
import type { TODO_any } from '../organization/TODO_any';
|
|
3
3
|
type SerializeToPromptbookJavascriptReturn = {
|
|
4
4
|
/**
|
|
5
5
|
* Array of import statements required for the `value` to work
|
|
@@ -15,7 +15,7 @@ export declare const BOOK_LANGUAGE_VERSION: string_semantic_version;
|
|
|
15
15
|
export declare const PROMPTBOOK_ENGINE_VERSION: string_promptbook_version;
|
|
16
16
|
/**
|
|
17
17
|
* Represents the version string of the Promptbook engine.
|
|
18
|
-
* It follows semantic versioning (e.g., `0.103.0-
|
|
18
|
+
* It follows semantic versioning (e.g., `0.103.0-42`).
|
|
19
19
|
*
|
|
20
20
|
* @generated
|
|
21
21
|
*/
|
package/package.json
CHANGED
package/umd/index.umd.js
CHANGED
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
* @generated
|
|
25
25
|
* @see https://github.com/webgptorg/promptbook
|
|
26
26
|
*/
|
|
27
|
-
const PROMPTBOOK_ENGINE_VERSION = '0.103.0-
|
|
27
|
+
const PROMPTBOOK_ENGINE_VERSION = '0.103.0-43';
|
|
28
28
|
/**
|
|
29
29
|
* TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
|
|
30
30
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
@@ -831,6 +831,23 @@
|
|
|
831
831
|
* TODO: Maybe connect with textures
|
|
832
832
|
*/
|
|
833
833
|
|
|
834
|
+
/**
|
|
835
|
+
* Makes color transformer which returns a grayscale version of the color
|
|
836
|
+
*
|
|
837
|
+
* @param amount from 0 to 1
|
|
838
|
+
*
|
|
839
|
+
* @public exported from `@promptbook/color`
|
|
840
|
+
*/
|
|
841
|
+
function grayscale(amount) {
|
|
842
|
+
return ({ red, green, blue, alpha }) => {
|
|
843
|
+
const average = (red + green + blue) / 3;
|
|
844
|
+
red = Math.round(average * amount + red * (1 - amount));
|
|
845
|
+
green = Math.round(average * amount + green * (1 - amount));
|
|
846
|
+
blue = Math.round(average * amount + blue * (1 - amount));
|
|
847
|
+
return Color.fromValues(red, green, blue, alpha);
|
|
848
|
+
};
|
|
849
|
+
}
|
|
850
|
+
|
|
834
851
|
/**
|
|
835
852
|
* Converts HSL values to RGB values
|
|
836
853
|
*
|
|
@@ -946,102 +963,6 @@
|
|
|
946
963
|
* TODO: Maybe implement by mix+hsl
|
|
947
964
|
*/
|
|
948
965
|
|
|
949
|
-
/**
|
|
950
|
-
* Calculates distance between two colors
|
|
951
|
-
*
|
|
952
|
-
* @param color1 first color
|
|
953
|
-
* @param color2 second color
|
|
954
|
-
*
|
|
955
|
-
* Note: This function is inefficient. Use colorDistanceSquared instead if possible.
|
|
956
|
-
*
|
|
957
|
-
* @public exported from `@promptbook/color`
|
|
958
|
-
*/
|
|
959
|
-
/**
|
|
960
|
-
* Calculates distance between two colors without square root
|
|
961
|
-
*
|
|
962
|
-
* @param color1 first color
|
|
963
|
-
* @param color2 second color
|
|
964
|
-
*
|
|
965
|
-
* @public exported from `@promptbook/color`
|
|
966
|
-
*/
|
|
967
|
-
function colorDistanceSquared(color1, color2) {
|
|
968
|
-
const rmean = (color1.red + color2.red) / 2;
|
|
969
|
-
const r = color1.red - color2.red;
|
|
970
|
-
const g = color1.green - color2.green;
|
|
971
|
-
const b = color1.blue - color2.blue;
|
|
972
|
-
const weightR = 2 + rmean / 256;
|
|
973
|
-
const weightG = 4.0;
|
|
974
|
-
const weightB = 2 + (255 - rmean) / 256;
|
|
975
|
-
const distance = weightR * r * r + weightG * g * g + weightB * b * b;
|
|
976
|
-
return distance;
|
|
977
|
-
}
|
|
978
|
-
|
|
979
|
-
/**
|
|
980
|
-
* Makes color transformer which finds the nearest color from the given list
|
|
981
|
-
*
|
|
982
|
-
* @param colors array of colors to choose from
|
|
983
|
-
*
|
|
984
|
-
* @public exported from `@promptbook/color`
|
|
985
|
-
*/
|
|
986
|
-
function nearest(...colors) {
|
|
987
|
-
return (color) => {
|
|
988
|
-
const distances = colors.map((c) => colorDistanceSquared(c, color));
|
|
989
|
-
const minDistance = Math.min(...distances);
|
|
990
|
-
const minIndex = distances.indexOf(minDistance);
|
|
991
|
-
const nearestColor = colors[minIndex];
|
|
992
|
-
return nearestColor;
|
|
993
|
-
};
|
|
994
|
-
}
|
|
995
|
-
|
|
996
|
-
/**
|
|
997
|
-
* Color transformer which returns the negative color
|
|
998
|
-
*
|
|
999
|
-
* @public exported from `@promptbook/color`
|
|
1000
|
-
*/
|
|
1001
|
-
function negative(color) {
|
|
1002
|
-
const r = 255 - color.red;
|
|
1003
|
-
const g = 255 - color.green;
|
|
1004
|
-
const b = 255 - color.blue;
|
|
1005
|
-
return Color.fromValues(r, g, b, color.alpha);
|
|
1006
|
-
}
|
|
1007
|
-
|
|
1008
|
-
/**
|
|
1009
|
-
* Makes color transformer which finds the furthest color from the given list
|
|
1010
|
-
*
|
|
1011
|
-
* @param colors array of colors to choose from
|
|
1012
|
-
*
|
|
1013
|
-
* @public exported from `@promptbook/color`
|
|
1014
|
-
*/
|
|
1015
|
-
function furthest(...colors) {
|
|
1016
|
-
return (color) => {
|
|
1017
|
-
const furthestColor = negative(nearest(...colors.map(negative))(color));
|
|
1018
|
-
return furthestColor;
|
|
1019
|
-
};
|
|
1020
|
-
}
|
|
1021
|
-
/**
|
|
1022
|
-
* Makes color transformer which finds the best text color (black or white) for the given background color
|
|
1023
|
-
*
|
|
1024
|
-
* @public exported from `@promptbook/color`
|
|
1025
|
-
*/
|
|
1026
|
-
furthest(Color.get('white'), Color.from('black'));
|
|
1027
|
-
|
|
1028
|
-
/**
|
|
1029
|
-
* Makes color transformer which returns a grayscale version of the color
|
|
1030
|
-
*
|
|
1031
|
-
* @param amount from 0 to 1
|
|
1032
|
-
*
|
|
1033
|
-
* @public exported from `@promptbook/color`
|
|
1034
|
-
*/
|
|
1035
|
-
function grayscale(amount) {
|
|
1036
|
-
return ({ red, green, blue, alpha }) => {
|
|
1037
|
-
const average = (red + green + blue) / 3;
|
|
1038
|
-
red = Math.round(average * amount + red * (1 - amount));
|
|
1039
|
-
green = Math.round(average * amount + green * (1 - amount));
|
|
1040
|
-
blue = Math.round(average * amount + blue * (1 - amount));
|
|
1041
|
-
return Color.fromValues(red, green, blue, alpha);
|
|
1042
|
-
};
|
|
1043
|
-
}
|
|
1044
|
-
|
|
1045
966
|
/**
|
|
1046
967
|
* Makes color transformer which saturate the given color
|
|
1047
968
|
*
|
|
@@ -2679,6 +2600,7 @@
|
|
|
2679
2600
|
/**
|
|
2680
2601
|
* Generates random token
|
|
2681
2602
|
*
|
|
2603
|
+
* Note: `$` is used to indicate that this function is not a pure function - it is not deterministic
|
|
2682
2604
|
* Note: This function is cryptographically secure (it uses crypto.randomBytes internally)
|
|
2683
2605
|
*
|
|
2684
2606
|
* @private internal helper function
|
|
@@ -2806,6 +2728,19 @@
|
|
|
2806
2728
|
}
|
|
2807
2729
|
}
|
|
2808
2730
|
|
|
2731
|
+
/**
|
|
2732
|
+
* This error indicates error from the database
|
|
2733
|
+
*
|
|
2734
|
+
* @public exported from `@promptbook/core`
|
|
2735
|
+
*/
|
|
2736
|
+
class DatabaseError extends Error {
|
|
2737
|
+
constructor(message) {
|
|
2738
|
+
super(message);
|
|
2739
|
+
this.name = 'DatabaseError';
|
|
2740
|
+
Object.setPrototypeOf(this, DatabaseError.prototype);
|
|
2741
|
+
}
|
|
2742
|
+
}
|
|
2743
|
+
|
|
2809
2744
|
/**
|
|
2810
2745
|
* This error type indicates that you try to use a feature that is not available in the current environment
|
|
2811
2746
|
*
|
|
@@ -2935,6 +2870,7 @@
|
|
|
2935
2870
|
UnexpectedError,
|
|
2936
2871
|
WrappedError,
|
|
2937
2872
|
NotAllowed,
|
|
2873
|
+
DatabaseError,
|
|
2938
2874
|
// TODO: [🪑]> VersionMismatchError,
|
|
2939
2875
|
};
|
|
2940
2876
|
/**
|
|
@@ -5763,18 +5699,6 @@
|
|
|
5763
5699
|
return replacedTemplates;
|
|
5764
5700
|
}
|
|
5765
5701
|
|
|
5766
|
-
/**
|
|
5767
|
-
* Logs an LLM call with the given report.
|
|
5768
|
-
*
|
|
5769
|
-
* @private internal utility of `createPipelineExecutor`
|
|
5770
|
-
*/
|
|
5771
|
-
function logLlmCall(logLlmCall, report) {
|
|
5772
|
-
logLlmCall({
|
|
5773
|
-
modelName: 'model' /* <- TODO: How to get model name from the report */,
|
|
5774
|
-
report,
|
|
5775
|
-
});
|
|
5776
|
-
}
|
|
5777
|
-
|
|
5778
5702
|
/**
|
|
5779
5703
|
* Counts number of characters in the text
|
|
5780
5704
|
*
|
|
@@ -6018,7 +5942,7 @@
|
|
|
6018
5942
|
*/
|
|
6019
5943
|
async function executeAttempts(options) {
|
|
6020
5944
|
const { jokerParameterNames, priority, maxAttempts, // <- Note: [💂]
|
|
6021
|
-
preparedContent, parameters, task, preparedPipeline, tools, $executionReport, pipelineIdentification, maxExecutionAttempts, onProgress, logLlmCall
|
|
5945
|
+
preparedContent, parameters, task, preparedPipeline, tools, $executionReport, pipelineIdentification, maxExecutionAttempts, onProgress, logLlmCall, } = options;
|
|
6022
5946
|
const $ongoingTaskResult = {
|
|
6023
5947
|
$result: null,
|
|
6024
5948
|
$resultString: null,
|
|
@@ -6280,8 +6204,11 @@
|
|
|
6280
6204
|
: serializeError($ongoingTaskResult.$expectError),
|
|
6281
6205
|
};
|
|
6282
6206
|
$executionReport.promptExecutions.push(executionPromptReport);
|
|
6283
|
-
if (logLlmCall
|
|
6284
|
-
logLlmCall(
|
|
6207
|
+
if (logLlmCall) {
|
|
6208
|
+
logLlmCall({
|
|
6209
|
+
modelName: 'model' /* <- TODO: How to get model name from the report */,
|
|
6210
|
+
report: executionPromptReport,
|
|
6211
|
+
});
|
|
6285
6212
|
}
|
|
6286
6213
|
}
|
|
6287
6214
|
}
|
|
@@ -6555,7 +6482,7 @@
|
|
|
6555
6482
|
},
|
|
6556
6483
|
content: task.content,
|
|
6557
6484
|
parameters,
|
|
6558
|
-
};
|
|
6485
|
+
}; /* <- Note: [🤛] */
|
|
6559
6486
|
const taskEmbeddingResult = await llmTools.callEmbeddingModel(taskEmbeddingPrompt);
|
|
6560
6487
|
const knowledgePiecesWithRelevance = preparedPipeline.knowledgePieces.map((knowledgePiece) => {
|
|
6561
6488
|
const { index } = knowledgePiece;
|