New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More โ†’
Socket
Sign inDemoInstall
Socket

@promptbook/google

Package Overview
Dependencies
Maintainers
0
Versions
84
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@promptbook/google - npm Package Compare versions

Comparing version 0.78.0-0 to 0.78.2

esm/typings/src/errors/utils/getErrorReportUrl.d.ts

346

esm/index.es.js
import colors from 'colors';
import spaceTrim$1, { spaceTrim } from 'spacetrim';
import spaceTrim, { spaceTrim as spaceTrim$1 } from 'spacetrim';

@@ -16,3 +16,3 @@ // โš ๏ธ WARNING: This code has been generated so that any manual changes will be overwritten

*/
var PROMPTBOOK_ENGINE_VERSION = '0.77.1';
var PROMPTBOOK_ENGINE_VERSION = '0.78.1';
/**

@@ -270,2 +270,99 @@ * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine

/**
* Name for the Promptbook
*
* TODO: [๐Ÿ—ฝ] Unite branding and make single place for it
*
* @public exported from `@promptbook/core`
*/
var NAME = "Promptbook";
/**
* Email of the responsible person
*
* @public exported from `@promptbook/core`
*/
var ADMIN_EMAIL = 'me@pavolhejny.com';
/**
* Name of the responsible person for the Promptbook on GitHub
*
* @public exported from `@promptbook/core`
*/
var ADMIN_GITHUB_NAME = 'hejny';
// <- TODO: [๐Ÿง ] Better system for generator warnings - not always "code" and "by `@promptbook/cli`"
/**
* The maximum number of iterations for a loops
*
* @private within the repository - too low-level in comparison with other `MAX_...`
*/
var LOOP_LIMIT = 1000;
/**
* Nonce which is used for replacing things in strings
*
* @private within the repository
*/
var REPLACING_NONCE = 'u$k42k%!V2zo34w7Fu#@QUHYPW';
/**
* @@@
*
* @private within the repository
*/
var RESERVED_PARAMETER_MISSING_VALUE = 'MISSING-' + REPLACING_NONCE;
/**
* @@@
*
* @private within the repository
*/
var RESERVED_PARAMETER_RESTRICTED = 'RESTRICTED-' + REPLACING_NONCE;
// <- TODO: [๐Ÿงœโ€โ™‚๏ธ]
/**
* @@@
*
* @public exported from `@promptbook/core`
*/
Object.freeze({
delimiter: ',',
quoteChar: '"',
newline: '\n',
skipEmptyLines: true,
});
/**
* TODO: Extract `constants.ts` from `config.ts`
* Note: [๐Ÿ’ž] Ignore a discrepancy between file name and entity name
* TODO: [๐Ÿง ][๐Ÿงœโ€โ™‚๏ธ] Maybe join remoteUrl and path into single value
*/
/**
* This error type indicates that some limit was reached
*
* @public exported from `@promptbook/core`
*/
var LimitReachedError = /** @class */ (function (_super) {
__extends(LimitReachedError, _super);
function LimitReachedError(message) {
var _this = _super.call(this, message) || this;
_this.name = 'LimitReachedError';
Object.setPrototypeOf(_this, LimitReachedError.prototype);
return _this;
}
return LimitReachedError;
}(Error));
/**
* Make error report URL for the given error
*
* @private !!!!!!
*/
function getErrorReportUrl(error) {
var report = {
title: "\uD83D\uDC1C Error report from ".concat(NAME),
body: spaceTrim(function (block) { return "\n\n\n `".concat(error.name || 'Error', "` has occurred in the [").concat(NAME, "], please look into it @").concat(ADMIN_GITHUB_NAME, ".\n\n ```\n ").concat(block(error.message || '(no error message)'), "\n ```\n\n\n ## More info:\n\n - **Promptbook engine version:** ").concat(PROMPTBOOK_ENGINE_VERSION, "\n - **Book language version:** ").concat(BOOK_LANGUAGE_VERSION, "\n - **Time:** ").concat(new Date().toISOString(), "\n\n <details>\n <summary>Stack trace:</summary>\n\n ## Stack trace:\n\n ```stacktrace\n ").concat(block(error.stack || '(empty)'), "\n ```\n </details>\n\n "); }),
};
var reportUrl = new URL("https://github.com/webgptorg/promptbook/issues/new");
reportUrl.searchParams.set('labels', 'bug');
reportUrl.searchParams.set('assignees', ADMIN_GITHUB_NAME);
reportUrl.searchParams.set('title', report.title);
reportUrl.searchParams.set('body', report.body);
return reportUrl;
}
/**
* This error type indicates that the error should not happen and its last check before crashing with some other error

@@ -278,3 +375,3 @@ *

function UnexpectedError(message) {
var _this = _super.call(this, spaceTrim(function (block) { return "\n ".concat(block(message), "\n\n Note: This error should not happen.\n It's probbably a bug in the pipeline collection\n\n Please report issue:\n https://github.com/webgptorg/promptbook/issues\n\n Or contact us on me@pavolhejny.com\n\n "); })) || this;
var _this = _super.call(this, spaceTrim$1(function (block) { return "\n ".concat(block(message), "\n\n Note: This error should not happen.\n It's probbably a bug in the pipeline collection\n\n Please report issue:\n ").concat(block(getErrorReportUrl(new Error(message)).href), "\n\n Or contact us on ").concat(ADMIN_EMAIL, "\n\n "); })) || this;
_this.name = 'UnexpectedError';

@@ -288,2 +385,81 @@ Object.setPrototypeOf(_this, UnexpectedError.prototype);

/**
* Replaces parameters in template with values from parameters object
*
* @param template the template with parameters in {curly} braces
* @param parameters the object with parameters
* @returns the template with replaced parameters
* @throws {PipelineExecutionError} if parameter is not defined, not closed, or not opened
* @public exported from `@promptbook/utils`
*/
function replaceParameters(template, parameters) {
var e_1, _a;
try {
for (var _b = __values(Object.entries(parameters)), _c = _b.next(); !_c.done; _c = _b.next()) {
var _d = __read(_c.value, 2), parameterName = _d[0], parameterValue = _d[1];
if (parameterValue === RESERVED_PARAMETER_MISSING_VALUE) {
throw new UnexpectedError("Parameter `{".concat(parameterName, "}` has missing value"));
}
else if (parameterValue === RESERVED_PARAMETER_RESTRICTED) {
// TODO: [๐Ÿต]
throw new UnexpectedError("Parameter `{".concat(parameterName, "}` is restricted to use"));
}
}
}
catch (e_1_1) { e_1 = { error: e_1_1 }; }
finally {
try {
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
}
finally { if (e_1) throw e_1.error; }
}
var replacedTemplates = template;
var match;
var loopLimit = LOOP_LIMIT;
var _loop_1 = function () {
if (loopLimit-- < 0) {
throw new LimitReachedError('Loop limit reached during parameters replacement in `replaceParameters`');
}
var precol = match.groups.precol;
var parameterName = match.groups.parameterName;
if (parameterName === '') {
return "continue";
}
if (parameterName.indexOf('{') !== -1 || parameterName.indexOf('}') !== -1) {
throw new PipelineExecutionError('Parameter is already opened or not closed');
}
if (parameters[parameterName] === undefined) {
throw new PipelineExecutionError("Parameter `{".concat(parameterName, "}` is not defined"));
}
var parameterValue = parameters[parameterName];
if (parameterValue === undefined) {
throw new PipelineExecutionError("Parameter `{".concat(parameterName, "}` is not defined"));
}
parameterValue = parameterValue.toString();
if (parameterValue.includes('\n') && /^\s*\W{0,3}\s*$/.test(precol)) {
parameterValue = parameterValue
.split('\n')
.map(function (line, index) { return (index === 0 ? line : "".concat(precol).concat(line)); })
.join('\n');
}
replacedTemplates =
replacedTemplates.substring(0, match.index + precol.length) +
parameterValue +
replacedTemplates.substring(match.index + precol.length + parameterName.length + 2);
};
while ((match = /^(?<precol>.*){(?<parameterName>\w+)}(.*)/m /* <- Not global */
.exec(replacedTemplates))) {
_loop_1();
}
// [๐Ÿ’ซ] Check if there are parameters that are not closed properly
if (/{\w+$/.test(replacedTemplates)) {
throw new PipelineExecutionError('Parameter is not closed');
}
// [๐Ÿ’ซ] Check if there are parameters that are not opened properly
if (/^\w+}/.test(replacedTemplates)) {
throw new PipelineExecutionError('Parameter is not opened');
}
return replacedTemplates;
}
/**
* Checks if the value is [๐Ÿš‰] serializable as JSON

@@ -338,3 +514,3 @@ * If not, throws an UnexpectedError with a rich error message and tracking

if (value instanceof Date) {
throw new UnexpectedError(spaceTrim$1("\n ".concat(name, " is Date\n\n Use `string_date_iso8601` instead\n ")));
throw new UnexpectedError(spaceTrim("\n ".concat(name, " is Date\n\n Use `string_date_iso8601` instead\n ")));
}

@@ -351,3 +527,3 @@ else if (value instanceof Map) {

else if (value instanceof Error) {
throw new UnexpectedError(spaceTrim$1("\n ".concat(name, " is unserialized Error\n\n Use function `serializeError`\n ")));
throw new UnexpectedError(spaceTrim("\n ".concat(name, " is unserialized Error\n\n Use function `serializeError`\n ")));
}

@@ -379,3 +555,3 @@ else {

}
throw new UnexpectedError(spaceTrim$1(function (block) { return "\n ".concat(name, " is not serializable\n\n ").concat(block(error.toString()), "\n "); }));
throw new UnexpectedError(spaceTrim(function (block) { return "\n ".concat(name, " is not serializable\n\n ").concat(block(error.toString()), "\n "); }));
}

@@ -434,157 +610,3 @@ /*

// <- TODO: [๐Ÿง ] Better system for generator warnings - not always "code" and "by `@promptbook/cli`"
/**
* The maximum number of iterations for a loops
*
* @private within the repository - too low-level in comparison with other `MAX_...`
*/
var LOOP_LIMIT = 1000;
/**
* Nonce which is used for replacing things in strings
*
* @private within the repository
*/
var REPLACING_NONCE = 'u$k42k%!V2zo34w7Fu#@QUHYPW';
/**
* The names of the parameters that are reserved for special purposes
*
* @public exported from `@promptbook/core`
*/
$asDeeplyFrozenSerializableJson('RESERVED_PARAMETER_NAMES', [
'content',
'context',
'knowledge',
'examples',
'modelName',
'currentDate',
// <- TODO: list here all command names
// <- TODO: Add more like 'date', 'modelName',...
// <- TODO: Add [emoji] + instructions ACRY when adding new reserved parameter
]);
/**
* @@@
*
* @private within the repository
*/
var RESERVED_PARAMETER_MISSING_VALUE = 'MISSING-' + REPLACING_NONCE;
/**
* @@@
*
* @private within the repository
*/
var RESERVED_PARAMETER_RESTRICTED = 'RESTRICTED-' + REPLACING_NONCE;
// <- TODO: [๐Ÿงœโ€โ™‚๏ธ]
/**
* @@@
*
* @public exported from `@promptbook/core`
*/
Object.freeze({
delimiter: ',',
quoteChar: '"',
newline: '\n',
skipEmptyLines: true,
});
/**
* TODO: Extract `constants.ts` from `config.ts`
* Note: [๐Ÿ’ž] Ignore a discrepancy between file name and entity name
* TODO: [๐Ÿง ][๐Ÿงœโ€โ™‚๏ธ] Maybe join remoteUrl and path into single value
*/
/**
* This error type indicates that some limit was reached
*
* @public exported from `@promptbook/core`
*/
var LimitReachedError = /** @class */ (function (_super) {
__extends(LimitReachedError, _super);
function LimitReachedError(message) {
var _this = _super.call(this, message) || this;
_this.name = 'LimitReachedError';
Object.setPrototypeOf(_this, LimitReachedError.prototype);
return _this;
}
return LimitReachedError;
}(Error));
/**
* Replaces parameters in template with values from parameters object
*
* @param template the template with parameters in {curly} braces
* @param parameters the object with parameters
* @returns the template with replaced parameters
* @throws {PipelineExecutionError} if parameter is not defined, not closed, or not opened
* @public exported from `@promptbook/utils`
*/
function replaceParameters(template, parameters) {
var e_1, _a;
try {
for (var _b = __values(Object.entries(parameters)), _c = _b.next(); !_c.done; _c = _b.next()) {
var _d = __read(_c.value, 2), parameterName = _d[0], parameterValue = _d[1];
if (parameterValue === RESERVED_PARAMETER_MISSING_VALUE) {
throw new UnexpectedError("Parameter `{".concat(parameterName, "}` has missing value"));
}
else if (parameterValue === RESERVED_PARAMETER_RESTRICTED) {
// TODO: [๐Ÿต]
throw new UnexpectedError("Parameter `{".concat(parameterName, "}` is restricted to use"));
}
}
}
catch (e_1_1) { e_1 = { error: e_1_1 }; }
finally {
try {
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
}
finally { if (e_1) throw e_1.error; }
}
var replacedTemplates = template;
var match;
var loopLimit = LOOP_LIMIT;
var _loop_1 = function () {
if (loopLimit-- < 0) {
throw new LimitReachedError('Loop limit reached during parameters replacement in `replaceParameters`');
}
var precol = match.groups.precol;
var parameterName = match.groups.parameterName;
if (parameterName === '') {
return "continue";
}
if (parameterName.indexOf('{') !== -1 || parameterName.indexOf('}') !== -1) {
throw new PipelineExecutionError('Parameter is already opened or not closed');
}
if (parameters[parameterName] === undefined) {
throw new PipelineExecutionError("Parameter `{".concat(parameterName, "}` is not defined"));
}
var parameterValue = parameters[parameterName];
if (parameterValue === undefined) {
throw new PipelineExecutionError("Parameter `{".concat(parameterName, "}` is not defined"));
}
parameterValue = parameterValue.toString();
if (parameterValue.includes('\n') && /^\s*\W{0,3}\s*$/.test(precol)) {
parameterValue = parameterValue
.split('\n')
.map(function (line, index) { return (index === 0 ? line : "".concat(precol).concat(line)); })
.join('\n');
}
replacedTemplates =
replacedTemplates.substring(0, match.index + precol.length) +
parameterValue +
replacedTemplates.substring(match.index + precol.length + parameterName.length + 2);
};
while ((match = /^(?<precol>.*){(?<parameterName>\w+)}(.*)/m /* <- Not global */
.exec(replacedTemplates))) {
_loop_1();
}
// [๐Ÿ’ซ] Check if there are parameters that are not closed properly
if (/{\w+$/.test(replacedTemplates)) {
throw new PipelineExecutionError('Parameter is not closed');
}
// [๐Ÿ’ซ] Check if there are parameters that are not opened properly
if (/^\w+}/.test(replacedTemplates)) {
throw new PipelineExecutionError('Parameter is not opened');
}
return replacedTemplates;
}
/**
* Function `asSerializable` will convert values which are not serializable to serializable values

@@ -668,3 +690,3 @@ * It walks deeply through the object and converts all values

if (!modelName) {
throw new PipelineExecutionError(spaceTrim$1("\n Can not determine which model to use.\n\n You need to provide at least one of:\n 1) In `createExecutionToolsFromVercelProvider` options, provide `availableModels` with at least one model\n 2) In `prompt.modelRequirements`, provide `modelName` with the name of the model to use\n \n "));
throw new PipelineExecutionError(spaceTrim("\n Can not determine which model to use.\n\n You need to provide at least one of:\n 1) In `createExecutionToolsFromVercelProvider` options, provide `availableModels` with at least one model\n 2) In `prompt.modelRequirements`, provide `modelName` with the name of the model to use\n \n "));
}

@@ -800,3 +822,3 @@ return [4 /*yield*/, vercelProvider.chat(modelName, __assign({ user: (userId === null || userId === void 0 ? void 0 : userId.toString()) || undefined }, additionalChatSettings))];

