@promptbook/markdown-utils 0.95.0 โ 0.98.0-10
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/README.md +12 -0
- package/esm/index.es.js +113 -52
- package/esm/index.es.js.map +1 -1
- package/esm/typings/src/_packages/anthropic-claude.index.d.ts +2 -2
- package/esm/typings/src/_packages/cli.index.d.ts +4 -0
- package/esm/typings/src/_packages/core.index.d.ts +2 -0
- package/esm/typings/src/_packages/openai.index.d.ts +10 -0
- package/esm/typings/src/_packages/types.index.d.ts +12 -2
- package/esm/typings/src/_packages/wizard.index.d.ts +4 -0
- package/esm/typings/src/config.d.ts +1 -1
- package/esm/typings/src/execution/createPipelineExecutor/$OngoingTaskResult.d.ts +8 -0
- package/esm/typings/src/execution/utils/validatePromptResult.d.ts +53 -0
- package/esm/typings/src/llm-providers/anthropic-claude/AnthropicClaudeExecutionTools.d.ts +3 -3
- package/esm/typings/src/llm-providers/anthropic-claude/AnthropicClaudeExecutionToolsOptions.d.ts +2 -2
- package/esm/typings/src/llm-providers/openai/OpenAiAssistantExecutionToolsOptions.d.ts +2 -2
- package/esm/typings/src/llm-providers/openai/OpenAiCompatibleExecutionTools.d.ts +4 -4
- package/esm/typings/src/llm-providers/openai/OpenAiCompatibleExecutionToolsOptions.d.ts +52 -0
- package/esm/typings/src/llm-providers/openai/OpenAiExecutionToolsOptions.d.ts +3 -5
- package/esm/typings/src/llm-providers/openai/createOpenAiCompatibleExecutionTools.d.ts +74 -0
- package/esm/typings/src/llm-providers/openai/register-configuration.d.ts +11 -0
- package/esm/typings/src/llm-providers/openai/register-constructor.d.ts +14 -0
- package/esm/typings/src/version.d.ts +1 -1
- package/package.json +1 -1
- package/umd/index.umd.js +113 -52
- package/umd/index.umd.js.map +1 -1
package/umd/index.umd.js
CHANGED
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
* @generated
|
|
26
26
|
* @see https://github.com/webgptorg/promptbook
|
|
27
27
|
*/
|
|
28
|
-
const PROMPTBOOK_ENGINE_VERSION = '0.
|
|
28
|
+
const PROMPTBOOK_ENGINE_VERSION = '0.98.0-10';
|
|
29
29
|
/**
|
|
30
30
|
* TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
|
|
31
31
|
* Note: [๐] Ignore a discrepancy between file name and entity name
|
|
@@ -304,7 +304,7 @@
|
|
|
304
304
|
*
|
|
305
305
|
* @public exported from `@promptbook/core`
|
|
306
306
|
*/
|
|
307
|
-
const DEFAULT_MAX_EXECUTION_ATTEMPTS =
|
|
307
|
+
const DEFAULT_MAX_EXECUTION_ATTEMPTS = 7; // <- TODO: [๐คนโโ๏ธ]
|
|
308
308
|
// <- TODO: [๐] Make also `BOOKS_DIRNAME_ALTERNATIVES`
|
|
309
309
|
// TODO: Just `.promptbook` in config, hardcode subfolders like `download-cache` or `execution-cache`
|
|
310
310
|
/**
|
|
@@ -2087,7 +2087,7 @@
|
|
|
2087
2087
|
throw new Error(spaceTrim__default["default"]((block) => `
|
|
2088
2088
|
${block(error.message)}
|
|
2089
2089
|
|
|
2090
|
-
The JSON text:
|
|
2090
|
+
The expected JSON text:
|
|
2091
2091
|
${block(value)}
|
|
2092
2092
|
`));
|
|
2093
2093
|
}
|
|
@@ -4792,6 +4792,68 @@
|
|
|
4792
4792
|
* Note: [๐] and [๐ค ] are interconnected together
|
|
4793
4793
|
*/
|
|
4794
4794
|
|
|
4795
|
+
/**
|
|
4796
|
+
* Validates a prompt result against expectations and format requirements.
|
|
4797
|
+
* This function provides a common abstraction for result validation that can be used
|
|
4798
|
+
* by both execution logic and caching logic to ensure consistency.
|
|
4799
|
+
*
|
|
4800
|
+
* @param options - The validation options including result string, expectations, and format
|
|
4801
|
+
* @returns Validation result with processed string and validity status
|
|
4802
|
+
* @private internal function of `createPipelineExecutor` and `cacheLlmTools`
|
|
4803
|
+
*/
|
|
4804
|
+
function validatePromptResult(options) {
|
|
4805
|
+
const { resultString, expectations, format } = options;
|
|
4806
|
+
let processedResultString = resultString;
|
|
4807
|
+
let validationError;
|
|
4808
|
+
try {
|
|
4809
|
+
// TODO: [๐] Unite object for expecting amount and format
|
|
4810
|
+
if (format) {
|
|
4811
|
+
if (format === 'JSON') {
|
|
4812
|
+
if (!isValidJsonString(processedResultString)) {
|
|
4813
|
+
// TODO: [๐ข] Do more universally via `FormatParser`
|
|
4814
|
+
try {
|
|
4815
|
+
processedResultString = extractJsonBlock(processedResultString);
|
|
4816
|
+
}
|
|
4817
|
+
catch (error) {
|
|
4818
|
+
keepUnused(error);
|
|
4819
|
+
throw new ExpectError(spaceTrim.spaceTrim((block) => `
|
|
4820
|
+
Expected valid JSON string
|
|
4821
|
+
|
|
4822
|
+
The expected JSON text:
|
|
4823
|
+
${block(processedResultString)}
|
|
4824
|
+
`));
|
|
4825
|
+
}
|
|
4826
|
+
}
|
|
4827
|
+
}
|
|
4828
|
+
else {
|
|
4829
|
+
throw new UnexpectedError(`Unknown format "${format}"`);
|
|
4830
|
+
}
|
|
4831
|
+
}
|
|
4832
|
+
// TODO: [๐] Unite object for expecting amount and format
|
|
4833
|
+
if (expectations) {
|
|
4834
|
+
checkExpectations(expectations, processedResultString);
|
|
4835
|
+
}
|
|
4836
|
+
return {
|
|
4837
|
+
isValid: true,
|
|
4838
|
+
processedResultString,
|
|
4839
|
+
};
|
|
4840
|
+
}
|
|
4841
|
+
catch (error) {
|
|
4842
|
+
if (error instanceof ExpectError) {
|
|
4843
|
+
validationError = error;
|
|
4844
|
+
}
|
|
4845
|
+
else {
|
|
4846
|
+
// Re-throw non-ExpectError errors (like UnexpectedError)
|
|
4847
|
+
throw error;
|
|
4848
|
+
}
|
|
4849
|
+
return {
|
|
4850
|
+
isValid: false,
|
|
4851
|
+
processedResultString,
|
|
4852
|
+
error: validationError,
|
|
4853
|
+
};
|
|
4854
|
+
}
|
|
4855
|
+
}
|
|
4856
|
+
|
|
4795
4857
|
/**
|
|
4796
4858
|
* Executes a pipeline task with multiple attempts, including joker and retry logic. Handles different task types
|
|
4797
4859
|
* (prompt, script, dialog, etc.), applies postprocessing, checks expectations, and updates the execution report.
|
|
@@ -4809,17 +4871,18 @@
|
|
|
4809
4871
|
$resultString: null,
|
|
4810
4872
|
$expectError: null,
|
|
4811
4873
|
$scriptPipelineExecutionErrors: [],
|
|
4874
|
+
$failedResults: [], // Track all failed attempts
|
|
4812
4875
|
};
|
|
4813
4876
|
// TODO: [๐] Make arrayable LLMs -> single LLM DRY
|
|
4814
4877
|
const _llms = arrayableToArray(tools.llm);
|
|
4815
4878
|
const llmTools = _llms.length === 1 ? _llms[0] : joinLlmExecutionTools(..._llms);
|
|
4816
|
-
attempts: for (let
|
|
4817
|
-
const isJokerAttempt =
|
|
4818
|
-
const jokerParameterName = jokerParameterNames[jokerParameterNames.length +
|
|
4879
|
+
attempts: for (let attemptIndex = -jokerParameterNames.length; attemptIndex < maxAttempts; attemptIndex++) {
|
|
4880
|
+
const isJokerAttempt = attemptIndex < 0;
|
|
4881
|
+
const jokerParameterName = jokerParameterNames[jokerParameterNames.length + attemptIndex];
|
|
4819
4882
|
// TODO: [๐ง ][๐ญ] JOKERS, EXPECTATIONS, POSTPROCESSING and FOREACH
|
|
4820
4883
|
if (isJokerAttempt && !jokerParameterName) {
|
|
4821
4884
|
throw new UnexpectedError(spaceTrim.spaceTrim((block) => `
|
|
4822
|
-
Joker not found in attempt ${
|
|
4885
|
+
Joker not found in attempt ${attemptIndex}
|
|
4823
4886
|
|
|
4824
4887
|
${block(pipelineIdentification)}
|
|
4825
4888
|
`));
|
|
@@ -5017,35 +5080,18 @@
|
|
|
5017
5080
|
}
|
|
5018
5081
|
}
|
|
5019
5082
|
// TODO: [๐] Unite object for expecting amount and format
|
|
5020
|
-
|
|
5021
|
-
|
|
5022
|
-
|
|
5023
|
-
|
|
5024
|
-
|
|
5025
|
-
|
|
5026
|
-
|
|
5027
|
-
|
|
5028
|
-
|
|
5029
|
-
throw new ExpectError(spaceTrim.spaceTrim((block) => `
|
|
5030
|
-
Expected valid JSON string
|
|
5031
|
-
|
|
5032
|
-
${block(
|
|
5033
|
-
/*<- Note: No need for `pipelineIdentification`, it will be catched and added later */ '')}
|
|
5034
|
-
`));
|
|
5035
|
-
}
|
|
5036
|
-
}
|
|
5037
|
-
}
|
|
5038
|
-
else {
|
|
5039
|
-
throw new UnexpectedError(spaceTrim.spaceTrim((block) => `
|
|
5040
|
-
Unknown format "${task.format}"
|
|
5041
|
-
|
|
5042
|
-
${block(pipelineIdentification)}
|
|
5043
|
-
`));
|
|
5083
|
+
// Use the common validation function for both format and expectations
|
|
5084
|
+
if (task.format || task.expectations) {
|
|
5085
|
+
const validationResult = validatePromptResult({
|
|
5086
|
+
resultString: $ongoingTaskResult.$resultString || '',
|
|
5087
|
+
expectations: task.expectations,
|
|
5088
|
+
format: task.format,
|
|
5089
|
+
});
|
|
5090
|
+
if (!validationResult.isValid) {
|
|
5091
|
+
throw validationResult.error;
|
|
5044
5092
|
}
|
|
5045
|
-
|
|
5046
|
-
|
|
5047
|
-
if (task.expectations) {
|
|
5048
|
-
checkExpectations(task.expectations, $ongoingTaskResult.$resultString || '');
|
|
5093
|
+
// Update the result string in case format processing modified it (e.g., JSON extraction)
|
|
5094
|
+
$ongoingTaskResult.$resultString = validationResult.processedResultString;
|
|
5049
5095
|
}
|
|
5050
5096
|
break attempts;
|
|
5051
5097
|
}
|
|
@@ -5054,6 +5100,15 @@
|
|
|
5054
5100
|
throw error;
|
|
5055
5101
|
}
|
|
5056
5102
|
$ongoingTaskResult.$expectError = error;
|
|
5103
|
+
// Store each failed attempt
|
|
5104
|
+
if (!Array.isArray($ongoingTaskResult.$failedResults)) {
|
|
5105
|
+
$ongoingTaskResult.$failedResults = [];
|
|
5106
|
+
}
|
|
5107
|
+
$ongoingTaskResult.$failedResults.push({
|
|
5108
|
+
attemptIndex,
|
|
5109
|
+
result: $ongoingTaskResult.$resultString,
|
|
5110
|
+
error: error,
|
|
5111
|
+
});
|
|
5057
5112
|
}
|
|
5058
5113
|
finally {
|
|
5059
5114
|
if (!isJokerAttempt &&
|
|
@@ -5075,35 +5130,41 @@
|
|
|
5075
5130
|
});
|
|
5076
5131
|
}
|
|
5077
5132
|
}
|
|
5078
|
-
if ($ongoingTaskResult.$expectError !== null &&
|
|
5133
|
+
if ($ongoingTaskResult.$expectError !== null && attemptIndex === maxAttempts - 1) {
|
|
5134
|
+
// Note: Create a summary of all failures
|
|
5135
|
+
const failuresSummary = $ongoingTaskResult.$failedResults
|
|
5136
|
+
.map((failure) => spaceTrim.spaceTrim((block) => {
|
|
5137
|
+
var _a, _b;
|
|
5138
|
+
return `
|
|
5139
|
+
Attempt ${failure.attemptIndex + 1}:
|
|
5140
|
+
Error ${((_a = failure.error) === null || _a === void 0 ? void 0 : _a.name) || ''}:
|
|
5141
|
+
${block((_b = failure.error) === null || _b === void 0 ? void 0 : _b.message.split('\n').map((line) => `> ${line}`).join('\n'))}
|
|
5142
|
+
|
|
5143
|
+
Result:
|
|
5144
|
+
${block(failure.result === null
|
|
5145
|
+
? 'null'
|
|
5146
|
+
: spaceTrim.spaceTrim(failure.result)
|
|
5147
|
+
.split('\n')
|
|
5148
|
+
.map((line) => `> ${line}`)
|
|
5149
|
+
.join('\n'))}
|
|
5150
|
+
`;
|
|
5151
|
+
}))
|
|
5152
|
+
.join('\n\n---\n\n');
|
|
5079
5153
|
throw new PipelineExecutionError(spaceTrim.spaceTrim((block) => {
|
|
5080
|
-
var _a
|
|
5154
|
+
var _a;
|
|
5081
5155
|
return `
|
|
5082
5156
|
LLM execution failed ${maxExecutionAttempts}x
|
|
5083
5157
|
|
|
5084
5158
|
${block(pipelineIdentification)}
|
|
5085
5159
|
|
|
5086
|
-
---
|
|
5087
5160
|
The Prompt:
|
|
5088
5161
|
${block((((_a = $ongoingTaskResult.$prompt) === null || _a === void 0 ? void 0 : _a.content) || '')
|
|
5089
5162
|
.split('\n')
|
|
5090
5163
|
.map((line) => `> ${line}`)
|
|
5091
5164
|
.join('\n'))}
|
|
5092
5165
|
|
|
5093
|
-
|
|
5094
|
-
${block(
|
|
5095
|
-
.split('\n')
|
|
5096
|
-
.map((line) => `> ${line}`)
|
|
5097
|
-
.join('\n'))}
|
|
5098
|
-
|
|
5099
|
-
Last result:
|
|
5100
|
-
${block($ongoingTaskResult.$resultString === null
|
|
5101
|
-
? 'null'
|
|
5102
|
-
: spaceTrim.spaceTrim($ongoingTaskResult.$resultString)
|
|
5103
|
-
.split('\n')
|
|
5104
|
-
.map((line) => `> ${line}`)
|
|
5105
|
-
.join('\n'))}
|
|
5106
|
-
---
|
|
5166
|
+
All Failed Attempts:
|
|
5167
|
+
${block(failuresSummary)}
|
|
5107
5168
|
`;
|
|
5108
5169
|
}));
|
|
5109
5170
|
}
|