@promptbook/ollama 0.112.0-13 → 0.112.0-16
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 +496 -496
- package/esm/index.es.js.map +1 -1
- package/esm/src/cli/cli-commands/coder/{find-fresh-emoji-tag.d.ts → find-fresh-emoji-tags.d.ts} +1 -1
- package/esm/src/cli/cli-commands/coder.d.ts +1 -1
- package/esm/src/execution/createPipelineExecutor/30-executeFormatSubvalues.d.ts +1 -1
- package/esm/src/llm-providers/anthropic-claude/anthropic-claude-models.d.ts +1 -1
- package/esm/src/llm-providers/deepseek/deepseek-models.d.ts +1 -1
- package/esm/src/llm-providers/google/google-models.d.ts +1 -1
- package/esm/src/llm-providers/openai/openai-models.d.ts +1 -1
- package/esm/src/scrapers/_boilerplate/BoilerplateScraper.d.ts +1 -2
- package/esm/src/scrapers/document/DocumentScraper.d.ts +1 -2
- package/esm/src/scrapers/document-legacy/LegacyDocumentScraper.d.ts +1 -2
- package/esm/src/scripting/javascript/postprocessing-functions.d.ts +1 -1
- package/esm/src/utils/parameters/mapAvailableToExpectedParameters.d.ts +1 -2
- package/esm/src/version.d.ts +1 -1
- package/package.json +2 -2
- package/umd/index.umd.js +501 -502
- package/umd/index.umd.js.map +1 -1
- package/umd/src/cli/cli-commands/coder/{find-fresh-emoji-tag.d.ts → find-fresh-emoji-tags.d.ts} +1 -1
- package/umd/src/cli/cli-commands/coder.d.ts +1 -1
- package/umd/src/execution/createPipelineExecutor/30-executeFormatSubvalues.d.ts +1 -1
- package/umd/src/llm-providers/anthropic-claude/anthropic-claude-models.d.ts +1 -1
- package/umd/src/llm-providers/deepseek/deepseek-models.d.ts +1 -1
- package/umd/src/llm-providers/google/google-models.d.ts +1 -1
- package/umd/src/llm-providers/openai/openai-models.d.ts +1 -1
- package/umd/src/scrapers/_boilerplate/BoilerplateScraper.d.ts +1 -2
- package/umd/src/scrapers/document/DocumentScraper.d.ts +1 -2
- package/umd/src/scrapers/document-legacy/LegacyDocumentScraper.d.ts +1 -2
- package/umd/src/scripting/javascript/postprocessing-functions.d.ts +1 -1
- package/umd/src/utils/parameters/mapAvailableToExpectedParameters.d.ts +1 -2
- package/umd/src/version.d.ts +1 -1
package/esm/index.es.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { spaceTrim as spaceTrim$1 } from 'spacetrim';
|
|
2
2
|
import { randomBytes } from 'crypto';
|
|
3
3
|
import Bottleneck from 'bottleneck';
|
|
4
4
|
import colors from 'colors';
|
|
@@ -21,7 +21,7 @@ const BOOK_LANGUAGE_VERSION = '2.0.0';
|
|
|
21
21
|
* @generated
|
|
22
22
|
* @see https://github.com/webgptorg/promptbook
|
|
23
23
|
*/
|
|
24
|
-
const PROMPTBOOK_ENGINE_VERSION = '0.112.0-
|
|
24
|
+
const PROMPTBOOK_ENGINE_VERSION = '0.112.0-16';
|
|
25
25
|
/**
|
|
26
26
|
* TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
|
|
27
27
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
@@ -1201,7 +1201,7 @@ const API_REQUEST_TIMEOUT = parseInt(process.env.API_REQUEST_TIMEOUT || '90000')
|
|
|
1201
1201
|
function getErrorReportUrl(error) {
|
|
1202
1202
|
const report = {
|
|
1203
1203
|
title: `🐜 Error report from ${NAME}`,
|
|
1204
|
-
body: spaceTrim$
|
|
1204
|
+
body: spaceTrim$1((block) => `
|
|
1205
1205
|
|
|
1206
1206
|
|
|
1207
1207
|
\`${error.name || 'Error'}\` has occurred in the [${NAME}], please look into it @${ADMIN_GITHUB_NAME}.
|
|
@@ -1359,7 +1359,7 @@ function checkSerializableAsJson(options) {
|
|
|
1359
1359
|
}
|
|
1360
1360
|
else if (typeof value === 'object') {
|
|
1361
1361
|
if (value instanceof Date) {
|
|
1362
|
-
throw new UnexpectedError(spaceTrim$
|
|
1362
|
+
throw new UnexpectedError(spaceTrim$1((block) => `
|
|
1363
1363
|
\`${name}\` is Date
|
|
1364
1364
|
|
|
1365
1365
|
Use \`string_date_iso8601\` instead
|
|
@@ -1378,7 +1378,7 @@ function checkSerializableAsJson(options) {
|
|
|
1378
1378
|
throw new UnexpectedError(`${name} is RegExp`);
|
|
1379
1379
|
}
|
|
1380
1380
|
else if (value instanceof Error) {
|
|
1381
|
-
throw new UnexpectedError(spaceTrim$
|
|
1381
|
+
throw new UnexpectedError(spaceTrim$1((block) => `
|
|
1382
1382
|
\`${name}\` is unserialized Error
|
|
1383
1383
|
|
|
1384
1384
|
Use function \`serializeError\`
|
|
@@ -1401,7 +1401,7 @@ function checkSerializableAsJson(options) {
|
|
|
1401
1401
|
}
|
|
1402
1402
|
catch (error) {
|
|
1403
1403
|
assertsError(error);
|
|
1404
|
-
throw new UnexpectedError(spaceTrim$
|
|
1404
|
+
throw new UnexpectedError(spaceTrim$1((block) => `
|
|
1405
1405
|
\`${name}\` is not serializable
|
|
1406
1406
|
|
|
1407
1407
|
${block(error.stack || error.message)}
|
|
@@ -1433,7 +1433,7 @@ function checkSerializableAsJson(options) {
|
|
|
1433
1433
|
}
|
|
1434
1434
|
}
|
|
1435
1435
|
else {
|
|
1436
|
-
throw new UnexpectedError(spaceTrim$
|
|
1436
|
+
throw new UnexpectedError(spaceTrim$1((block) => `
|
|
1437
1437
|
\`${name}\` is unknown type
|
|
1438
1438
|
|
|
1439
1439
|
Additional message for \`${name}\`:
|
|
@@ -2030,7 +2030,7 @@ function pricing(value) {
|
|
|
2030
2030
|
/**
|
|
2031
2031
|
* List of available OpenAI models with pricing
|
|
2032
2032
|
*
|
|
2033
|
-
* Note: Synced with official API docs at
|
|
2033
|
+
* Note: Synced with official API docs at 2026-03-22
|
|
2034
2034
|
*
|
|
2035
2035
|
* @see https://platform.openai.com/docs/models/
|
|
2036
2036
|
* @see https://openai.com/api/pricing/
|
|
@@ -2152,8 +2152,8 @@ const OPENAI_MODELS = exportJson({
|
|
|
2152
2152
|
modelName: 'gpt-4.1',
|
|
2153
2153
|
modelDescription: 'Smartest non-reasoning model with 128K context window. Enhanced version of GPT-4 with improved instruction following, better factual accuracy, and reduced hallucinations. Features advanced function calling capabilities and superior performance on coding tasks. Ideal for applications requiring high intelligence without reasoning overhead.',
|
|
2154
2154
|
pricing: {
|
|
2155
|
-
prompt: pricing(`$
|
|
2156
|
-
output: pricing(`$
|
|
2155
|
+
prompt: pricing(`$2.00 / 1M tokens`),
|
|
2156
|
+
output: pricing(`$8.00 / 1M tokens`),
|
|
2157
2157
|
},
|
|
2158
2158
|
},
|
|
2159
2159
|
/**/
|
|
@@ -2164,8 +2164,8 @@ const OPENAI_MODELS = exportJson({
|
|
|
2164
2164
|
modelName: 'gpt-4.1-mini',
|
|
2165
2165
|
modelDescription: 'Smaller, faster version of GPT-4.1 with 128K context window. Balances intelligence and efficiency with 3x faster inference than base GPT-4.1. Maintains strong capabilities across text generation, reasoning, and coding while offering better cost-performance ratio for most applications.',
|
|
2166
2166
|
pricing: {
|
|
2167
|
-
prompt: pricing(`$0.
|
|
2168
|
-
output: pricing(`$
|
|
2167
|
+
prompt: pricing(`$0.40 / 1M tokens`),
|
|
2168
|
+
output: pricing(`$1.60 / 1M tokens`),
|
|
2169
2169
|
},
|
|
2170
2170
|
},
|
|
2171
2171
|
/**/
|
|
@@ -2176,8 +2176,8 @@ const OPENAI_MODELS = exportJson({
|
|
|
2176
2176
|
modelName: 'gpt-4.1-nano',
|
|
2177
2177
|
modelDescription: 'Fastest, most cost-efficient version of GPT-4.1 with 128K context window. Optimized for high-throughput applications requiring good quality at minimal cost. Features 5x faster inference than GPT-4.1 while maintaining adequate performance for most general-purpose tasks.',
|
|
2178
2178
|
pricing: {
|
|
2179
|
-
prompt: pricing(`$0.
|
|
2180
|
-
output: pricing(`$0.
|
|
2179
|
+
prompt: pricing(`$0.10 / 1M tokens`),
|
|
2180
|
+
output: pricing(`$0.40 / 1M tokens`),
|
|
2181
2181
|
},
|
|
2182
2182
|
},
|
|
2183
2183
|
/**/
|
|
@@ -2188,8 +2188,8 @@ const OPENAI_MODELS = exportJson({
|
|
|
2188
2188
|
modelName: 'o3',
|
|
2189
2189
|
modelDescription: 'Advanced reasoning model with 128K context window specializing in complex logical, mathematical, and analytical tasks. Successor to o1 with enhanced step-by-step problem-solving capabilities and superior performance on STEM-focused problems. Ideal for professional applications requiring deep analytical thinking and precise reasoning.',
|
|
2190
2190
|
pricing: {
|
|
2191
|
-
prompt: pricing(`$
|
|
2192
|
-
output: pricing(`$
|
|
2191
|
+
prompt: pricing(`$2.00 / 1M tokens`),
|
|
2192
|
+
output: pricing(`$8.00 / 1M tokens`),
|
|
2193
2193
|
},
|
|
2194
2194
|
},
|
|
2195
2195
|
/**/
|
|
@@ -2200,8 +2200,8 @@ const OPENAI_MODELS = exportJson({
|
|
|
2200
2200
|
modelName: 'o3-pro',
|
|
2201
2201
|
modelDescription: 'Enhanced version of o3 with more compute allocated for better responses on the most challenging problems. Features extended reasoning time and improved accuracy on complex analytical tasks. Designed for applications where maximum reasoning quality is more important than response speed.',
|
|
2202
2202
|
pricing: {
|
|
2203
|
-
prompt: pricing(`$
|
|
2204
|
-
output: pricing(`$
|
|
2203
|
+
prompt: pricing(`$20.00 / 1M tokens`),
|
|
2204
|
+
output: pricing(`$80.00 / 1M tokens`),
|
|
2205
2205
|
},
|
|
2206
2206
|
},
|
|
2207
2207
|
/**/
|
|
@@ -2212,8 +2212,8 @@ const OPENAI_MODELS = exportJson({
|
|
|
2212
2212
|
modelName: 'o4-mini',
|
|
2213
2213
|
modelDescription: 'Fast, cost-efficient reasoning model with 128K context window. Successor to o1-mini with improved analytical capabilities while maintaining speed advantages. Features enhanced mathematical reasoning and logical problem-solving at significantly lower cost than full reasoning models.',
|
|
2214
2214
|
pricing: {
|
|
2215
|
-
prompt: pricing(`$
|
|
2216
|
-
output: pricing(`$
|
|
2215
|
+
prompt: pricing(`$1.10 / 1M tokens`),
|
|
2216
|
+
output: pricing(`$4.40 / 1M tokens`),
|
|
2217
2217
|
},
|
|
2218
2218
|
},
|
|
2219
2219
|
/**/
|
|
@@ -2571,8 +2571,8 @@ const OPENAI_MODELS = exportJson({
|
|
|
2571
2571
|
modelName: 'gpt-4o-2024-05-13',
|
|
2572
2572
|
modelDescription: 'May 2024 version of GPT-4o with 128K context window. Features enhanced multimodal capabilities including superior image understanding (up to 20MP), audio processing, and improved reasoning. Optimized for 2x lower latency than GPT-4 Turbo while maintaining high performance. Includes knowledge up to October 2023. Ideal for production applications requiring reliable multimodal capabilities.',
|
|
2573
2573
|
pricing: {
|
|
2574
|
-
prompt: pricing(`$
|
|
2575
|
-
output: pricing(`$
|
|
2574
|
+
prompt: pricing(`$2.50 / 1M tokens`),
|
|
2575
|
+
output: pricing(`$10.00 / 1M tokens`),
|
|
2576
2576
|
},
|
|
2577
2577
|
},
|
|
2578
2578
|
/**/
|
|
@@ -2583,8 +2583,8 @@ const OPENAI_MODELS = exportJson({
|
|
|
2583
2583
|
modelName: 'gpt-4o',
|
|
2584
2584
|
modelDescription: "OpenAI's most advanced general-purpose multimodal model with 128K context window. Optimized for balanced performance, speed, and cost with 2x faster responses than GPT-4 Turbo. Features excellent vision processing, audio understanding, reasoning, and text generation quality. Represents optimal balance of capability and efficiency for most advanced applications.",
|
|
2585
2585
|
pricing: {
|
|
2586
|
-
prompt: pricing(`$
|
|
2587
|
-
output: pricing(`$
|
|
2586
|
+
prompt: pricing(`$2.50 / 1M tokens`),
|
|
2587
|
+
output: pricing(`$10.00 / 1M tokens`),
|
|
2588
2588
|
},
|
|
2589
2589
|
},
|
|
2590
2590
|
/**/
|
|
@@ -2655,8 +2655,8 @@ const OPENAI_MODELS = exportJson({
|
|
|
2655
2655
|
modelName: 'o3-mini',
|
|
2656
2656
|
modelDescription: 'Cost-effective reasoning model with 128K context window optimized for academic and scientific problem-solving. Features efficient performance on STEM tasks with specialized capabilities in mathematics, physics, chemistry, and computer science. Offers 80% of O1 performance on technical domains at significantly lower cost. Ideal for educational applications and research support.',
|
|
2657
2657
|
pricing: {
|
|
2658
|
-
prompt: pricing(`$
|
|
2659
|
-
output: pricing(`$
|
|
2658
|
+
prompt: pricing(`$1.10 / 1M tokens`),
|
|
2659
|
+
output: pricing(`$4.40 / 1M tokens`),
|
|
2660
2660
|
},
|
|
2661
2661
|
},
|
|
2662
2662
|
/**/
|
|
@@ -2757,116 +2757,130 @@ resultContent, rawResponse, duration = ZERO_VALUE) {
|
|
|
2757
2757
|
*/
|
|
2758
2758
|
|
|
2759
2759
|
/**
|
|
2760
|
-
*
|
|
2761
|
-
*
|
|
2762
|
-
* @private internal runtime wiring for commitment tools
|
|
2763
|
-
*/
|
|
2764
|
-
const TOOL_RUNTIME_CONTEXT_PARAMETER = 'promptbookToolRuntimeContext';
|
|
2765
|
-
/**
|
|
2766
|
-
* Hidden argument key used to pass runtime context into individual tool calls.
|
|
2760
|
+
* This error indicates problems parsing the format value
|
|
2767
2761
|
*
|
|
2768
|
-
*
|
|
2769
|
-
|
|
2770
|
-
const TOOL_RUNTIME_CONTEXT_ARGUMENT = '__promptbookToolRuntimeContext';
|
|
2771
|
-
/**
|
|
2772
|
-
* Prompt parameter key used to pass a hidden tool-progress listener token into script execution.
|
|
2762
|
+
* For example, when the format value is not a valid JSON or CSV
|
|
2763
|
+
* This is not thrown directly but in extended classes
|
|
2773
2764
|
*
|
|
2774
|
-
* @
|
|
2765
|
+
* @public exported from `@promptbook/core`
|
|
2775
2766
|
*/
|
|
2776
|
-
|
|
2767
|
+
class AbstractFormatError extends Error {
|
|
2768
|
+
// Note: To allow instanceof do not put here error `name`
|
|
2769
|
+
// public readonly name = 'AbstractFormatError';
|
|
2770
|
+
constructor(message) {
|
|
2771
|
+
super(message);
|
|
2772
|
+
Object.setPrototypeOf(this, AbstractFormatError.prototype);
|
|
2773
|
+
}
|
|
2774
|
+
}
|
|
2775
|
+
|
|
2777
2776
|
/**
|
|
2778
|
-
*
|
|
2777
|
+
* This error indicates problem with parsing of CSV
|
|
2779
2778
|
*
|
|
2780
|
-
* @
|
|
2779
|
+
* @public exported from `@promptbook/core`
|
|
2781
2780
|
*/
|
|
2782
|
-
|
|
2781
|
+
class CsvFormatError extends AbstractFormatError {
|
|
2782
|
+
constructor(message) {
|
|
2783
|
+
super(message);
|
|
2784
|
+
this.name = 'CsvFormatError';
|
|
2785
|
+
Object.setPrototypeOf(this, CsvFormatError.prototype);
|
|
2786
|
+
}
|
|
2787
|
+
}
|
|
2788
|
+
|
|
2783
2789
|
/**
|
|
2784
|
-
*
|
|
2790
|
+
* AuthenticationError is thrown from login function which is dependency of remote server
|
|
2785
2791
|
*
|
|
2786
|
-
* @
|
|
2792
|
+
* @public exported from `@promptbook/core`
|
|
2787
2793
|
*/
|
|
2788
|
-
|
|
2794
|
+
class AuthenticationError extends Error {
|
|
2795
|
+
constructor(message) {
|
|
2796
|
+
super(message);
|
|
2797
|
+
this.name = 'AuthenticationError';
|
|
2798
|
+
Object.setPrototypeOf(this, AuthenticationError.prototype);
|
|
2799
|
+
}
|
|
2800
|
+
}
|
|
2801
|
+
|
|
2789
2802
|
/**
|
|
2790
|
-
*
|
|
2803
|
+
* This error indicates that the pipeline collection cannot be properly loaded
|
|
2791
2804
|
*
|
|
2792
|
-
* @
|
|
2805
|
+
* @public exported from `@promptbook/core`
|
|
2793
2806
|
*/
|
|
2794
|
-
|
|
2807
|
+
class CollectionError extends Error {
|
|
2808
|
+
constructor(message) {
|
|
2809
|
+
super(message);
|
|
2810
|
+
this.name = 'CollectionError';
|
|
2811
|
+
Object.setPrototypeOf(this, CollectionError.prototype);
|
|
2812
|
+
}
|
|
2813
|
+
}
|
|
2814
|
+
|
|
2795
2815
|
/**
|
|
2796
|
-
*
|
|
2797
|
-
*
|
|
2798
|
-
* The returned token is passed into script execution as a hidden argument so tool implementations
|
|
2799
|
-
* can stream progress without exposing extra parameters to the model.
|
|
2816
|
+
* Signals that the requested operation could not be completed because the target already exists.
|
|
2800
2817
|
*
|
|
2801
|
-
* @
|
|
2802
|
-
* @returns Hidden token used to route progress updates.
|
|
2803
|
-
* @private internal runtime wiring for commitment tools
|
|
2818
|
+
* @public exported from `@promptbook/core`
|
|
2804
2819
|
*/
|
|
2805
|
-
|
|
2806
|
-
|
|
2807
|
-
|
|
2808
|
-
|
|
2809
|
-
|
|
2820
|
+
class ConflictError extends Error {
|
|
2821
|
+
constructor(message) {
|
|
2822
|
+
super(message);
|
|
2823
|
+
this.name = 'ConflictError';
|
|
2824
|
+
Object.setPrototypeOf(this, ConflictError.prototype);
|
|
2825
|
+
}
|
|
2810
2826
|
}
|
|
2827
|
+
|
|
2811
2828
|
/**
|
|
2812
|
-
*
|
|
2829
|
+
* This error indicates error from the database
|
|
2813
2830
|
*
|
|
2814
|
-
* @
|
|
2815
|
-
* @private internal runtime wiring for commitment tools
|
|
2831
|
+
* @public exported from `@promptbook/core`
|
|
2816
2832
|
*/
|
|
2817
|
-
|
|
2818
|
-
|
|
2833
|
+
class DatabaseError extends Error {
|
|
2834
|
+
constructor(message) {
|
|
2835
|
+
super(message);
|
|
2836
|
+
this.name = 'DatabaseError';
|
|
2837
|
+
Object.setPrototypeOf(this, DatabaseError.prototype);
|
|
2838
|
+
}
|
|
2819
2839
|
}
|
|
2820
2840
|
/**
|
|
2821
|
-
*
|
|
2841
|
+
* TODO: [🐱🚀] Explain that NotFoundError ([🐱🚀] and other specific errors) has priority over DatabaseError in some contexts
|
|
2822
2842
|
*/
|
|
2823
2843
|
|
|
2824
2844
|
/**
|
|
2825
|
-
*
|
|
2845
|
+
* This error type indicates that you try to use a feature that is not available in the current environment
|
|
2826
2846
|
*
|
|
2827
|
-
* @
|
|
2847
|
+
* @public exported from `@promptbook/core`
|
|
2828
2848
|
*/
|
|
2829
|
-
|
|
2849
|
+
class EnvironmentMismatchError extends Error {
|
|
2850
|
+
constructor(message) {
|
|
2851
|
+
super(message);
|
|
2852
|
+
this.name = 'EnvironmentMismatchError';
|
|
2853
|
+
Object.setPrototypeOf(this, EnvironmentMismatchError.prototype);
|
|
2854
|
+
}
|
|
2855
|
+
}
|
|
2856
|
+
|
|
2830
2857
|
/**
|
|
2831
|
-
*
|
|
2858
|
+
* This error occurs when some expectation is not met in the execution of the pipeline
|
|
2832
2859
|
*
|
|
2833
|
-
* @
|
|
2860
|
+
* @public exported from `@promptbook/core`
|
|
2861
|
+
* Note: Do not throw this error, its reserved for `checkExpectations` and `createPipelineExecutor` and public ONLY to be serializable through remote server
|
|
2862
|
+
* Note: Always thrown in `checkExpectations` and catched in `createPipelineExecutor` and rethrown as `PipelineExecutionError`
|
|
2863
|
+
* Note: This is a kindof subtype of PipelineExecutionError
|
|
2834
2864
|
*/
|
|
2835
|
-
|
|
2836
|
-
|
|
2837
|
-
|
|
2838
|
-
|
|
2839
|
-
|
|
2840
|
-
const parsedValue = JSON.parse(rawValue);
|
|
2841
|
-
if (!parsedValue ||
|
|
2842
|
-
typeof parsedValue !== 'object' ||
|
|
2843
|
-
parsedValue[TOOL_EXECUTION_ENVELOPE_MARKER] !== true ||
|
|
2844
|
-
typeof parsedValue.assistantMessage !== 'string') {
|
|
2845
|
-
return null;
|
|
2846
|
-
}
|
|
2847
|
-
return {
|
|
2848
|
-
assistantMessage: parsedValue.assistantMessage,
|
|
2849
|
-
toolResult: parsedValue.toolResult,
|
|
2850
|
-
};
|
|
2851
|
-
}
|
|
2852
|
-
catch (_a) {
|
|
2853
|
-
return null;
|
|
2865
|
+
class ExpectError extends Error {
|
|
2866
|
+
constructor(message) {
|
|
2867
|
+
super(message);
|
|
2868
|
+
this.name = 'ExpectError';
|
|
2869
|
+
Object.setPrototypeOf(this, ExpectError.prototype);
|
|
2854
2870
|
}
|
|
2855
2871
|
}
|
|
2856
|
-
/**
|
|
2857
|
-
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
2858
|
-
*/
|
|
2859
2872
|
|
|
2860
2873
|
/**
|
|
2861
|
-
*
|
|
2862
|
-
*
|
|
2863
|
-
* Note: `$` is used to indicate that this function is not a pure function - it is not deterministic because it depends on the current time
|
|
2874
|
+
* This error indicates that the promptbook can not retrieve knowledge from external sources
|
|
2864
2875
|
*
|
|
2865
|
-
* @
|
|
2866
|
-
* @public exported from `@promptbook/utils`
|
|
2876
|
+
* @public exported from `@promptbook/core`
|
|
2867
2877
|
*/
|
|
2868
|
-
|
|
2869
|
-
|
|
2878
|
+
class KnowledgeScrapeError extends Error {
|
|
2879
|
+
constructor(message) {
|
|
2880
|
+
super(message);
|
|
2881
|
+
this.name = 'KnowledgeScrapeError';
|
|
2882
|
+
Object.setPrototypeOf(this, KnowledgeScrapeError.prototype);
|
|
2883
|
+
}
|
|
2870
2884
|
}
|
|
2871
2885
|
|
|
2872
2886
|
/**
|
|
@@ -2883,332 +2897,53 @@ class LimitReachedError extends Error {
|
|
|
2883
2897
|
}
|
|
2884
2898
|
|
|
2885
2899
|
/**
|
|
2886
|
-
*
|
|
2900
|
+
* This error type indicates that some tools are missing for pipeline execution or preparation
|
|
2887
2901
|
*
|
|
2888
|
-
* @public exported from `@promptbook/
|
|
2902
|
+
* @public exported from `@promptbook/core`
|
|
2889
2903
|
*/
|
|
2890
|
-
|
|
2891
|
-
|
|
2892
|
-
|
|
2893
|
-
|
|
2894
|
-
|
|
2895
|
-
|
|
2896
|
-
|
|
2897
|
-
|
|
2898
|
-
|
|
2899
|
-
|
|
2900
|
-
else if (value === -Infinity) {
|
|
2901
|
-
return VALUE_STRINGS.negativeInfinity;
|
|
2902
|
-
}
|
|
2903
|
-
for (let exponent = 0; exponent < 15; exponent++) {
|
|
2904
|
-
const factor = 10 ** exponent;
|
|
2905
|
-
const valueRounded = Math.round(value * factor) / factor;
|
|
2906
|
-
if (Math.abs(value - valueRounded) / value < SMALL_NUMBER) {
|
|
2907
|
-
return valueRounded.toFixed(exponent);
|
|
2908
|
-
}
|
|
2904
|
+
class MissingToolsError extends Error {
|
|
2905
|
+
constructor(message) {
|
|
2906
|
+
super(spaceTrim$1((block) => `
|
|
2907
|
+
${block(message)}
|
|
2908
|
+
|
|
2909
|
+
Note: You have probably forgot to provide some tools for pipeline execution or preparation
|
|
2910
|
+
|
|
2911
|
+
`));
|
|
2912
|
+
this.name = 'MissingToolsError';
|
|
2913
|
+
Object.setPrototypeOf(this, MissingToolsError.prototype);
|
|
2909
2914
|
}
|
|
2910
|
-
return value.toString();
|
|
2911
2915
|
}
|
|
2912
2916
|
|
|
2913
2917
|
/**
|
|
2914
|
-
*
|
|
2915
|
-
* This is useful and used in the `templateParameters` function
|
|
2918
|
+
* This error indicates that promptbook operation is not allowed
|
|
2916
2919
|
*
|
|
2917
|
-
*
|
|
2918
|
-
|
|
2919
|
-
|
|
2920
|
+
* @public exported from `@promptbook/core`
|
|
2921
|
+
*/
|
|
2922
|
+
class NotAllowed extends Error {
|
|
2923
|
+
constructor(message) {
|
|
2924
|
+
super(message);
|
|
2925
|
+
this.name = 'NotAllowed';
|
|
2926
|
+
Object.setPrototypeOf(this, NotAllowed.prototype);
|
|
2927
|
+
}
|
|
2928
|
+
}
|
|
2929
|
+
|
|
2930
|
+
/**
|
|
2931
|
+
* This error indicates that promptbook not found in the collection
|
|
2920
2932
|
*
|
|
2921
|
-
*
|
|
2922
|
-
|
|
2923
|
-
|
|
2933
|
+
* @public exported from `@promptbook/core`
|
|
2934
|
+
*/
|
|
2935
|
+
class NotFoundError extends Error {
|
|
2936
|
+
constructor(message) {
|
|
2937
|
+
super(message);
|
|
2938
|
+
this.name = 'NotFoundError';
|
|
2939
|
+
Object.setPrototypeOf(this, NotFoundError.prototype);
|
|
2940
|
+
}
|
|
2941
|
+
}
|
|
2942
|
+
|
|
2943
|
+
/**
|
|
2944
|
+
* This error type indicates that some part of the code is not implemented yet
|
|
2924
2945
|
*
|
|
2925
|
-
* @public exported from `@promptbook/
|
|
2926
|
-
*/
|
|
2927
|
-
function valueToString(value) {
|
|
2928
|
-
try {
|
|
2929
|
-
if (value === '') {
|
|
2930
|
-
return VALUE_STRINGS.empty;
|
|
2931
|
-
}
|
|
2932
|
-
else if (value === null) {
|
|
2933
|
-
return VALUE_STRINGS.null;
|
|
2934
|
-
}
|
|
2935
|
-
else if (value === undefined) {
|
|
2936
|
-
return VALUE_STRINGS.undefined;
|
|
2937
|
-
}
|
|
2938
|
-
else if (typeof value === 'string') {
|
|
2939
|
-
return value;
|
|
2940
|
-
}
|
|
2941
|
-
else if (typeof value === 'number') {
|
|
2942
|
-
return numberToString(value);
|
|
2943
|
-
}
|
|
2944
|
-
else if (value instanceof Date) {
|
|
2945
|
-
return value.toISOString();
|
|
2946
|
-
}
|
|
2947
|
-
else {
|
|
2948
|
-
try {
|
|
2949
|
-
return JSON.stringify(value);
|
|
2950
|
-
}
|
|
2951
|
-
catch (error) {
|
|
2952
|
-
if (error instanceof TypeError && error.message.includes('circular structure')) {
|
|
2953
|
-
return VALUE_STRINGS.circular;
|
|
2954
|
-
}
|
|
2955
|
-
throw error;
|
|
2956
|
-
}
|
|
2957
|
-
}
|
|
2958
|
-
}
|
|
2959
|
-
catch (error) {
|
|
2960
|
-
assertsError(error);
|
|
2961
|
-
console.error(error);
|
|
2962
|
-
return VALUE_STRINGS.unserializable;
|
|
2963
|
-
}
|
|
2964
|
-
}
|
|
2965
|
-
|
|
2966
|
-
/**
|
|
2967
|
-
* Replaces parameters in template with values from parameters object
|
|
2968
|
-
*
|
|
2969
|
-
* Note: This function is not places strings into string,
|
|
2970
|
-
* It's more complex and can handle this operation specifically for LLM models
|
|
2971
|
-
*
|
|
2972
|
-
* @param template the template with parameters in {curly} braces
|
|
2973
|
-
* @param parameters the object with parameters
|
|
2974
|
-
* @returns the template with replaced parameters
|
|
2975
|
-
* @throws {PipelineExecutionError} if parameter is not defined, not closed, or not opened
|
|
2976
|
-
* @public exported from `@promptbook/utils`
|
|
2977
|
-
*/
|
|
2978
|
-
function templateParameters(template, parameters) {
|
|
2979
|
-
for (const [parameterName, parameterValue] of Object.entries(parameters)) {
|
|
2980
|
-
if (parameterValue === RESERVED_PARAMETER_MISSING_VALUE) {
|
|
2981
|
-
throw new UnexpectedError(`Parameter \`{${parameterName}}\` has missing value`);
|
|
2982
|
-
}
|
|
2983
|
-
else if (parameterValue === RESERVED_PARAMETER_RESTRICTED) {
|
|
2984
|
-
// TODO: [🍵]
|
|
2985
|
-
throw new UnexpectedError(`Parameter \`{${parameterName}}\` is restricted to use`);
|
|
2986
|
-
}
|
|
2987
|
-
}
|
|
2988
|
-
let replacedTemplates = template;
|
|
2989
|
-
let match;
|
|
2990
|
-
let loopLimit = LOOP_LIMIT;
|
|
2991
|
-
while ((match = /^(?<precol>.*){(?<parameterName>\w+)}(.*)/m /* <- Not global */
|
|
2992
|
-
.exec(replacedTemplates))) {
|
|
2993
|
-
if (loopLimit-- < 0) {
|
|
2994
|
-
throw new LimitReachedError('Loop limit reached during parameters replacement in `templateParameters`');
|
|
2995
|
-
}
|
|
2996
|
-
const precol = match.groups.precol;
|
|
2997
|
-
const parameterName = match.groups.parameterName;
|
|
2998
|
-
if (parameterName === '') {
|
|
2999
|
-
// Note: Skip empty placeholders. It's used to avoid confusion with JSON-like strings
|
|
3000
|
-
continue;
|
|
3001
|
-
}
|
|
3002
|
-
if (parameterName.indexOf('{') !== -1 || parameterName.indexOf('}') !== -1) {
|
|
3003
|
-
throw new PipelineExecutionError('Parameter is already opened or not closed');
|
|
3004
|
-
}
|
|
3005
|
-
if (parameters[parameterName] === undefined) {
|
|
3006
|
-
throw new PipelineExecutionError(`Parameter \`{${parameterName}}\` is not defined`);
|
|
3007
|
-
}
|
|
3008
|
-
let parameterValue = parameters[parameterName];
|
|
3009
|
-
if (parameterValue === undefined) {
|
|
3010
|
-
throw new PipelineExecutionError(`Parameter \`{${parameterName}}\` is not defined`);
|
|
3011
|
-
}
|
|
3012
|
-
parameterValue = valueToString(parameterValue);
|
|
3013
|
-
// Escape curly braces in parameter values to prevent prompt-injection
|
|
3014
|
-
parameterValue = parameterValue.replace(/[{}]/g, '\\$&');
|
|
3015
|
-
if (parameterValue.includes('\n') && /^\s*\W{0,3}\s*$/.test(precol)) {
|
|
3016
|
-
parameterValue = parameterValue
|
|
3017
|
-
.split(/\r?\n/)
|
|
3018
|
-
.map((line, index) => (index === 0 ? line : `${precol}${line}`))
|
|
3019
|
-
.join('\n');
|
|
3020
|
-
}
|
|
3021
|
-
replacedTemplates =
|
|
3022
|
-
replacedTemplates.substring(0, match.index + precol.length) +
|
|
3023
|
-
parameterValue +
|
|
3024
|
-
replacedTemplates.substring(match.index + precol.length + parameterName.length + 2);
|
|
3025
|
-
}
|
|
3026
|
-
// [💫] Check if there are parameters that are not closed properly
|
|
3027
|
-
if (/{\w+$/.test(replacedTemplates)) {
|
|
3028
|
-
throw new PipelineExecutionError('Parameter is not closed');
|
|
3029
|
-
}
|
|
3030
|
-
// [💫] Check if there are parameters that are not opened properly
|
|
3031
|
-
if (/^\w+}/.test(replacedTemplates)) {
|
|
3032
|
-
throw new PipelineExecutionError('Parameter is not opened');
|
|
3033
|
-
}
|
|
3034
|
-
return replacedTemplates;
|
|
3035
|
-
}
|
|
3036
|
-
|
|
3037
|
-
/**
|
|
3038
|
-
* This error indicates problems parsing the format value
|
|
3039
|
-
*
|
|
3040
|
-
* For example, when the format value is not a valid JSON or CSV
|
|
3041
|
-
* This is not thrown directly but in extended classes
|
|
3042
|
-
*
|
|
3043
|
-
* @public exported from `@promptbook/core`
|
|
3044
|
-
*/
|
|
3045
|
-
class AbstractFormatError extends Error {
|
|
3046
|
-
// Note: To allow instanceof do not put here error `name`
|
|
3047
|
-
// public readonly name = 'AbstractFormatError';
|
|
3048
|
-
constructor(message) {
|
|
3049
|
-
super(message);
|
|
3050
|
-
Object.setPrototypeOf(this, AbstractFormatError.prototype);
|
|
3051
|
-
}
|
|
3052
|
-
}
|
|
3053
|
-
|
|
3054
|
-
/**
|
|
3055
|
-
* This error indicates problem with parsing of CSV
|
|
3056
|
-
*
|
|
3057
|
-
* @public exported from `@promptbook/core`
|
|
3058
|
-
*/
|
|
3059
|
-
class CsvFormatError extends AbstractFormatError {
|
|
3060
|
-
constructor(message) {
|
|
3061
|
-
super(message);
|
|
3062
|
-
this.name = 'CsvFormatError';
|
|
3063
|
-
Object.setPrototypeOf(this, CsvFormatError.prototype);
|
|
3064
|
-
}
|
|
3065
|
-
}
|
|
3066
|
-
|
|
3067
|
-
/**
|
|
3068
|
-
* AuthenticationError is thrown from login function which is dependency of remote server
|
|
3069
|
-
*
|
|
3070
|
-
* @public exported from `@promptbook/core`
|
|
3071
|
-
*/
|
|
3072
|
-
class AuthenticationError extends Error {
|
|
3073
|
-
constructor(message) {
|
|
3074
|
-
super(message);
|
|
3075
|
-
this.name = 'AuthenticationError';
|
|
3076
|
-
Object.setPrototypeOf(this, AuthenticationError.prototype);
|
|
3077
|
-
}
|
|
3078
|
-
}
|
|
3079
|
-
|
|
3080
|
-
/**
|
|
3081
|
-
* This error indicates that the pipeline collection cannot be properly loaded
|
|
3082
|
-
*
|
|
3083
|
-
* @public exported from `@promptbook/core`
|
|
3084
|
-
*/
|
|
3085
|
-
class CollectionError extends Error {
|
|
3086
|
-
constructor(message) {
|
|
3087
|
-
super(message);
|
|
3088
|
-
this.name = 'CollectionError';
|
|
3089
|
-
Object.setPrototypeOf(this, CollectionError.prototype);
|
|
3090
|
-
}
|
|
3091
|
-
}
|
|
3092
|
-
|
|
3093
|
-
/**
|
|
3094
|
-
* Signals that the requested operation could not be completed because the target already exists.
|
|
3095
|
-
*
|
|
3096
|
-
* @public exported from `@promptbook/core`
|
|
3097
|
-
*/
|
|
3098
|
-
class ConflictError extends Error {
|
|
3099
|
-
constructor(message) {
|
|
3100
|
-
super(message);
|
|
3101
|
-
this.name = 'ConflictError';
|
|
3102
|
-
Object.setPrototypeOf(this, ConflictError.prototype);
|
|
3103
|
-
}
|
|
3104
|
-
}
|
|
3105
|
-
|
|
3106
|
-
/**
|
|
3107
|
-
* This error indicates error from the database
|
|
3108
|
-
*
|
|
3109
|
-
* @public exported from `@promptbook/core`
|
|
3110
|
-
*/
|
|
3111
|
-
class DatabaseError extends Error {
|
|
3112
|
-
constructor(message) {
|
|
3113
|
-
super(message);
|
|
3114
|
-
this.name = 'DatabaseError';
|
|
3115
|
-
Object.setPrototypeOf(this, DatabaseError.prototype);
|
|
3116
|
-
}
|
|
3117
|
-
}
|
|
3118
|
-
/**
|
|
3119
|
-
* TODO: [🐱🚀] Explain that NotFoundError ([🐱🚀] and other specific errors) has priority over DatabaseError in some contexts
|
|
3120
|
-
*/
|
|
3121
|
-
|
|
3122
|
-
/**
|
|
3123
|
-
* This error type indicates that you try to use a feature that is not available in the current environment
|
|
3124
|
-
*
|
|
3125
|
-
* @public exported from `@promptbook/core`
|
|
3126
|
-
*/
|
|
3127
|
-
class EnvironmentMismatchError extends Error {
|
|
3128
|
-
constructor(message) {
|
|
3129
|
-
super(message);
|
|
3130
|
-
this.name = 'EnvironmentMismatchError';
|
|
3131
|
-
Object.setPrototypeOf(this, EnvironmentMismatchError.prototype);
|
|
3132
|
-
}
|
|
3133
|
-
}
|
|
3134
|
-
|
|
3135
|
-
/**
|
|
3136
|
-
* This error occurs when some expectation is not met in the execution of the pipeline
|
|
3137
|
-
*
|
|
3138
|
-
* @public exported from `@promptbook/core`
|
|
3139
|
-
* Note: Do not throw this error, its reserved for `checkExpectations` and `createPipelineExecutor` and public ONLY to be serializable through remote server
|
|
3140
|
-
* Note: Always thrown in `checkExpectations` and catched in `createPipelineExecutor` and rethrown as `PipelineExecutionError`
|
|
3141
|
-
* Note: This is a kindof subtype of PipelineExecutionError
|
|
3142
|
-
*/
|
|
3143
|
-
class ExpectError extends Error {
|
|
3144
|
-
constructor(message) {
|
|
3145
|
-
super(message);
|
|
3146
|
-
this.name = 'ExpectError';
|
|
3147
|
-
Object.setPrototypeOf(this, ExpectError.prototype);
|
|
3148
|
-
}
|
|
3149
|
-
}
|
|
3150
|
-
|
|
3151
|
-
/**
|
|
3152
|
-
* This error indicates that the promptbook can not retrieve knowledge from external sources
|
|
3153
|
-
*
|
|
3154
|
-
* @public exported from `@promptbook/core`
|
|
3155
|
-
*/
|
|
3156
|
-
class KnowledgeScrapeError extends Error {
|
|
3157
|
-
constructor(message) {
|
|
3158
|
-
super(message);
|
|
3159
|
-
this.name = 'KnowledgeScrapeError';
|
|
3160
|
-
Object.setPrototypeOf(this, KnowledgeScrapeError.prototype);
|
|
3161
|
-
}
|
|
3162
|
-
}
|
|
3163
|
-
|
|
3164
|
-
/**
|
|
3165
|
-
* This error type indicates that some tools are missing for pipeline execution or preparation
|
|
3166
|
-
*
|
|
3167
|
-
* @public exported from `@promptbook/core`
|
|
3168
|
-
*/
|
|
3169
|
-
class MissingToolsError extends Error {
|
|
3170
|
-
constructor(message) {
|
|
3171
|
-
super(spaceTrim$1((block) => `
|
|
3172
|
-
${block(message)}
|
|
3173
|
-
|
|
3174
|
-
Note: You have probably forgot to provide some tools for pipeline execution or preparation
|
|
3175
|
-
|
|
3176
|
-
`));
|
|
3177
|
-
this.name = 'MissingToolsError';
|
|
3178
|
-
Object.setPrototypeOf(this, MissingToolsError.prototype);
|
|
3179
|
-
}
|
|
3180
|
-
}
|
|
3181
|
-
|
|
3182
|
-
/**
|
|
3183
|
-
* This error indicates that promptbook operation is not allowed
|
|
3184
|
-
*
|
|
3185
|
-
* @public exported from `@promptbook/core`
|
|
3186
|
-
*/
|
|
3187
|
-
class NotAllowed extends Error {
|
|
3188
|
-
constructor(message) {
|
|
3189
|
-
super(message);
|
|
3190
|
-
this.name = 'NotAllowed';
|
|
3191
|
-
Object.setPrototypeOf(this, NotAllowed.prototype);
|
|
3192
|
-
}
|
|
3193
|
-
}
|
|
3194
|
-
|
|
3195
|
-
/**
|
|
3196
|
-
* This error indicates that promptbook not found in the collection
|
|
3197
|
-
*
|
|
3198
|
-
* @public exported from `@promptbook/core`
|
|
3199
|
-
*/
|
|
3200
|
-
class NotFoundError extends Error {
|
|
3201
|
-
constructor(message) {
|
|
3202
|
-
super(message);
|
|
3203
|
-
this.name = 'NotFoundError';
|
|
3204
|
-
Object.setPrototypeOf(this, NotFoundError.prototype);
|
|
3205
|
-
}
|
|
3206
|
-
}
|
|
3207
|
-
|
|
3208
|
-
/**
|
|
3209
|
-
* This error type indicates that some part of the code is not implemented yet
|
|
3210
|
-
*
|
|
3211
|
-
* @public exported from `@promptbook/core`
|
|
2946
|
+
* @public exported from `@promptbook/core`
|
|
3212
2947
|
*/
|
|
3213
2948
|
class NotYetImplementedError extends Error {
|
|
3214
2949
|
constructor(message) {
|
|
@@ -3357,7 +3092,7 @@ function serializeError(error) {
|
|
|
3357
3092
|
const { name, message, stack } = error;
|
|
3358
3093
|
const { id } = error;
|
|
3359
3094
|
if (!Object.keys(ALL_ERRORS).includes(name)) {
|
|
3360
|
-
console.error(spaceTrim$
|
|
3095
|
+
console.error(spaceTrim$1((block) => `
|
|
3361
3096
|
|
|
3362
3097
|
Cannot serialize error with name "${name}"
|
|
3363
3098
|
|
|
@@ -3369,41 +3104,205 @@ function serializeError(error) {
|
|
|
3369
3104
|
|
|
3370
3105
|
`));
|
|
3371
3106
|
}
|
|
3372
|
-
return {
|
|
3373
|
-
name: name,
|
|
3374
|
-
message,
|
|
3375
|
-
stack,
|
|
3376
|
-
id, // Include id in the serialized object
|
|
3377
|
-
};
|
|
3107
|
+
return {
|
|
3108
|
+
name: name,
|
|
3109
|
+
message,
|
|
3110
|
+
stack,
|
|
3111
|
+
id, // Include id in the serialized object
|
|
3112
|
+
};
|
|
3113
|
+
}
|
|
3114
|
+
|
|
3115
|
+
/**
|
|
3116
|
+
* Async version of Array.forEach
|
|
3117
|
+
*
|
|
3118
|
+
* @param array - Array to iterate over
|
|
3119
|
+
* @param options - Options for the function
|
|
3120
|
+
* @param callbackfunction - Function to call for each item
|
|
3121
|
+
* @public exported from `@promptbook/utils`
|
|
3122
|
+
* @deprecated [🪂] Use queues instead
|
|
3123
|
+
*/
|
|
3124
|
+
async function forEachAsync(array, options, callbackfunction) {
|
|
3125
|
+
const { maxParallelCount = Infinity } = options;
|
|
3126
|
+
let index = 0;
|
|
3127
|
+
let runningTasks = [];
|
|
3128
|
+
const tasks = [];
|
|
3129
|
+
for (const item of array) {
|
|
3130
|
+
const currentIndex = index++;
|
|
3131
|
+
const task = callbackfunction(item, currentIndex, array);
|
|
3132
|
+
tasks.push(task);
|
|
3133
|
+
runningTasks.push(task);
|
|
3134
|
+
/* not await */ Promise.resolve(task).then(() => {
|
|
3135
|
+
runningTasks = runningTasks.filter((runningTask) => runningTask !== task);
|
|
3136
|
+
});
|
|
3137
|
+
if (maxParallelCount < runningTasks.length) {
|
|
3138
|
+
await Promise.race(runningTasks);
|
|
3139
|
+
}
|
|
3140
|
+
}
|
|
3141
|
+
await Promise.all(tasks);
|
|
3142
|
+
}
|
|
3143
|
+
|
|
3144
|
+
/**
|
|
3145
|
+
* Format either small or big number
|
|
3146
|
+
*
|
|
3147
|
+
* @public exported from `@promptbook/utils`
|
|
3148
|
+
*/
|
|
3149
|
+
function numberToString(value) {
|
|
3150
|
+
if (value === 0) {
|
|
3151
|
+
return '0';
|
|
3152
|
+
}
|
|
3153
|
+
else if (Number.isNaN(value)) {
|
|
3154
|
+
return VALUE_STRINGS.nan;
|
|
3155
|
+
}
|
|
3156
|
+
else if (value === Infinity) {
|
|
3157
|
+
return VALUE_STRINGS.infinity;
|
|
3158
|
+
}
|
|
3159
|
+
else if (value === -Infinity) {
|
|
3160
|
+
return VALUE_STRINGS.negativeInfinity;
|
|
3161
|
+
}
|
|
3162
|
+
for (let exponent = 0; exponent < 15; exponent++) {
|
|
3163
|
+
const factor = 10 ** exponent;
|
|
3164
|
+
const valueRounded = Math.round(value * factor) / factor;
|
|
3165
|
+
if (Math.abs(value - valueRounded) / value < SMALL_NUMBER) {
|
|
3166
|
+
return valueRounded.toFixed(exponent);
|
|
3167
|
+
}
|
|
3168
|
+
}
|
|
3169
|
+
return value.toString();
|
|
3170
|
+
}
|
|
3171
|
+
|
|
3172
|
+
/**
|
|
3173
|
+
* Function `valueToString` will convert the given value to string
|
|
3174
|
+
* This is useful and used in the `templateParameters` function
|
|
3175
|
+
*
|
|
3176
|
+
* Note: This function is not just calling `toString` method
|
|
3177
|
+
* It's more complex and can handle this conversion specifically for LLM models
|
|
3178
|
+
* See `VALUE_STRINGS`
|
|
3179
|
+
*
|
|
3180
|
+
* Note: There are 2 similar functions
|
|
3181
|
+
* - `valueToString` converts value to string for LLM models as human-readable string
|
|
3182
|
+
* - `asSerializable` converts value to string to preserve full information to be able to convert it back
|
|
3183
|
+
*
|
|
3184
|
+
* @public exported from `@promptbook/utils`
|
|
3185
|
+
*/
|
|
3186
|
+
function valueToString(value) {
|
|
3187
|
+
try {
|
|
3188
|
+
if (value === '') {
|
|
3189
|
+
return VALUE_STRINGS.empty;
|
|
3190
|
+
}
|
|
3191
|
+
else if (value === null) {
|
|
3192
|
+
return VALUE_STRINGS.null;
|
|
3193
|
+
}
|
|
3194
|
+
else if (value === undefined) {
|
|
3195
|
+
return VALUE_STRINGS.undefined;
|
|
3196
|
+
}
|
|
3197
|
+
else if (typeof value === 'string') {
|
|
3198
|
+
return value;
|
|
3199
|
+
}
|
|
3200
|
+
else if (typeof value === 'number') {
|
|
3201
|
+
return numberToString(value);
|
|
3202
|
+
}
|
|
3203
|
+
else if (value instanceof Date) {
|
|
3204
|
+
return value.toISOString();
|
|
3205
|
+
}
|
|
3206
|
+
else {
|
|
3207
|
+
try {
|
|
3208
|
+
return JSON.stringify(value);
|
|
3209
|
+
}
|
|
3210
|
+
catch (error) {
|
|
3211
|
+
if (error instanceof TypeError && error.message.includes('circular structure')) {
|
|
3212
|
+
return VALUE_STRINGS.circular;
|
|
3213
|
+
}
|
|
3214
|
+
throw error;
|
|
3215
|
+
}
|
|
3216
|
+
}
|
|
3217
|
+
}
|
|
3218
|
+
catch (error) {
|
|
3219
|
+
assertsError(error);
|
|
3220
|
+
console.error(error);
|
|
3221
|
+
return VALUE_STRINGS.unserializable;
|
|
3222
|
+
}
|
|
3223
|
+
}
|
|
3224
|
+
|
|
3225
|
+
/**
|
|
3226
|
+
* Replaces parameters in template with values from parameters object
|
|
3227
|
+
*
|
|
3228
|
+
* Note: This function is not places strings into string,
|
|
3229
|
+
* It's more complex and can handle this operation specifically for LLM models
|
|
3230
|
+
*
|
|
3231
|
+
* @param template the template with parameters in {curly} braces
|
|
3232
|
+
* @param parameters the object with parameters
|
|
3233
|
+
* @returns the template with replaced parameters
|
|
3234
|
+
* @throws {PipelineExecutionError} if parameter is not defined, not closed, or not opened
|
|
3235
|
+
* @public exported from `@promptbook/utils`
|
|
3236
|
+
*/
|
|
3237
|
+
function templateParameters(template, parameters) {
|
|
3238
|
+
for (const [parameterName, parameterValue] of Object.entries(parameters)) {
|
|
3239
|
+
if (parameterValue === RESERVED_PARAMETER_MISSING_VALUE) {
|
|
3240
|
+
throw new UnexpectedError(`Parameter \`{${parameterName}}\` has missing value`);
|
|
3241
|
+
}
|
|
3242
|
+
else if (parameterValue === RESERVED_PARAMETER_RESTRICTED) {
|
|
3243
|
+
// TODO: [🍵]
|
|
3244
|
+
throw new UnexpectedError(`Parameter \`{${parameterName}}\` is restricted to use`);
|
|
3245
|
+
}
|
|
3246
|
+
}
|
|
3247
|
+
let replacedTemplates = template;
|
|
3248
|
+
let match;
|
|
3249
|
+
let loopLimit = LOOP_LIMIT;
|
|
3250
|
+
while ((match = /^(?<precol>.*){(?<parameterName>\w+)}(.*)/m /* <- Not global */
|
|
3251
|
+
.exec(replacedTemplates))) {
|
|
3252
|
+
if (loopLimit-- < 0) {
|
|
3253
|
+
throw new LimitReachedError('Loop limit reached during parameters replacement in `templateParameters`');
|
|
3254
|
+
}
|
|
3255
|
+
const precol = match.groups.precol;
|
|
3256
|
+
const parameterName = match.groups.parameterName;
|
|
3257
|
+
if (parameterName === '') {
|
|
3258
|
+
// Note: Skip empty placeholders. It's used to avoid confusion with JSON-like strings
|
|
3259
|
+
continue;
|
|
3260
|
+
}
|
|
3261
|
+
if (parameterName.indexOf('{') !== -1 || parameterName.indexOf('}') !== -1) {
|
|
3262
|
+
throw new PipelineExecutionError('Parameter is already opened or not closed');
|
|
3263
|
+
}
|
|
3264
|
+
if (parameters[parameterName] === undefined) {
|
|
3265
|
+
throw new PipelineExecutionError(`Parameter \`{${parameterName}}\` is not defined`);
|
|
3266
|
+
}
|
|
3267
|
+
let parameterValue = parameters[parameterName];
|
|
3268
|
+
if (parameterValue === undefined) {
|
|
3269
|
+
throw new PipelineExecutionError(`Parameter \`{${parameterName}}\` is not defined`);
|
|
3270
|
+
}
|
|
3271
|
+
parameterValue = valueToString(parameterValue);
|
|
3272
|
+
// Escape curly braces in parameter values to prevent prompt-injection
|
|
3273
|
+
parameterValue = parameterValue.replace(/[{}]/g, '\\$&');
|
|
3274
|
+
if (parameterValue.includes('\n') && /^\s*\W{0,3}\s*$/.test(precol)) {
|
|
3275
|
+
parameterValue = parameterValue
|
|
3276
|
+
.split(/\r?\n/)
|
|
3277
|
+
.map((line, index) => (index === 0 ? line : `${precol}${line}`))
|
|
3278
|
+
.join('\n');
|
|
3279
|
+
}
|
|
3280
|
+
replacedTemplates =
|
|
3281
|
+
replacedTemplates.substring(0, match.index + precol.length) +
|
|
3282
|
+
parameterValue +
|
|
3283
|
+
replacedTemplates.substring(match.index + precol.length + parameterName.length + 2);
|
|
3284
|
+
}
|
|
3285
|
+
// [💫] Check if there are parameters that are not closed properly
|
|
3286
|
+
if (/{\w+$/.test(replacedTemplates)) {
|
|
3287
|
+
throw new PipelineExecutionError('Parameter is not closed');
|
|
3288
|
+
}
|
|
3289
|
+
// [💫] Check if there are parameters that are not opened properly
|
|
3290
|
+
if (/^\w+}/.test(replacedTemplates)) {
|
|
3291
|
+
throw new PipelineExecutionError('Parameter is not opened');
|
|
3292
|
+
}
|
|
3293
|
+
return replacedTemplates;
|
|
3378
3294
|
}
|
|
3379
3295
|
|
|
3380
3296
|
/**
|
|
3381
|
-
*
|
|
3297
|
+
* Simple wrapper `new Date().toISOString()`
|
|
3382
3298
|
*
|
|
3383
|
-
*
|
|
3384
|
-
*
|
|
3385
|
-
* @
|
|
3299
|
+
* Note: `$` is used to indicate that this function is not a pure function - it is not deterministic because it depends on the current time
|
|
3300
|
+
*
|
|
3301
|
+
* @returns string_date branded type
|
|
3386
3302
|
* @public exported from `@promptbook/utils`
|
|
3387
|
-
* @deprecated [🪂] Use queues instead
|
|
3388
3303
|
*/
|
|
3389
|
-
|
|
3390
|
-
|
|
3391
|
-
let index = 0;
|
|
3392
|
-
let runningTasks = [];
|
|
3393
|
-
const tasks = [];
|
|
3394
|
-
for (const item of array) {
|
|
3395
|
-
const currentIndex = index++;
|
|
3396
|
-
const task = callbackfunction(item, currentIndex, array);
|
|
3397
|
-
tasks.push(task);
|
|
3398
|
-
runningTasks.push(task);
|
|
3399
|
-
/* not await */ Promise.resolve(task).then(() => {
|
|
3400
|
-
runningTasks = runningTasks.filter((runningTask) => runningTask !== task);
|
|
3401
|
-
});
|
|
3402
|
-
if (maxParallelCount < runningTasks.length) {
|
|
3403
|
-
await Promise.race(runningTasks);
|
|
3404
|
-
}
|
|
3405
|
-
}
|
|
3406
|
-
await Promise.all(tasks);
|
|
3304
|
+
function $getCurrentDate() {
|
|
3305
|
+
return new Date().toISOString();
|
|
3407
3306
|
}
|
|
3408
3307
|
|
|
3409
3308
|
/**
|
|
@@ -3478,6 +3377,107 @@ function normalizeTo_snake_case(text) {
|
|
|
3478
3377
|
return normalizeTo_SCREAMING_CASE(text).toLowerCase();
|
|
3479
3378
|
}
|
|
3480
3379
|
|
|
3380
|
+
/**
|
|
3381
|
+
* Marker property stored inside serialized tool-execution envelopes.
|
|
3382
|
+
*
|
|
3383
|
+
* @private internal tool-execution transport
|
|
3384
|
+
*/
|
|
3385
|
+
const TOOL_EXECUTION_ENVELOPE_MARKER = '__promptbookToolExecutionEnvelope';
|
|
3386
|
+
/**
|
|
3387
|
+
* Parses one serialized tool-execution envelope when present.
|
|
3388
|
+
*
|
|
3389
|
+
* @private internal tool-execution transport
|
|
3390
|
+
*/
|
|
3391
|
+
function parseToolExecutionEnvelope(rawValue) {
|
|
3392
|
+
if (typeof rawValue !== 'string') {
|
|
3393
|
+
return null;
|
|
3394
|
+
}
|
|
3395
|
+
try {
|
|
3396
|
+
const parsedValue = JSON.parse(rawValue);
|
|
3397
|
+
if (!parsedValue ||
|
|
3398
|
+
typeof parsedValue !== 'object' ||
|
|
3399
|
+
parsedValue[TOOL_EXECUTION_ENVELOPE_MARKER] !== true ||
|
|
3400
|
+
typeof parsedValue.assistantMessage !== 'string') {
|
|
3401
|
+
return null;
|
|
3402
|
+
}
|
|
3403
|
+
return {
|
|
3404
|
+
assistantMessage: parsedValue.assistantMessage,
|
|
3405
|
+
toolResult: parsedValue.toolResult,
|
|
3406
|
+
};
|
|
3407
|
+
}
|
|
3408
|
+
catch (_a) {
|
|
3409
|
+
return null;
|
|
3410
|
+
}
|
|
3411
|
+
}
|
|
3412
|
+
/**
|
|
3413
|
+
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
3414
|
+
*/
|
|
3415
|
+
|
|
3416
|
+
/**
|
|
3417
|
+
* Prompt parameter key used to pass hidden runtime context to tool execution.
|
|
3418
|
+
*
|
|
3419
|
+
* @private internal runtime wiring for commitment tools
|
|
3420
|
+
*/
|
|
3421
|
+
const TOOL_RUNTIME_CONTEXT_PARAMETER = 'promptbookToolRuntimeContext';
|
|
3422
|
+
/**
|
|
3423
|
+
* Hidden argument key used to pass runtime context into individual tool calls.
|
|
3424
|
+
*
|
|
3425
|
+
* @private internal runtime wiring for commitment tools
|
|
3426
|
+
*/
|
|
3427
|
+
const TOOL_RUNTIME_CONTEXT_ARGUMENT = '__promptbookToolRuntimeContext';
|
|
3428
|
+
/**
|
|
3429
|
+
* Prompt parameter key used to pass a hidden tool-progress listener token into script execution.
|
|
3430
|
+
*
|
|
3431
|
+
* @private internal runtime wiring for commitment tools
|
|
3432
|
+
*/
|
|
3433
|
+
const TOOL_PROGRESS_TOKEN_PARAMETER = 'promptbookToolProgressToken';
|
|
3434
|
+
/**
|
|
3435
|
+
* Hidden argument key used to pass a tool-progress listener token into individual tool calls.
|
|
3436
|
+
*
|
|
3437
|
+
* @private internal runtime wiring for commitment tools
|
|
3438
|
+
*/
|
|
3439
|
+
const TOOL_PROGRESS_TOKEN_ARGUMENT = '__promptbookToolProgressToken';
|
|
3440
|
+
/**
|
|
3441
|
+
* Monotonic counter used for hidden progress-listener tokens.
|
|
3442
|
+
*
|
|
3443
|
+
* @private internal runtime wiring for commitment tools
|
|
3444
|
+
*/
|
|
3445
|
+
let toolCallProgressListenerCounter = 0;
|
|
3446
|
+
/**
|
|
3447
|
+
* Active tool-progress listeners keyed by hidden execution token.
|
|
3448
|
+
*
|
|
3449
|
+
* @private internal runtime wiring for commitment tools
|
|
3450
|
+
*/
|
|
3451
|
+
const toolCallProgressListeners = new Map();
|
|
3452
|
+
/**
|
|
3453
|
+
* Registers one in-memory listener that receives progress updates emitted by a running tool.
|
|
3454
|
+
*
|
|
3455
|
+
* The returned token is passed into script execution as a hidden argument so tool implementations
|
|
3456
|
+
* can stream progress without exposing extra parameters to the model.
|
|
3457
|
+
*
|
|
3458
|
+
* @param listener - Listener notified about tool progress.
|
|
3459
|
+
* @returns Hidden token used to route progress updates.
|
|
3460
|
+
* @private internal runtime wiring for commitment tools
|
|
3461
|
+
*/
|
|
3462
|
+
function registerToolCallProgressListener(listener) {
|
|
3463
|
+
toolCallProgressListenerCounter += 1;
|
|
3464
|
+
const token = `tool-progress:${Date.now()}:${toolCallProgressListenerCounter}`;
|
|
3465
|
+
toolCallProgressListeners.set(token, listener);
|
|
3466
|
+
return token;
|
|
3467
|
+
}
|
|
3468
|
+
/**
|
|
3469
|
+
* Unregisters one in-memory progress listener.
|
|
3470
|
+
*
|
|
3471
|
+
* @param token - Token previously created by `registerToolCallProgressListener`.
|
|
3472
|
+
* @private internal runtime wiring for commitment tools
|
|
3473
|
+
*/
|
|
3474
|
+
function unregisterToolCallProgressListener(token) {
|
|
3475
|
+
toolCallProgressListeners.delete(token);
|
|
3476
|
+
}
|
|
3477
|
+
/**
|
|
3478
|
+
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
3479
|
+
*/
|
|
3480
|
+
|
|
3481
3481
|
/**
|
|
3482
3482
|
* Function `addUsage` will add multiple usages into one
|
|
3483
3483
|
*
|
|
@@ -3532,53 +3532,6 @@ function addUsage(...usageItems) {
|
|
|
3532
3532
|
}, deepClone(ZERO_USAGE));
|
|
3533
3533
|
}
|
|
3534
3534
|
|
|
3535
|
-
/**
|
|
3536
|
-
* Maps Promptbook tools to OpenAI tools.
|
|
3537
|
-
*
|
|
3538
|
-
* @private
|
|
3539
|
-
*/
|
|
3540
|
-
function mapToolsToOpenAi(tools) {
|
|
3541
|
-
return tools.map((tool) => ({
|
|
3542
|
-
type: 'function',
|
|
3543
|
-
function: {
|
|
3544
|
-
name: tool.name,
|
|
3545
|
-
description: tool.description,
|
|
3546
|
-
parameters: tool.parameters,
|
|
3547
|
-
},
|
|
3548
|
-
}));
|
|
3549
|
-
}
|
|
3550
|
-
|
|
3551
|
-
/**
|
|
3552
|
-
* Builds a tool invocation script that injects hidden runtime context into tool args.
|
|
3553
|
-
*
|
|
3554
|
-
* @private utility of OpenAI tool execution wrappers
|
|
3555
|
-
*/
|
|
3556
|
-
function buildToolInvocationScript(options) {
|
|
3557
|
-
const { functionName, functionArgsExpression } = options;
|
|
3558
|
-
return `
|
|
3559
|
-
const args = ${functionArgsExpression};
|
|
3560
|
-
const runtimeContextRaw =
|
|
3561
|
-
typeof ${TOOL_RUNTIME_CONTEXT_PARAMETER} === 'undefined'
|
|
3562
|
-
? undefined
|
|
3563
|
-
: ${TOOL_RUNTIME_CONTEXT_PARAMETER};
|
|
3564
|
-
|
|
3565
|
-
if (runtimeContextRaw !== undefined && args && typeof args === 'object' && !Array.isArray(args)) {
|
|
3566
|
-
args.${TOOL_RUNTIME_CONTEXT_ARGUMENT} = runtimeContextRaw;
|
|
3567
|
-
}
|
|
3568
|
-
|
|
3569
|
-
const toolProgressTokenRaw =
|
|
3570
|
-
typeof ${TOOL_PROGRESS_TOKEN_PARAMETER} === 'undefined'
|
|
3571
|
-
? undefined
|
|
3572
|
-
: ${TOOL_PROGRESS_TOKEN_PARAMETER};
|
|
3573
|
-
|
|
3574
|
-
if (toolProgressTokenRaw !== undefined && args && typeof args === 'object' && !Array.isArray(args)) {
|
|
3575
|
-
args.${TOOL_PROGRESS_TOKEN_ARGUMENT} = toolProgressTokenRaw;
|
|
3576
|
-
}
|
|
3577
|
-
|
|
3578
|
-
return await ${functionName}(args);
|
|
3579
|
-
`;
|
|
3580
|
-
}
|
|
3581
|
-
|
|
3582
3535
|
/**
|
|
3583
3536
|
* Parses an OpenAI error message to identify which parameter is unsupported
|
|
3584
3537
|
*
|
|
@@ -3635,6 +3588,53 @@ function isUnsupportedParameterError(error) {
|
|
|
3635
3588
|
errorMessage.includes('does not support'));
|
|
3636
3589
|
}
|
|
3637
3590
|
|
|
3591
|
+
/**
|
|
3592
|
+
* Builds a tool invocation script that injects hidden runtime context into tool args.
|
|
3593
|
+
*
|
|
3594
|
+
* @private utility of OpenAI tool execution wrappers
|
|
3595
|
+
*/
|
|
3596
|
+
function buildToolInvocationScript(options) {
|
|
3597
|
+
const { functionName, functionArgsExpression } = options;
|
|
3598
|
+
return `
|
|
3599
|
+
const args = ${functionArgsExpression};
|
|
3600
|
+
const runtimeContextRaw =
|
|
3601
|
+
typeof ${TOOL_RUNTIME_CONTEXT_PARAMETER} === 'undefined'
|
|
3602
|
+
? undefined
|
|
3603
|
+
: ${TOOL_RUNTIME_CONTEXT_PARAMETER};
|
|
3604
|
+
|
|
3605
|
+
if (runtimeContextRaw !== undefined && args && typeof args === 'object' && !Array.isArray(args)) {
|
|
3606
|
+
args.${TOOL_RUNTIME_CONTEXT_ARGUMENT} = runtimeContextRaw;
|
|
3607
|
+
}
|
|
3608
|
+
|
|
3609
|
+
const toolProgressTokenRaw =
|
|
3610
|
+
typeof ${TOOL_PROGRESS_TOKEN_PARAMETER} === 'undefined'
|
|
3611
|
+
? undefined
|
|
3612
|
+
: ${TOOL_PROGRESS_TOKEN_PARAMETER};
|
|
3613
|
+
|
|
3614
|
+
if (toolProgressTokenRaw !== undefined && args && typeof args === 'object' && !Array.isArray(args)) {
|
|
3615
|
+
args.${TOOL_PROGRESS_TOKEN_ARGUMENT} = toolProgressTokenRaw;
|
|
3616
|
+
}
|
|
3617
|
+
|
|
3618
|
+
return await ${functionName}(args);
|
|
3619
|
+
`;
|
|
3620
|
+
}
|
|
3621
|
+
|
|
3622
|
+
/**
|
|
3623
|
+
* Maps Promptbook tools to OpenAI tools.
|
|
3624
|
+
*
|
|
3625
|
+
* @private
|
|
3626
|
+
*/
|
|
3627
|
+
function mapToolsToOpenAi(tools) {
|
|
3628
|
+
return tools.map((tool) => ({
|
|
3629
|
+
type: 'function',
|
|
3630
|
+
function: {
|
|
3631
|
+
name: tool.name,
|
|
3632
|
+
description: tool.description,
|
|
3633
|
+
parameters: tool.parameters,
|
|
3634
|
+
},
|
|
3635
|
+
}));
|
|
3636
|
+
}
|
|
3637
|
+
|
|
3638
3638
|
/**
|
|
3639
3639
|
* Provides access to the structured clone implementation when available.
|
|
3640
3640
|
*/
|
|
@@ -4601,7 +4601,7 @@ class OpenAiCompatibleExecutionTools {
|
|
|
4601
4601
|
// Note: Match exact or prefix for model families
|
|
4602
4602
|
const model = this.HARDCODED_MODELS.find(({ modelName }) => modelName === defaultModelName || modelName.startsWith(defaultModelName));
|
|
4603
4603
|
if (model === undefined) {
|
|
4604
|
-
throw new PipelineExecutionError(spaceTrim$
|
|
4604
|
+
throw new PipelineExecutionError(spaceTrim$1((block) => `
|
|
4605
4605
|
Cannot find model in ${this.title} models with name "${defaultModelName}" which should be used as default.
|
|
4606
4606
|
|
|
4607
4607
|
Available models:
|