function NotYetImplementedError(message) {
var _this = _super.call(this, spaceTrim(function (block) { return "\n ".concat(block(message), "\n\n Note: This feature is not implemented yet but it will be soon.\n\n If you want speed up the implementation or just read more, look here:\n https://github.com/webgptorg/promptbook\n\n Or contact us on me@pavolhejny.com\n\n "); })) || this;
var _this = _super.call(this, spaceTrim$1(function (block) { return "\n ".concat(block(message), "\n\n Note: This feature is not implemented yet but it will be soon.\n\n If you want speed up the implementation or just read more, look here:\n https://github.com/webgptorg/promptbook\n\n Or contact us on me@pavolhejny.com\n\n "); })) || this;
_this.name = 'NotYetImplementedError';

@@ -803,0 +825,0 @@ Object.setPrototypeOf(_this, NotYetImplementedError.prototype);

@@ -8,2 +8,4 @@ import { BOOK_LANGUAGE_VERSION, PROMPTBOOK_ENGINE_VERSION } from '../version';

import { NAME } from '../config';
import { ADMIN_EMAIL } from '../config';
import { ADMIN_GITHUB_NAME } from '../config';
import { CLAIM } from '../config';

@@ -127,2 +129,4 @@ import { LOGO_LIGHT_SRC } from '../config';

export { NAME };
export { ADMIN_EMAIL };
export { ADMIN_GITHUB_NAME };
export { CLAIM };

@@ -129,0 +133,0 @@ export { LOGO_LIGHT_SRC };

import type { CsvSettings } from './formats/csv/CsvSettings';
import type { IntermediateFilesStrategy } from './types/IntermediateFilesStrategy';
import type { string_email } from './types/typeAliases';
import type { string_name } from './types/typeAliases';
import type { string_url_image } from './types/typeAliases';

@@ -19,2 +21,14 @@ /**

/**
* Email of the responsible person
*
* @public exported from `@promptbook/core`
*/
export declare const ADMIN_EMAIL: string_email;
/**
* Name of the responsible person for the Promptbook on GitHub
*
* @public exported from `@promptbook/core`
*/
export declare const ADMIN_GITHUB_NAME: string_name;
/**
* Claim for the Promptbook

@@ -21,0 +35,0 @@ *

@@ -15,3 +15,3 @@ /**

/**
* TODO: Better validation or remove branded type and make it just string
* TODO: [๐Ÿ’ฉ] Better validation or remove branded type and make it just string
*/

@@ -27,3 +27,3 @@ import type { AvailableModel } from '../../execution/AvailableModel';

* @see /other/playground/playground.ts
* TODO: [๐Ÿ“] Make better
* TODO: [๐Ÿ“][๐Ÿ’ฉ] Make better
* TODO: Change model titles to human eg: "gpt-4-turbo-2024-04-09" -> "GPT-4 Turbo (2024-04-09)"

@@ -30,0 +30,0 @@ * TODO: [๐Ÿšธ] Not all models are compatible with JSON mode, add this information here and use it

@@ -11,3 +11,3 @@ /**

/**
* TODO: !! Better validation (validatePipelineString) or remove branded type and make it just string
* TODO: [๐Ÿ’ฉ] Better validation (validatePipelineString) or remove branded type and make it just string
*/
{
"name": "@promptbook/google",
"version": "0.78.0-0",
"version": "0.78.2",
"description": "It's time for a paradigm shift. The future of software in plain English, French or Latin",

@@ -57,3 +57,3 @@ "--note-0": " <- [๐ŸŠ]",

"peerDependencies": {
"@promptbook/core": "0.78.0-0"
"@promptbook/core": "0.78.2"
},

@@ -60,0 +60,0 @@ "dependencies": {

@@ -26,6 +26,2 @@ <!-- โš ๏ธ WARNING: This code has been generated so that any manual changes will be overwritten -->

<blockquote style="color: #ff8811">
<b>โš  Warning:</b> This is a pre-release version of the library. It is not yet ready for production use. Please look at <a href="https://www.npmjs.com/package/@promptbook/core?activeTab=versions">latest stable release</a>.
</blockquote>
## ๐Ÿ“ฆ Package `@promptbook/google`

@@ -32,0 +28,0 @@

@@ -24,3 +24,3 @@ (function (global, factory) {

*/
var PROMPTBOOK_ENGINE_VERSION = '0.77.1';
var PROMPTBOOK_ENGINE_VERSION = '0.78.1';
/**

@@ -278,2 +278,99 @@ * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine

/**
* Name for the Promptbook
*
* TODO: [๐Ÿ—ฝ] Unite branding and make single place for it
*
* @public exported from `@promptbook/core`
*/
var NAME = "Promptbook";
/**
* Email of the responsible person
*
* @public exported from `@promptbook/core`
*/
var ADMIN_EMAIL = 'me@pavolhejny.com';
/**
* Name of the responsible person for the Promptbook on GitHub
*
* @public exported from `@promptbook/core`
*/
var ADMIN_GITHUB_NAME = 'hejny';
// <- TODO: [๐Ÿง ] Better system for generator warnings - not always "code" and "by `@promptbook/cli`"
/**
* The maximum number of iterations for a loops
*
* @private within the repository - too low-level in comparison with other `MAX_...`
*/
var LOOP_LIMIT = 1000;
/**
* Nonce which is used for replacing things in strings
*
* @private within the repository
*/
var REPLACING_NONCE = 'u$k42k%!V2zo34w7Fu#@QUHYPW';
/**
* @@@
*
* @private within the repository
*/
var RESERVED_PARAMETER_MISSING_VALUE = 'MISSING-' + REPLACING_NONCE;
/**
* @@@
*
* @private within the repository
*/
var RESERVED_PARAMETER_RESTRICTED = 'RESTRICTED-' + REPLACING_NONCE;
// <- TODO: [๐Ÿงœโ€โ™‚๏ธ]
/**
* @@@
*
* @public exported from `@promptbook/core`
*/
Object.freeze({
delimiter: ',',
quoteChar: '"',
newline: '\n',
skipEmptyLines: true,
});
/**
* TODO: Extract `constants.ts` from `config.ts`
* Note: [๐Ÿ’ž] Ignore a discrepancy between file name and entity name
* TODO: [๐Ÿง ][๐Ÿงœโ€โ™‚๏ธ] Maybe join remoteUrl and path into single value
*/
/**
* This error type indicates that some limit was reached
*
* @public exported from `@promptbook/core`
*/
var LimitReachedError = /** @class */ (function (_super) {
__extends(LimitReachedError, _super);
function LimitReachedError(message) {
var _this = _super.call(this, message) || this;
_this.name = 'LimitReachedError';
Object.setPrototypeOf(_this, LimitReachedError.prototype);
return _this;
}
return LimitReachedError;
}(Error));
/**
* Make error report URL for the given error
*
* @private !!!!!!
*/
function getErrorReportUrl(error) {
var report = {
title: "\uD83D\uDC1C Error report from ".concat(NAME),
body: spaceTrim__default["default"](function (block) { return "\n\n\n `".concat(error.name || 'Error', "` has occurred in the [").concat(NAME, "], please look into it @").concat(ADMIN_GITHUB_NAME, ".\n\n ```\n ").concat(block(error.message || '(no error message)'), "\n ```\n\n\n ## More info:\n\n - **Promptbook engine version:** ").concat(PROMPTBOOK_ENGINE_VERSION, "\n - **Book language version:** ").concat(BOOK_LANGUAGE_VERSION, "\n - **Time:** ").concat(new Date().toISOString(), "\n\n <details>\n <summary>Stack trace:</summary>\n\n ## Stack trace:\n\n ```stacktrace\n ").concat(block(error.stack || '(empty)'), "\n ```\n </details>\n\n "); }),
};
var reportUrl = new URL("https://github.com/webgptorg/promptbook/issues/new");
reportUrl.searchParams.set('labels', 'bug');
reportUrl.searchParams.set('assignees', ADMIN_GITHUB_NAME);
reportUrl.searchParams.set('title', report.title);
reportUrl.searchParams.set('body', report.body);
return reportUrl;
}
/**
* This error type indicates that the error should not happen and its last check before crashing with some other error

@@ -286,3 +383,3 @@ *

function UnexpectedError(message) {
var _this = _super.call(this, spaceTrim.spaceTrim(function (block) { return "\n ".concat(block(message), "\n\n Note: This error should not happen.\n It's probbably a bug in the pipeline collection\n\n Please report issue:\n https://github.com/webgptorg/promptbook/issues\n\n Or contact us on me@pavolhejny.com\n\n "); })) || this;
var _this = _super.call(this, spaceTrim.spaceTrim(function (block) { return "\n ".concat(block(message), "\n\n Note: This error should not happen.\n It's probbably a bug in the pipeline collection\n\n Please report issue:\n ").concat(block(getErrorReportUrl(new Error(message)).href), "\n\n Or contact us on ").concat(ADMIN_EMAIL, "\n\n "); })) || this;
_this.name = 'UnexpectedError';

@@ -296,2 +393,81 @@ Object.setPrototypeOf(_this, UnexpectedError.prototype);

/**
* Replaces parameters in template with values from parameters object
*
* @param template the template with parameters in {curly} braces
* @param parameters the object with parameters
* @returns the template with replaced parameters
* @throws {PipelineExecutionError} if parameter is not defined, not closed, or not opened
* @public exported from `@promptbook/utils`
*/
function replaceParameters(template, parameters) {
var e_1, _a;
try {
for (var _b = __values(Object.entries(parameters)), _c = _b.next(); !_c.done; _c = _b.next()) {
var _d = __read(_c.value, 2), parameterName = _d[0], parameterValue = _d[1];
if (parameterValue === RESERVED_PARAMETER_MISSING_VALUE) {
throw new UnexpectedError("Parameter `{".concat(parameterName, "}` has missing value"));
}
else if (parameterValue === RESERVED_PARAMETER_RESTRICTED) {
// TODO: [๐Ÿต]
throw new UnexpectedError("Parameter `{".concat(parameterName, "}` is restricted to use"));
}
}
}
catch (e_1_1) { e_1 = { error: e_1_1 }; }
finally {
try {
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
}
finally { if (e_1) throw e_1.error; }
}
var replacedTemplates = template;
var match;
var loopLimit = LOOP_LIMIT;
var _loop_1 = function () {
if (loopLimit-- < 0) {
throw new LimitReachedError('Loop limit reached during parameters replacement in `replaceParameters`');
}
var precol = match.groups.precol;
var parameterName = match.groups.parameterName;
if (parameterName === '') {
return "continue";
}
if (parameterName.indexOf('{') !== -1 || parameterName.indexOf('}') !== -1) {
throw new PipelineExecutionError('Parameter is already opened or not closed');
}
if (parameters[parameterName] === undefined) {
throw new PipelineExecutionError("Parameter `{".concat(parameterName, "}` is not defined"));
}
var parameterValue = parameters[parameterName];
if (parameterValue === undefined) {
throw new PipelineExecutionError("Parameter `{".concat(parameterName, "}` is not defined"));
}
parameterValue = parameterValue.toString();
if (parameterValue.includes('\n') && /^\s*\W{0,3}\s*$/.test(precol)) {
parameterValue = parameterValue
.split('\n')
.map(function (line, index) { return (index === 0 ? line : "".concat(precol).concat(line)); })
.join('\n');
}
replacedTemplates =
replacedTemplates.substring(0, match.index + precol.length) +
parameterValue +
replacedTemplates.substring(match.index + precol.length + parameterName.length + 2);
};
while ((match = /^(?<precol>.*){(?<parameterName>\w+)}(.*)/m /* <- Not global */
.exec(replacedTemplates))) {
_loop_1();
}
// [๐Ÿ’ซ] Check if there are parameters that are not closed properly
if (/{\w+$/.test(replacedTemplates)) {
throw new PipelineExecutionError('Parameter is not closed');
}
// [๐Ÿ’ซ] Check if there are parameters that are not opened properly
if (/^\w+}/.test(replacedTemplates)) {
throw new PipelineExecutionError('Parameter is not opened');
}
return replacedTemplates;
}
/**
* Checks if the value is [๐Ÿš‰] serializable as JSON

@@ -439,157 +615,3 @@ * If not, throws an UnexpectedError with a rich error message and tracking

// <- TODO: [๐Ÿง ] Better system for generator warnings - not always "code" and "by `@promptbook/cli`"
/**
* The maximum number of iterations for a loops
*
* @private within the repository - too low-level in comparison with other `MAX_...`
*/
var LOOP_LIMIT = 1000;
/**
* Nonce which is used for replacing things in strings
*
* @private within the repository
*/
var REPLACING_NONCE = 'u$k42k%!V2zo34w7Fu#@QUHYPW';
/**
* The names of the parameters that are reserved for special purposes
*
* @public exported from `@promptbook/core`
*/
$asDeeplyFrozenSerializableJson('RESERVED_PARAMETER_NAMES', [
'content',
'context',
'knowledge',
'examples',
'modelName',
'currentDate',
// <- TODO: list here all command names
// <- TODO: Add more like 'date', 'modelName',...
// <- TODO: Add [emoji] + instructions ACRY when adding new reserved parameter
]);
/**
* @@@
*
* @private within the repository
*/
var RESERVED_PARAMETER_MISSING_VALUE = 'MISSING-' + REPLACING_NONCE;
/**
* @@@
*
* @private within the repository
*/
var RESERVED_PARAMETER_RESTRICTED = 'RESTRICTED-' + REPLACING_NONCE;
// <- TODO: [๐Ÿงœโ€โ™‚๏ธ]
/**
* @@@
*
* @public exported from `@promptbook/core`
*/
Object.freeze({
delimiter: ',',
quoteChar: '"',
newline: '\n',
skipEmptyLines: true,
});
/**
* TODO: Extract `constants.ts` from `config.ts`
* Note: [๐Ÿ’ž] Ignore a discrepancy between file name and entity name
* TODO: [๐Ÿง ][๐Ÿงœโ€โ™‚๏ธ] Maybe join remoteUrl and path into single value
*/
/**
* This error type indicates that some limit was reached
*
* @public exported from `@promptbook/core`
*/
var LimitReachedError = /** @class */ (function (_super) {
__extends(LimitReachedError, _super);
function LimitReachedError(message) {
var _this = _super.call(this, message) || this;
_this.name = 'LimitReachedError';
Object.setPrototypeOf(_this, LimitReachedError.prototype);
return _this;
}
return LimitReachedError;
}(Error));
/**
* Replaces parameters in template with values from parameters object
*
* @param template the template with parameters in {curly} braces
* @param parameters the object with parameters
* @returns the template with replaced parameters
* @throws {PipelineExecutionError} if parameter is not defined, not closed, or not opened
* @public exported from `@promptbook/utils`
*/
function replaceParameters(template, parameters) {
var e_1, _a;
try {
for (var _b = __values(Object.entries(parameters)), _c = _b.next(); !_c.done; _c = _b.next()) {
var _d = __read(_c.value, 2), parameterName = _d[0], parameterValue = _d[1];
if (parameterValue === RESERVED_PARAMETER_MISSING_VALUE) {
throw new UnexpectedError("Parameter `{".concat(parameterName, "}` has missing value"));
}
else if (parameterValue === RESERVED_PARAMETER_RESTRICTED) {
// TODO: [๐Ÿต]
throw new UnexpectedError("Parameter `{".concat(parameterName, "}` is restricted to use"));
}
}
}
catch (e_1_1) { e_1 = { error: e_1_1 }; }
finally {
try {
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
}
finally { if (e_1) throw e_1.error; }
}
var replacedTemplates = template;
var match;
var loopLimit = LOOP_LIMIT;
var _loop_1 = function () {
if (loopLimit-- < 0) {
throw new LimitReachedError('Loop limit reached during parameters replacement in `replaceParameters`');
}
var precol = match.groups.precol;
var parameterName = match.groups.parameterName;
if (parameterName === '') {
return "continue";
}
if (parameterName.indexOf('{') !== -1 || parameterName.indexOf('}') !== -1) {
throw new PipelineExecutionError('Parameter is already opened or not closed');
}
if (parameters[parameterName] === undefined) {
throw new PipelineExecutionError("Parameter `{".concat(parameterName, "}` is not defined"));
}
var parameterValue = parameters[parameterName];
if (parameterValue === undefined) {
throw new PipelineExecutionError("Parameter `{".concat(parameterName, "}` is not defined"));
}
parameterValue = parameterValue.toString();
if (parameterValue.includes('\n') && /^\s*\W{0,3}\s*$/.test(precol)) {
parameterValue = parameterValue
.split('\n')
.map(function (line, index) { return (index === 0 ? line : "".concat(precol).concat(line)); })
.join('\n');
}
replacedTemplates =
replacedTemplates.substring(0, match.index + precol.length) +
parameterValue +
replacedTemplates.substring(match.index + precol.length + parameterName.length + 2);
};
while ((match = /^(?<precol>.*){(?<parameterName>\w+)}(.*)/m /* <- Not global */
.exec(replacedTemplates))) {
_loop_1();
}
// [๐Ÿ’ซ] Check if there are parameters that are not closed properly
if (/{\w+$/.test(replacedTemplates)) {
throw new PipelineExecutionError('Parameter is not closed');
}
// [๐Ÿ’ซ] Check if there are parameters that are not opened properly
if (/^\w+}/.test(replacedTemplates)) {
throw new PipelineExecutionError('Parameter is not opened');
}
return replacedTemplates;
}
/**
* Function `asSerializable` will convert values which are not serializable to serializable values

@@ -596,0 +618,0 @@ * It walks deeply through the object and converts all values

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with โšก๏ธ by Socket Inc