@promptbook/core 0.104.0 โ 0.105.0-0
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 +4 -0
- package/esm/index.es.js +269 -114
- package/esm/index.es.js.map +1 -1
- package/esm/typings/src/_packages/core.index.d.ts +2 -0
- package/esm/typings/src/book-2.0/agent-source/AgentModelRequirements.d.ts +4 -0
- package/esm/typings/src/book-components/Chat/types/ChatMessage.d.ts +17 -0
- package/esm/typings/src/commitments/IMPORT/IMPORT.d.ts +34 -0
- package/esm/typings/src/commitments/index.d.ts +2 -1
- package/esm/typings/src/config.d.ts +6 -0
- package/esm/typings/src/errors/utils/deserializeError.d.ts +1 -1
- package/esm/typings/src/execution/PromptResult.d.ts +24 -1
- package/esm/typings/src/llm-providers/openai/OpenAiCompatibleExecutionToolsOptions.d.ts +5 -0
- package/esm/typings/src/types/LlmToolDefinition.d.ts +8 -1
- package/esm/typings/src/types/Prompt.d.ts +13 -0
- package/esm/typings/src/utils/misc/parseNumber.d.ts +1 -1
- package/esm/typings/src/version.d.ts +1 -1
- package/package.json +1 -1
- package/umd/index.umd.js +269 -113
- package/umd/index.umd.js.map +1 -1
package/README.md
CHANGED
|
@@ -27,6 +27,10 @@ Turn your company's scattered knowledge into AI ready Books
|
|
|
27
27
|
|
|
28
28
|
|
|
29
29
|
|
|
30
|
+
<blockquote style="color: #ff8811">
|
|
31
|
+
<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>.
|
|
32
|
+
</blockquote>
|
|
33
|
+
|
|
30
34
|
## ๐ฆ Package `@promptbook/core`
|
|
31
35
|
|
|
32
36
|
- Promptbooks are [divided into several](#-packages) packages, all are published from [single monorepo](https://github.com/webgptorg/promptbook).
|
package/esm/index.es.js
CHANGED
|
@@ -27,7 +27,7 @@ const BOOK_LANGUAGE_VERSION = '2.0.0';
|
|
|
27
27
|
* @generated
|
|
28
28
|
* @see https://github.com/webgptorg/promptbook
|
|
29
29
|
*/
|
|
30
|
-
const PROMPTBOOK_ENGINE_VERSION = '0.
|
|
30
|
+
const PROMPTBOOK_ENGINE_VERSION = '0.105.0-0';
|
|
31
31
|
/**
|
|
32
32
|
* TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
|
|
33
33
|
* Note: [๐] Ignore a discrepancy between file name and entity name
|
|
@@ -1124,6 +1124,12 @@ const DEFAULT_INTERMEDIATE_FILES_STRATEGY = 'HIDE_AND_KEEP';
|
|
|
1124
1124
|
* @public exported from `@promptbook/core`
|
|
1125
1125
|
*/
|
|
1126
1126
|
const DEFAULT_MAX_PARALLEL_COUNT = 5; // <- TODO: [๐คนโโ๏ธ]
|
|
1127
|
+
/**
|
|
1128
|
+
* The maximum depth to which recursion can occur
|
|
1129
|
+
*
|
|
1130
|
+
* @public exported from `@promptbook/core`
|
|
1131
|
+
*/
|
|
1132
|
+
const DEFAULT_MAX_RECURSION = 10;
|
|
1127
1133
|
/**
|
|
1128
1134
|
* The maximum number of attempts to execute LLM task before giving up
|
|
1129
1135
|
*
|
|
@@ -3235,7 +3241,7 @@ function jsonStringsToJsons(object) {
|
|
|
3235
3241
|
*
|
|
3236
3242
|
* @public exported from `@promptbook/utils`
|
|
3237
3243
|
*/
|
|
3238
|
-
function deserializeError(error) {
|
|
3244
|
+
function deserializeError(error, isStackAddedToMessage = true) {
|
|
3239
3245
|
const { name, stack, id } = error; // Added id
|
|
3240
3246
|
let { message } = error;
|
|
3241
3247
|
let ErrorClass = ALL_ERRORS[error.name];
|
|
@@ -3243,7 +3249,7 @@ function deserializeError(error) {
|
|
|
3243
3249
|
ErrorClass = Error;
|
|
3244
3250
|
message = `${name}: ${message}`;
|
|
3245
3251
|
}
|
|
3246
|
-
if (stack !== undefined && stack !== '') {
|
|
3252
|
+
if (isStackAddedToMessage && stack !== undefined && stack !== '') {
|
|
3247
3253
|
message = spaceTrim$2((block) => `
|
|
3248
3254
|
${block(message)}
|
|
3249
3255
|
|
|
@@ -8473,6 +8479,9 @@ function $getCurrentDate() {
|
|
|
8473
8479
|
* @public exported from `@promptbook/utils`
|
|
8474
8480
|
*/
|
|
8475
8481
|
function parseNumber(value) {
|
|
8482
|
+
if (value === null || value === undefined) {
|
|
8483
|
+
return 0;
|
|
8484
|
+
}
|
|
8476
8485
|
const originalValue = value;
|
|
8477
8486
|
if (typeof value === 'number') {
|
|
8478
8487
|
value = value.toString(); // <- TODO: Maybe more efficient way to do this
|
|
@@ -8699,6 +8708,79 @@ class FromCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
8699
8708
|
* Note: [๐] Ignore a discrepancy between file name and entity name
|
|
8700
8709
|
*/
|
|
8701
8710
|
|
|
8711
|
+
/**
|
|
8712
|
+
* IMPORT commitment definition
|
|
8713
|
+
*
|
|
8714
|
+
* The IMPORT commitment tells the agent to import content from another agent at the current location.
|
|
8715
|
+
*
|
|
8716
|
+
* Example usage in agent source:
|
|
8717
|
+
*
|
|
8718
|
+
* ```book
|
|
8719
|
+
* IMPORT https://s6.ptbk.io/benjamin-white
|
|
8720
|
+
* ```
|
|
8721
|
+
*
|
|
8722
|
+
* @private [๐ช] Maybe export the commitments through some package
|
|
8723
|
+
*/
|
|
8724
|
+
class ImportCommitmentDefinition extends BaseCommitmentDefinition {
|
|
8725
|
+
constructor(type = 'IMPORT') {
|
|
8726
|
+
super(type);
|
|
8727
|
+
}
|
|
8728
|
+
/**
|
|
8729
|
+
* Short one-line description of IMPORT.
|
|
8730
|
+
*/
|
|
8731
|
+
get description() {
|
|
8732
|
+
return 'Import content from another agent.';
|
|
8733
|
+
}
|
|
8734
|
+
/**
|
|
8735
|
+
* Icon for this commitment.
|
|
8736
|
+
*/
|
|
8737
|
+
get icon() {
|
|
8738
|
+
return '๐ฅ';
|
|
8739
|
+
}
|
|
8740
|
+
/**
|
|
8741
|
+
* Markdown documentation for IMPORT commitment.
|
|
8742
|
+
*/
|
|
8743
|
+
get documentation() {
|
|
8744
|
+
return spaceTrim$1(`
|
|
8745
|
+
# ${this.type}
|
|
8746
|
+
|
|
8747
|
+
Imports content from another agent at the location of the commitment.
|
|
8748
|
+
|
|
8749
|
+
## Examples
|
|
8750
|
+
|
|
8751
|
+
\`\`\`book
|
|
8752
|
+
My AI Agent
|
|
8753
|
+
|
|
8754
|
+
IMPORT https://s6.ptbk.io/benjamin-white
|
|
8755
|
+
RULE Speak only in English.
|
|
8756
|
+
\`\`\`
|
|
8757
|
+
`);
|
|
8758
|
+
}
|
|
8759
|
+
applyToAgentModelRequirements(requirements, content) {
|
|
8760
|
+
const trimmedContent = content.trim();
|
|
8761
|
+
if (!trimmedContent) {
|
|
8762
|
+
return requirements;
|
|
8763
|
+
}
|
|
8764
|
+
if (!isValidAgentUrl(trimmedContent)) {
|
|
8765
|
+
throw new Error(spaceTrim$1((block) => `
|
|
8766
|
+
Invalid agent URL in IMPORT commitment: "${trimmedContent}"
|
|
8767
|
+
|
|
8768
|
+
\`\`\`book
|
|
8769
|
+
${block(content)}
|
|
8770
|
+
\`\`\`
|
|
8771
|
+
`));
|
|
8772
|
+
}
|
|
8773
|
+
const importedAgentUrl = trimmedContent;
|
|
8774
|
+
return {
|
|
8775
|
+
...requirements,
|
|
8776
|
+
importedAgentUrls: [...(requirements.importedAgentUrls || []), importedAgentUrl],
|
|
8777
|
+
};
|
|
8778
|
+
}
|
|
8779
|
+
}
|
|
8780
|
+
/**
|
|
8781
|
+
* Note: [๐] Ignore a discrepancy between file name and entity name
|
|
8782
|
+
*/
|
|
8783
|
+
|
|
8702
8784
|
/**
|
|
8703
8785
|
* GOAL commitment definition
|
|
8704
8786
|
*
|
|
@@ -11060,7 +11142,7 @@ class UseBrowserCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
11060
11142
|
// Add 'web_browser' to tools if not already present
|
|
11061
11143
|
const updatedTools = existingTools.some((tool) => tool.name === 'web_browser')
|
|
11062
11144
|
? existingTools
|
|
11063
|
-
: [
|
|
11145
|
+
: ([
|
|
11064
11146
|
// TODO: [๐ฐ] Use through proper MCP server
|
|
11065
11147
|
...existingTools,
|
|
11066
11148
|
{
|
|
@@ -11080,7 +11162,7 @@ class UseBrowserCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
11080
11162
|
required: ['url'],
|
|
11081
11163
|
},
|
|
11082
11164
|
},
|
|
11083
|
-
];
|
|
11165
|
+
]);
|
|
11084
11166
|
// Return requirements with updated tools and metadata
|
|
11085
11167
|
return {
|
|
11086
11168
|
...requirements,
|
|
@@ -11382,6 +11464,8 @@ const COMMITMENT_REGISTRY = [
|
|
|
11382
11464
|
new FormatCommitmentDefinition('FORMAT'),
|
|
11383
11465
|
new FormatCommitmentDefinition('FORMATS'),
|
|
11384
11466
|
new FromCommitmentDefinition('FROM'),
|
|
11467
|
+
new ImportCommitmentDefinition('IMPORT'),
|
|
11468
|
+
new ImportCommitmentDefinition('IMPORTS'),
|
|
11385
11469
|
new ModelCommitmentDefinition('MODEL'),
|
|
11386
11470
|
new ModelCommitmentDefinition('MODELS'),
|
|
11387
11471
|
new ActionCommitmentDefinition('ACTION'),
|
|
@@ -18302,83 +18386,180 @@ class OpenAiCompatibleExecutionTools {
|
|
|
18302
18386
|
content: msg.content,
|
|
18303
18387
|
}));
|
|
18304
18388
|
}
|
|
18305
|
-
const
|
|
18306
|
-
...
|
|
18307
|
-
|
|
18308
|
-
|
|
18309
|
-
|
|
18310
|
-
|
|
18311
|
-
|
|
18312
|
-
|
|
18313
|
-
|
|
18314
|
-
|
|
18315
|
-
|
|
18316
|
-
|
|
18317
|
-
|
|
18318
|
-
|
|
18319
|
-
|
|
18320
|
-
|
|
18321
|
-
|
|
18322
|
-
|
|
18323
|
-
|
|
18324
|
-
|
|
18325
|
-
:
|
|
18389
|
+
const messages = [
|
|
18390
|
+
...(currentModelRequirements.systemMessage === undefined
|
|
18391
|
+
? []
|
|
18392
|
+
: [
|
|
18393
|
+
{
|
|
18394
|
+
role: 'system',
|
|
18395
|
+
content: currentModelRequirements.systemMessage,
|
|
18396
|
+
},
|
|
18397
|
+
]),
|
|
18398
|
+
...threadMessages,
|
|
18399
|
+
{
|
|
18400
|
+
role: 'user',
|
|
18401
|
+
content: rawPromptContent,
|
|
18402
|
+
},
|
|
18403
|
+
];
|
|
18404
|
+
let totalUsage = {
|
|
18405
|
+
price: uncertainNumber(0),
|
|
18406
|
+
input: {
|
|
18407
|
+
tokensCount: uncertainNumber(0),
|
|
18408
|
+
charactersCount: uncertainNumber(0),
|
|
18409
|
+
wordsCount: uncertainNumber(0),
|
|
18410
|
+
sentencesCount: uncertainNumber(0),
|
|
18411
|
+
linesCount: uncertainNumber(0),
|
|
18412
|
+
paragraphsCount: uncertainNumber(0),
|
|
18413
|
+
pagesCount: uncertainNumber(0),
|
|
18414
|
+
},
|
|
18415
|
+
output: {
|
|
18416
|
+
tokensCount: uncertainNumber(0),
|
|
18417
|
+
charactersCount: uncertainNumber(0),
|
|
18418
|
+
wordsCount: uncertainNumber(0),
|
|
18419
|
+
sentencesCount: uncertainNumber(0),
|
|
18420
|
+
linesCount: uncertainNumber(0),
|
|
18421
|
+
paragraphsCount: uncertainNumber(0),
|
|
18422
|
+
pagesCount: uncertainNumber(0),
|
|
18423
|
+
},
|
|
18326
18424
|
};
|
|
18425
|
+
const toolCalls = [];
|
|
18327
18426
|
const start = $getCurrentDate();
|
|
18328
|
-
|
|
18329
|
-
|
|
18330
|
-
|
|
18331
|
-
|
|
18332
|
-
|
|
18333
|
-
|
|
18334
|
-
.
|
|
18335
|
-
|
|
18336
|
-
|
|
18337
|
-
console.info(colors.bgRed('error'), error);
|
|
18338
|
-
}
|
|
18339
|
-
throw error;
|
|
18340
|
-
});
|
|
18427
|
+
const tools = 'tools' in prompt && Array.isArray(prompt.tools) ? prompt.tools : currentModelRequirements.tools;
|
|
18428
|
+
let isLooping = true;
|
|
18429
|
+
while (isLooping) {
|
|
18430
|
+
const rawRequest = {
|
|
18431
|
+
...modelSettings,
|
|
18432
|
+
messages,
|
|
18433
|
+
user: (_a = this.options.userId) === null || _a === void 0 ? void 0 : _a.toString(),
|
|
18434
|
+
tools: tools === undefined ? undefined : mapToolsToOpenAi(tools),
|
|
18435
|
+
};
|
|
18341
18436
|
if (this.options.isVerbose) {
|
|
18342
|
-
console.info(colors.bgWhite('
|
|
18343
|
-
}
|
|
18344
|
-
const complete = $getCurrentDate();
|
|
18345
|
-
if (!rawResponse.choices[0]) {
|
|
18346
|
-
throw new PipelineExecutionError(`No choises from ${this.title}`);
|
|
18347
|
-
}
|
|
18348
|
-
if (rawResponse.choices.length > 1) {
|
|
18349
|
-
// TODO: This should be maybe only warning
|
|
18350
|
-
throw new PipelineExecutionError(`More than one choise from ${this.title}`);
|
|
18351
|
-
}
|
|
18352
|
-
const resultContent = rawResponse.choices[0].message.content;
|
|
18353
|
-
const usage = this.computeUsage(content || '', resultContent || '', rawResponse);
|
|
18354
|
-
if (resultContent === null) {
|
|
18355
|
-
throw new PipelineExecutionError(`No response message from ${this.title}`);
|
|
18437
|
+
console.info(colors.bgWhite('rawRequest'), JSON.stringify(rawRequest, null, 4));
|
|
18356
18438
|
}
|
|
18357
|
-
|
|
18358
|
-
|
|
18359
|
-
|
|
18360
|
-
|
|
18361
|
-
|
|
18362
|
-
|
|
18363
|
-
|
|
18364
|
-
|
|
18365
|
-
|
|
18366
|
-
|
|
18439
|
+
try {
|
|
18440
|
+
const rawResponse = await this.limiter
|
|
18441
|
+
.schedule(() => this.makeRequestWithNetworkRetry(() => client.chat.completions.create(rawRequest)))
|
|
18442
|
+
.catch((error) => {
|
|
18443
|
+
assertsError(error);
|
|
18444
|
+
if (this.options.isVerbose) {
|
|
18445
|
+
console.info(colors.bgRed('error'), error);
|
|
18446
|
+
}
|
|
18447
|
+
throw error;
|
|
18448
|
+
});
|
|
18449
|
+
if (this.options.isVerbose) {
|
|
18450
|
+
console.info(colors.bgWhite('rawResponse'), JSON.stringify(rawResponse, null, 4));
|
|
18451
|
+
}
|
|
18452
|
+
if (!rawResponse.choices[0]) {
|
|
18453
|
+
throw new PipelineExecutionError(`No choises from ${this.title}`);
|
|
18454
|
+
}
|
|
18455
|
+
const responseMessage = rawResponse.choices[0].message;
|
|
18456
|
+
messages.push(responseMessage);
|
|
18457
|
+
const usage = this.computeUsage(content || '', responseMessage.content || '', rawResponse);
|
|
18458
|
+
totalUsage = addUsage(totalUsage, usage);
|
|
18459
|
+
if (responseMessage.tool_calls && responseMessage.tool_calls.length > 0) {
|
|
18460
|
+
await forEachAsync(responseMessage.tool_calls, {}, async (toolCall) => {
|
|
18461
|
+
const functionName = toolCall.function.name;
|
|
18462
|
+
const functionArgs = toolCall.function.arguments;
|
|
18463
|
+
const executionTools = this.options
|
|
18464
|
+
.executionTools;
|
|
18465
|
+
if (!executionTools || !executionTools.script) {
|
|
18466
|
+
throw new PipelineExecutionError(`Model requested tool '${functionName}' but no executionTools.script were provided in OpenAiCompatibleExecutionTools options`);
|
|
18467
|
+
}
|
|
18468
|
+
// TODO: [DRY] Use some common tool caller
|
|
18469
|
+
const scriptTools = Array.isArray(executionTools.script)
|
|
18470
|
+
? executionTools.script
|
|
18471
|
+
: [executionTools.script];
|
|
18472
|
+
let functionResponse;
|
|
18473
|
+
try {
|
|
18474
|
+
const scriptTool = scriptTools[0]; // <- TODO: [๐ง ] Which script tool to use?
|
|
18475
|
+
functionResponse = await scriptTool.execute({
|
|
18476
|
+
scriptLanguage: 'javascript',
|
|
18477
|
+
script: `
|
|
18478
|
+
const args = ${functionArgs};
|
|
18479
|
+
return await ${functionName}(args);
|
|
18480
|
+
`,
|
|
18481
|
+
parameters: {}, // <- TODO: [๐ง ] What parameters to pass?
|
|
18482
|
+
});
|
|
18483
|
+
}
|
|
18484
|
+
catch (error) {
|
|
18485
|
+
assertsError(error);
|
|
18486
|
+
functionResponse = `Error: ${error.message}`;
|
|
18487
|
+
}
|
|
18488
|
+
messages.push({
|
|
18489
|
+
role: 'tool',
|
|
18490
|
+
tool_call_id: toolCall.id,
|
|
18491
|
+
content: functionResponse,
|
|
18492
|
+
});
|
|
18493
|
+
toolCalls.push({
|
|
18494
|
+
name: functionName,
|
|
18495
|
+
arguments: functionArgs,
|
|
18496
|
+
result: functionResponse,
|
|
18497
|
+
rawToolCall: toolCall,
|
|
18498
|
+
});
|
|
18499
|
+
});
|
|
18500
|
+
continue;
|
|
18501
|
+
}
|
|
18502
|
+
const complete = $getCurrentDate();
|
|
18503
|
+
const resultContent = responseMessage.content;
|
|
18504
|
+
if (resultContent === null) {
|
|
18505
|
+
throw new PipelineExecutionError(`No response message from ${this.title}`);
|
|
18506
|
+
}
|
|
18507
|
+
isLooping = false;
|
|
18508
|
+
return exportJson({
|
|
18509
|
+
name: 'promptResult',
|
|
18510
|
+
message: `Result of \`OpenAiCompatibleExecutionTools.callChatModel\``,
|
|
18511
|
+
order: [],
|
|
18512
|
+
value: {
|
|
18513
|
+
content: resultContent,
|
|
18514
|
+
modelName: rawResponse.model || modelName,
|
|
18515
|
+
timing: {
|
|
18516
|
+
start,
|
|
18517
|
+
complete,
|
|
18518
|
+
},
|
|
18519
|
+
usage: totalUsage,
|
|
18520
|
+
toolCalls,
|
|
18521
|
+
rawPromptContent,
|
|
18522
|
+
rawRequest,
|
|
18523
|
+
rawResponse,
|
|
18367
18524
|
},
|
|
18368
|
-
|
|
18369
|
-
|
|
18370
|
-
|
|
18371
|
-
|
|
18372
|
-
|
|
18373
|
-
|
|
18374
|
-
|
|
18375
|
-
|
|
18376
|
-
|
|
18377
|
-
|
|
18378
|
-
|
|
18379
|
-
|
|
18380
|
-
|
|
18381
|
-
|
|
18525
|
+
});
|
|
18526
|
+
}
|
|
18527
|
+
catch (error) {
|
|
18528
|
+
isLooping = false;
|
|
18529
|
+
assertsError(error);
|
|
18530
|
+
// Check if this is an unsupported parameter error
|
|
18531
|
+
if (!isUnsupportedParameterError(error)) {
|
|
18532
|
+
// If we have attemptStack, include it in the error message
|
|
18533
|
+
if (attemptStack.length > 0) {
|
|
18534
|
+
throw new PipelineExecutionError(`All attempts failed. Attempt history:\n` +
|
|
18535
|
+
attemptStack
|
|
18536
|
+
.map((a, i) => ` ${i + 1}. Model: ${a.modelName}` +
|
|
18537
|
+
(a.unsupportedParameter ? `, Stripped: ${a.unsupportedParameter}` : '') +
|
|
18538
|
+
`, Error: ${a.errorMessage}` +
|
|
18539
|
+
(a.stripped ? ' (stripped and retried)' : ''))
|
|
18540
|
+
.join('\n') +
|
|
18541
|
+
`\nFinal error: ${error.message}`);
|
|
18542
|
+
}
|
|
18543
|
+
throw error;
|
|
18544
|
+
}
|
|
18545
|
+
// Parse which parameter is unsupported
|
|
18546
|
+
const unsupportedParameter = parseUnsupportedParameterError(error.message);
|
|
18547
|
+
if (!unsupportedParameter) {
|
|
18548
|
+
if (this.options.isVerbose) {
|
|
18549
|
+
console.warn(colors.bgYellow('Warning'), 'Could not parse unsupported parameter from error:', error.message);
|
|
18550
|
+
}
|
|
18551
|
+
throw error;
|
|
18552
|
+
}
|
|
18553
|
+
// Create a unique key for this model + parameter combination to prevent infinite loops
|
|
18554
|
+
const retryKey = `${modelName}-${unsupportedParameter}`;
|
|
18555
|
+
if (retriedUnsupportedParameters.has(retryKey)) {
|
|
18556
|
+
// Already retried this parameter, throw the error with attemptStack
|
|
18557
|
+
attemptStack.push({
|
|
18558
|
+
modelName,
|
|
18559
|
+
unsupportedParameter,
|
|
18560
|
+
errorMessage: error.message,
|
|
18561
|
+
stripped: true,
|
|
18562
|
+
});
|
|
18382
18563
|
throw new PipelineExecutionError(`All attempts failed. Attempt history:\n` +
|
|
18383
18564
|
attemptStack
|
|
18384
18565
|
.map((a, i) => ` ${i + 1}. Model: ${a.modelName}` +
|
|
@@ -18388,52 +18569,25 @@ class OpenAiCompatibleExecutionTools {
|
|
|
18388
18569
|
.join('\n') +
|
|
18389
18570
|
`\nFinal error: ${error.message}`);
|
|
18390
18571
|
}
|
|
18391
|
-
|
|
18392
|
-
|
|
18393
|
-
|
|
18394
|
-
const unsupportedParameter = parseUnsupportedParameterError(error.message);
|
|
18395
|
-
if (!unsupportedParameter) {
|
|
18572
|
+
// Mark this parameter as retried
|
|
18573
|
+
retriedUnsupportedParameters.add(retryKey);
|
|
18574
|
+
// Log warning in verbose mode
|
|
18396
18575
|
if (this.options.isVerbose) {
|
|
18397
|
-
console.warn(colors.bgYellow('Warning'),
|
|
18576
|
+
console.warn(colors.bgYellow('Warning'), `Removing unsupported parameter '${unsupportedParameter}' for model '${modelName}' and retrying request`);
|
|
18398
18577
|
}
|
|
18399
|
-
|
|
18400
|
-
}
|
|
18401
|
-
// Create a unique key for this model + parameter combination to prevent infinite loops
|
|
18402
|
-
const retryKey = `${modelName}-${unsupportedParameter}`;
|
|
18403
|
-
if (retriedUnsupportedParameters.has(retryKey)) {
|
|
18404
|
-
// Already retried this parameter, throw the error with attemptStack
|
|
18578
|
+
// Add to attemptStack
|
|
18405
18579
|
attemptStack.push({
|
|
18406
18580
|
modelName,
|
|
18407
18581
|
unsupportedParameter,
|
|
18408
18582
|
errorMessage: error.message,
|
|
18409
18583
|
stripped: true,
|
|
18410
18584
|
});
|
|
18411
|
-
|
|
18412
|
-
|
|
18413
|
-
|
|
18414
|
-
(a.unsupportedParameter ? `, Stripped: ${a.unsupportedParameter}` : '') +
|
|
18415
|
-
`, Error: ${a.errorMessage}` +
|
|
18416
|
-
(a.stripped ? ' (stripped and retried)' : ''))
|
|
18417
|
-
.join('\n') +
|
|
18418
|
-
`\nFinal error: ${error.message}`);
|
|
18585
|
+
// Remove the unsupported parameter and retry
|
|
18586
|
+
const modifiedModelRequirements = removeUnsupportedModelRequirement(currentModelRequirements, unsupportedParameter);
|
|
18587
|
+
return this.callChatModelWithRetry(prompt, modifiedModelRequirements, attemptStack, retriedUnsupportedParameters);
|
|
18419
18588
|
}
|
|
18420
|
-
// Mark this parameter as retried
|
|
18421
|
-
retriedUnsupportedParameters.add(retryKey);
|
|
18422
|
-
// Log warning in verbose mode
|
|
18423
|
-
if (this.options.isVerbose) {
|
|
18424
|
-
console.warn(colors.bgYellow('Warning'), `Removing unsupported parameter '${unsupportedParameter}' for model '${modelName}' and retrying request`);
|
|
18425
|
-
}
|
|
18426
|
-
// Add to attemptStack
|
|
18427
|
-
attemptStack.push({
|
|
18428
|
-
modelName,
|
|
18429
|
-
unsupportedParameter,
|
|
18430
|
-
errorMessage: error.message,
|
|
18431
|
-
stripped: true,
|
|
18432
|
-
});
|
|
18433
|
-
// Remove the unsupported parameter and retry
|
|
18434
|
-
const modifiedModelRequirements = removeUnsupportedModelRequirement(currentModelRequirements, unsupportedParameter);
|
|
18435
|
-
return this.callChatModelWithRetry(prompt, modifiedModelRequirements, attemptStack, retriedUnsupportedParameters);
|
|
18436
18589
|
}
|
|
18590
|
+
throw new PipelineExecutionError(`Tool calling loop did not return a result from ${this.title}`);
|
|
18437
18591
|
}
|
|
18438
18592
|
/**
|
|
18439
18593
|
* Calls OpenAI API to use a complete model.
|
|
@@ -20151,6 +20305,7 @@ class RemoteAgent extends Agent {
|
|
|
20151
20305
|
body: JSON.stringify({
|
|
20152
20306
|
message: prompt.content,
|
|
20153
20307
|
thread: chatPrompt.thread,
|
|
20308
|
+
attachments: chatPrompt.attachments,
|
|
20154
20309
|
}),
|
|
20155
20310
|
});
|
|
20156
20311
|
// <- TODO: [๐ฑโ๐] What about closed-source agents?
|
|
@@ -21721,5 +21876,5 @@ function $generateBookBoilerplate(options) {
|
|
|
21721
21876
|
* TODO: [๐คถ] Maybe export through `@promptbook/utils` or `@promptbook/random` package
|
|
21722
21877
|
*/
|
|
21723
21878
|
|
|
21724
|
-
export { $bookTranspilersRegister, $generateBookBoilerplate, $llmToolsMetadataRegister, $llmToolsRegister, $scrapersMetadataRegister, $scrapersRegister, ADMIN_EMAIL, ADMIN_GITHUB_NAME, API_REQUEST_TIMEOUT, AbstractFormatError, Agent, AgentCollectionInSupabase, AgentLlmExecutionTools, AuthenticationError, BIG_DATASET_TRESHOLD, BOOK_LANGUAGE_VERSION, BlackholeStorage, BoilerplateError, BoilerplateFormfactorDefinition, CLAIM, CLI_APP_ID, CORE_AGENTS_SERVER, CORE_AGENTS_SERVER_WELL_KNOWN_AGENT_NAMES, CallbackInterfaceTools, ChatbotFormfactorDefinition, CollectionError, CompletionFormfactorDefinition, CsvFormatError, CsvFormatParser, DEFAULT_AGENTS_DIRNAME, DEFAULT_BOOK, DEFAULT_BOOKS_DIRNAME, DEFAULT_BOOK_OUTPUT_PARAMETER_NAME, DEFAULT_BOOK_TITLE, DEFAULT_CSV_SETTINGS, DEFAULT_DOWNLOAD_CACHE_DIRNAME, DEFAULT_EXECUTION_CACHE_DIRNAME, DEFAULT_GET_PIPELINE_COLLECTION_FUNCTION_NAME, DEFAULT_INTERMEDIATE_FILES_STRATEGY, DEFAULT_IS_AUTO_INSTALLED, DEFAULT_IS_VERBOSE, DEFAULT_MAX_EXECUTION_ATTEMPTS, DEFAULT_MAX_FILE_SIZE, DEFAULT_MAX_KNOWLEDGE_SOURCES_SCRAPING_DEPTH, DEFAULT_MAX_KNOWLEDGE_SOURCES_SCRAPING_TOTAL, DEFAULT_MAX_PARALLEL_COUNT, DEFAULT_MAX_REQUESTS_PER_MINUTE, DEFAULT_PIPELINE_COLLECTION_BASE_FILENAME, DEFAULT_PROMPT_TASK_TITLE, DEFAULT_REMOTE_SERVER_URL, DEFAULT_SCRAPE_CACHE_DIRNAME, DEFAULT_TASK_SIMULATED_DURATION_MS, DEFAULT_TASK_TITLE, DatabaseError, EXPECTATION_UNITS, EnvironmentMismatchError, ExecutionReportStringOptionsDefaults, ExpectError, FAILED_VALUE_PLACEHOLDER, FORMFACTOR_DEFINITIONS, FormattedBookInMarkdownTranspiler, GENERIC_PIPELINE_INTERFACE, GeneratorFormfactorDefinition, GenericFormfactorDefinition, ImageGeneratorFormfactorDefinition, KnowledgeScrapeError, LimitReachedError, MANDATORY_CSV_SETTINGS, MAX_FILENAME_LENGTH, MODEL_ORDERS, MODEL_TRUST_LEVELS, MODEL_VARIANTS, MatcherFormfactorDefinition, MemoryStorage, MissingToolsError, MultipleLlmExecutionTools, NAME, NonTaskSectionTypes, NotAllowed, NotFoundError, NotYetImplementedCommitmentDefinition, NotYetImplementedError, ORDER_OF_PIPELINE_JSON, OpenAiSdkTranspiler, PADDING_LINES, PENDING_VALUE_PLACEHOLDER, PLAYGROUND_APP_ID, PROMPTBOOK_CHAT_COLOR, PROMPTBOOK_COLOR, PROMPTBOOK_ENGINE_VERSION, PROMPTBOOK_ERRORS, PROMPTBOOK_LEGAL_ENTITY, PROMPTBOOK_LOGO_URL, PROMPTBOOK_SYNTAX_COLORS, PUBLIC_AGENTS_SERVERS, ParseError, PipelineExecutionError, PipelineLogicError, PipelineUrlError, PrefixStorage, PromptbookFetchError, RESERVED_PARAMETER_NAMES, RemoteAgent, SET_IS_VERBOSE, SectionTypes, SheetsFormfactorDefinition, TaskTypes, TextFormatParser, TranslatorFormfactorDefinition, UNCERTAIN_USAGE, UNCERTAIN_ZERO_VALUE, USER_CHAT_COLOR, UnexpectedError, WrappedError, ZERO_USAGE, ZERO_VALUE, _AgentMetadata, _AgentRegistration, _AnthropicClaudeMetadataRegistration, _AzureOpenAiMetadataRegistration, _BoilerplateScraperMetadataRegistration, _DeepseekMetadataRegistration, _DocumentScraperMetadataRegistration, _GoogleMetadataRegistration, _LegacyDocumentScraperMetadataRegistration, _MarkdownScraperMetadataRegistration, _MarkitdownScraperMetadataRegistration, _OllamaMetadataRegistration, _OpenAiAssistantMetadataRegistration, _OpenAiCompatibleMetadataRegistration, _OpenAiMetadataRegistration, _PdfScraperMetadataRegistration, _WebsiteScraperMetadataRegistration, aboutPromptbookInformation, addUsage, book, cacheLlmTools, compilePipeline, computeAgentHash, computeCosineSimilarity, countUsage, createAgentLlmExecutionTools, createAgentModelRequirements, createAgentModelRequirementsWithCommitments, createBasicAgentModelRequirements, createDefaultAgentName, createEmptyAgentModelRequirements, createLlmToolsFromConfiguration, createPipelineCollectionFromJson, createPipelineCollectionFromPromise, createPipelineCollectionFromUrl, createPipelineExecutor, createPipelineSubcollection, embeddingVectorToString, executionReportJsonToString, extractParameterNamesFromTask, filterModels, generatePlaceholderAgentProfileImageUrl, getAllCommitmentDefinitions, getAllCommitmentTypes, getCommitmentDefinition, getGroupedCommitmentDefinitions, getPipelineInterface, getSingleLlmExecutionTools, identificationToPromptbookToken, isCommitmentSupported, isPassingExpectations, isPipelineImplementingInterface, isPipelineInterfacesEqual, isPipelinePrepared, isValidBook, isValidPipelineString, joinLlmExecutionTools, limitTotalUsage, makeKnowledgeSourceHandler, migratePipeline, normalizeAgentName, padBook, parseAgentSource, parseParameters, parsePipeline, pipelineCollectionToJson, pipelineJsonToString, prepareKnowledgePieces, preparePersona, preparePipeline, prettifyPipelineString, promptbookFetch, promptbookTokenToIdentification, unpreparePipeline, usageToHuman, usageToWorktime, validateBook, validatePipeline, validatePipelineString };
|
|
21879
|
+
export { $bookTranspilersRegister, $generateBookBoilerplate, $llmToolsMetadataRegister, $llmToolsRegister, $scrapersMetadataRegister, $scrapersRegister, ADMIN_EMAIL, ADMIN_GITHUB_NAME, API_REQUEST_TIMEOUT, AbstractFormatError, Agent, AgentCollectionInSupabase, AgentLlmExecutionTools, AuthenticationError, BIG_DATASET_TRESHOLD, BOOK_LANGUAGE_VERSION, BlackholeStorage, BoilerplateError, BoilerplateFormfactorDefinition, CLAIM, CLI_APP_ID, CORE_AGENTS_SERVER, CORE_AGENTS_SERVER_WELL_KNOWN_AGENT_NAMES, CallbackInterfaceTools, ChatbotFormfactorDefinition, CollectionError, CompletionFormfactorDefinition, CsvFormatError, CsvFormatParser, DEFAULT_AGENTS_DIRNAME, DEFAULT_BOOK, DEFAULT_BOOKS_DIRNAME, DEFAULT_BOOK_OUTPUT_PARAMETER_NAME, DEFAULT_BOOK_TITLE, DEFAULT_CSV_SETTINGS, DEFAULT_DOWNLOAD_CACHE_DIRNAME, DEFAULT_EXECUTION_CACHE_DIRNAME, DEFAULT_GET_PIPELINE_COLLECTION_FUNCTION_NAME, DEFAULT_INTERMEDIATE_FILES_STRATEGY, DEFAULT_IS_AUTO_INSTALLED, DEFAULT_IS_VERBOSE, DEFAULT_MAX_EXECUTION_ATTEMPTS, DEFAULT_MAX_FILE_SIZE, DEFAULT_MAX_KNOWLEDGE_SOURCES_SCRAPING_DEPTH, DEFAULT_MAX_KNOWLEDGE_SOURCES_SCRAPING_TOTAL, DEFAULT_MAX_PARALLEL_COUNT, DEFAULT_MAX_RECURSION, DEFAULT_MAX_REQUESTS_PER_MINUTE, DEFAULT_PIPELINE_COLLECTION_BASE_FILENAME, DEFAULT_PROMPT_TASK_TITLE, DEFAULT_REMOTE_SERVER_URL, DEFAULT_SCRAPE_CACHE_DIRNAME, DEFAULT_TASK_SIMULATED_DURATION_MS, DEFAULT_TASK_TITLE, DatabaseError, EXPECTATION_UNITS, EnvironmentMismatchError, ExecutionReportStringOptionsDefaults, ExpectError, FAILED_VALUE_PLACEHOLDER, FORMFACTOR_DEFINITIONS, FormattedBookInMarkdownTranspiler, GENERIC_PIPELINE_INTERFACE, GeneratorFormfactorDefinition, GenericFormfactorDefinition, ImageGeneratorFormfactorDefinition, KnowledgeScrapeError, LimitReachedError, MANDATORY_CSV_SETTINGS, MAX_FILENAME_LENGTH, MODEL_ORDERS, MODEL_TRUST_LEVELS, MODEL_VARIANTS, MatcherFormfactorDefinition, MemoryStorage, MissingToolsError, MultipleLlmExecutionTools, NAME, NonTaskSectionTypes, NotAllowed, NotFoundError, NotYetImplementedCommitmentDefinition, NotYetImplementedError, ORDER_OF_PIPELINE_JSON, OpenAiSdkTranspiler, PADDING_LINES, PENDING_VALUE_PLACEHOLDER, PLAYGROUND_APP_ID, PROMPTBOOK_CHAT_COLOR, PROMPTBOOK_COLOR, PROMPTBOOK_ENGINE_VERSION, PROMPTBOOK_ERRORS, PROMPTBOOK_LEGAL_ENTITY, PROMPTBOOK_LOGO_URL, PROMPTBOOK_SYNTAX_COLORS, PUBLIC_AGENTS_SERVERS, ParseError, PipelineExecutionError, PipelineLogicError, PipelineUrlError, PrefixStorage, PromptbookFetchError, RESERVED_PARAMETER_NAMES, RemoteAgent, SET_IS_VERBOSE, SectionTypes, SheetsFormfactorDefinition, TaskTypes, TextFormatParser, TranslatorFormfactorDefinition, UNCERTAIN_USAGE, UNCERTAIN_ZERO_VALUE, USER_CHAT_COLOR, UnexpectedError, WrappedError, ZERO_USAGE, ZERO_VALUE, _AgentMetadata, _AgentRegistration, _AnthropicClaudeMetadataRegistration, _AzureOpenAiMetadataRegistration, _BoilerplateScraperMetadataRegistration, _DeepseekMetadataRegistration, _DocumentScraperMetadataRegistration, _GoogleMetadataRegistration, _LegacyDocumentScraperMetadataRegistration, _MarkdownScraperMetadataRegistration, _MarkitdownScraperMetadataRegistration, _OllamaMetadataRegistration, _OpenAiAssistantMetadataRegistration, _OpenAiCompatibleMetadataRegistration, _OpenAiMetadataRegistration, _PdfScraperMetadataRegistration, _WebsiteScraperMetadataRegistration, aboutPromptbookInformation, addUsage, book, cacheLlmTools, compilePipeline, computeAgentHash, computeCosineSimilarity, countUsage, createAgentLlmExecutionTools, createAgentModelRequirements, createAgentModelRequirementsWithCommitments, createBasicAgentModelRequirements, createDefaultAgentName, createEmptyAgentModelRequirements, createLlmToolsFromConfiguration, createPipelineCollectionFromJson, createPipelineCollectionFromPromise, createPipelineCollectionFromUrl, createPipelineExecutor, createPipelineSubcollection, embeddingVectorToString, executionReportJsonToString, extractParameterNamesFromTask, filterModels, generatePlaceholderAgentProfileImageUrl, getAllCommitmentDefinitions, getAllCommitmentTypes, getCommitmentDefinition, getGroupedCommitmentDefinitions, getPipelineInterface, getSingleLlmExecutionTools, identificationToPromptbookToken, isCommitmentSupported, isPassingExpectations, isPipelineImplementingInterface, isPipelineInterfacesEqual, isPipelinePrepared, isValidBook, isValidPipelineString, joinLlmExecutionTools, limitTotalUsage, makeKnowledgeSourceHandler, migratePipeline, normalizeAgentName, padBook, parseAgentSource, parseParameters, parsePipeline, pipelineCollectionToJson, pipelineJsonToString, prepareKnowledgePieces, preparePersona, preparePipeline, prettifyPipelineString, promptbookFetch, promptbookTokenToIdentification, unpreparePipeline, usageToHuman, usageToWorktime, validateBook, validatePipeline, validatePipelineString };
|
|
21725
21880
|
//# sourceMappingURL=index.es.js.map
|