@promptbook/cli 0.105.0-12 → 0.105.0-15

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 CHANGED
@@ -16,8 +16,8 @@ import { spawn } from 'child_process';
16
16
  import JSZip from 'jszip';
17
17
  import { parse, unparse } from 'papaparse';
18
18
  import { lookup, extension } from 'mime-types';
19
- import glob from 'glob-promise';
20
19
  import moment from 'moment';
20
+ import glob from 'glob-promise';
21
21
  import express from 'express';
22
22
  import * as OpenApiValidator from 'express-openapi-validator';
23
23
  import http from 'http';
@@ -47,7 +47,7 @@ const BOOK_LANGUAGE_VERSION = '2.0.0';
47
47
  * @generated
48
48
  * @see https://github.com/webgptorg/promptbook
49
49
  */
50
- const PROMPTBOOK_ENGINE_VERSION = '0.105.0-12';
50
+ const PROMPTBOOK_ENGINE_VERSION = '0.105.0-15';
51
51
  /**
52
52
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
53
53
  * Note: [💞] Ignore a discrepancy between file name and entity name
@@ -2555,6 +2555,56 @@ const RESERVED_PARAMETER_NAMES = exportJson({
2555
2555
  // <- TODO: Add [emoji] + instructions ACRY when adding new reserved parameter
2556
2556
  ],
2557
2557
  });
2558
+ /**
2559
+ * Limits for IDs, names, and other strings
2560
+ *
2561
+ * @public exported from `@promptbook/core`
2562
+ */
2563
+ const LIMITS = {
2564
+ /**
2565
+ * Minimum length of a name (e.g. agent name, persona name)
2566
+ */
2567
+ NAME_MIN_LENGTH: 3,
2568
+ /**
2569
+ * Recommended maximum length of a name
2570
+ */
2571
+ NAME_MAX_LENGTH: 20,
2572
+ /**
2573
+ * Maximum length of a short description or a hash
2574
+ */
2575
+ SHORT_TEXT_MAX_LENGTH: 30,
2576
+ /**
2577
+ * Gone
2578
+ */
2579
+ GONE: 410,
2580
+ /**
2581
+ * Gateway timeout
2582
+ */
2583
+ GATEWAY_TIMEOUT: 504,
2584
+ /**
2585
+ * Too many requests
2586
+ */
2587
+ TOO_MANY_REQUESTS: 429,
2588
+ /**
2589
+ * Maximum length of a file path segment
2590
+ */
2591
+ FILE_PATH_SEGMENT_MAX_LENGTH: 8,
2592
+ /**
2593
+ * Default length of a short name (e.g. for default agent names)
2594
+ */
2595
+ SHORT_NAME_LENGTH: 6,
2596
+ };
2597
+ /**
2598
+ * Common ports and network limits
2599
+ *
2600
+ * @public exported from `@promptbook/core`
2601
+ */
2602
+ const NETWORK_LIMITS = {
2603
+ /**
2604
+ * Maximum valid port number
2605
+ */
2606
+ MAX_PORT: 65535,
2607
+ };
2558
2608
  /**
2559
2609
  * Note: [💞] Ignore a discrepancy between file name and entity name
2560
2610
  */
@@ -16822,6 +16872,25 @@ class SerpSearchEngine {
16822
16872
  }
16823
16873
  }
16824
16874
 
16875
+ /**
16876
+ * @@@
16877
+ *
16878
+ * @private utility for commitments
16879
+ */
16880
+ function formatOptionalInstructionBlock(label, content) {
16881
+ const trimmedContent = spaceTrim$1(content);
16882
+ if (!trimmedContent) {
16883
+ return '';
16884
+ }
16885
+ return spaceTrim$1((block) => `
16886
+ - ${label}:
16887
+ ${block(trimmedContent
16888
+ .split('\n')
16889
+ .map((line) => `- ${line}`)
16890
+ .join('\n'))}
16891
+ `);
16892
+ }
16893
+
16825
16894
  /**
16826
16895
  * USE SEARCH ENGINE commitment definition
16827
16896
  *
@@ -16843,6 +16912,9 @@ class UseSearchEngineCommitmentDefinition extends BaseCommitmentDefinition {
16843
16912
  constructor() {
16844
16913
  super('USE SEARCH ENGINE', ['USE SEARCH']);
16845
16914
  }
16915
+ get requiresContent() {
16916
+ return false;
16917
+ }
16846
16918
  /**
16847
16919
  * Short one-line description of USE SEARCH ENGINE.
16848
16920
  */
@@ -16891,6 +16963,7 @@ class UseSearchEngineCommitmentDefinition extends BaseCommitmentDefinition {
16891
16963
  `);
16892
16964
  }
16893
16965
  applyToAgentModelRequirements(requirements, content) {
16966
+ const extraInstructions = formatOptionalInstructionBlock('Search instructions', content);
16894
16967
  // Get existing tools array or create new one
16895
16968
  const existingTools = requirements.tools || [];
16896
16969
  // Add 'web_search' to tools if not already present
@@ -16949,13 +17022,14 @@ class UseSearchEngineCommitmentDefinition extends BaseCommitmentDefinition {
16949
17022
  ...requirements.metadata,
16950
17023
  useSearchEngine: content || true,
16951
17024
  },
16952
- }, spaceTrim$1(`
16953
- Tools:
16954
- You have access to the web search engine via the tool "web_search".
16955
- Use it to find up-to-date information or facts that you don't know.
16956
- When you need to know some information from the internet, use the tool provided to you.
16957
- Do not make up information when you can search for it.
16958
- Do not tell the user you cannot search for information, YOU CAN.
17025
+ }, spaceTrim$1((block) => `
17026
+ Tool:
17027
+ - You have access to the web search engine via the tool "web_search".
17028
+ - Use it to find up-to-date information or facts that you don't know.
17029
+ - When you need to know some information from the internet, use the tool provided to you.
17030
+ - Do not make up information when you can search for it.
17031
+ - Do not tell the user you cannot search for information, YOU CAN.
17032
+ ${block(extraInstructions)}
16959
17033
  `));
16960
17034
  }
16961
17035
  /**
@@ -17007,6 +17081,7 @@ class UseSearchEngineCommitmentDefinition extends BaseCommitmentDefinition {
17007
17081
  *
17008
17082
  * ```book
17009
17083
  * USE TIME
17084
+ * USE TIME Prefer the user's local timezone.
17010
17085
  * ```
17011
17086
  *
17012
17087
  * @private [🪔] Maybe export the commitments through some package
@@ -17015,6 +17090,9 @@ class UseTimeCommitmentDefinition extends BaseCommitmentDefinition {
17015
17090
  constructor() {
17016
17091
  super('USE TIME', ['CURRENT TIME', 'TIME', 'DATE']);
17017
17092
  }
17093
+ get requiresContent() {
17094
+ return false;
17095
+ }
17018
17096
  /**
17019
17097
  * Short one-line description of USE TIME.
17020
17098
  */
@@ -17041,6 +17119,7 @@ class UseTimeCommitmentDefinition extends BaseCommitmentDefinition {
17041
17119
  - This tool won't receive any input.
17042
17120
  - It outputs the current date and time as an ISO 8601 string.
17043
17121
  - Allows the agent to answer questions about the current time or date.
17122
+ - The content following \`USE TIME\` is an arbitrary text that the agent should know (e.g. timezone preference).
17044
17123
 
17045
17124
  ## Examples
17046
17125
 
@@ -17050,9 +17129,17 @@ class UseTimeCommitmentDefinition extends BaseCommitmentDefinition {
17050
17129
  PERSONA You are a helpful assistant who knows the current time.
17051
17130
  USE TIME
17052
17131
  \`\`\`
17132
+
17133
+ \`\`\`book
17134
+ Travel Assistant
17135
+
17136
+ PERSONA You help travelers with planning.
17137
+ USE TIME Prefer the user's local timezone.
17138
+ \`\`\`
17053
17139
  `);
17054
17140
  }
17055
17141
  applyToAgentModelRequirements(requirements, content) {
17142
+ const extraInstructions = formatOptionalInstructionBlock('Time instructions', content);
17056
17143
  // Get existing tools array or create new one
17057
17144
  const existingTools = requirements.tools || [];
17058
17145
  // Add 'get_current_time' to tools if not already present
@@ -17083,13 +17170,12 @@ class UseTimeCommitmentDefinition extends BaseCommitmentDefinition {
17083
17170
  metadata: {
17084
17171
  ...requirements.metadata,
17085
17172
  },
17086
- }, spaceTrim$1(`
17087
- Tool:
17088
- You have access to the current date and time via the tool "get_current_time".
17089
- Use it to answer questions about the current date and time.
17090
- When you need to know the current date or time, use the tool provided to you.
17091
- Do not make up the current date or time; always use the tool to get accurate information.
17092
- `));
17173
+ }, spaceTrim$1((block) => `
17174
+ Time and date context:
17175
+ - It is ${moment().format('MMMM YYYY')} now.
17176
+ - If you need more precise current time information, use the tool "get_current_time".
17177
+ ${block(extraInstructions)}
17178
+ `));
17093
17179
  }
17094
17180
  /**
17095
17181
  * Gets human-readable titles for tool functions provided by this commitment.
@@ -19335,7 +19421,7 @@ function $initializeStartAgentsServerCommand(program) {
19335
19421
  const { port: portRaw, reload: isCacheReloaded, verbose: isVerbose } = cliOptions;
19336
19422
  // TODO: [🐱‍🚀] [🌕] DRY
19337
19423
  const port = parseInt(portRaw, 10);
19338
- if (isNaN(port) || port <= 0 || port > 65535) {
19424
+ if (isNaN(port) || port <= 0 || port > NETWORK_LIMITS.MAX_PORT) {
19339
19425
  console.error(colors.red(`Invalid port number: ${portRaw}`));
19340
19426
  return process.exit(1);
19341
19427
  }
@@ -23739,18 +23825,26 @@ class OpenAiCompatibleExecutionTools {
23739
23825
  const usage = this.computeUsage(content || '', responseMessage.content || '', rawResponse);
23740
23826
  totalUsage = addUsage(totalUsage, usage);
23741
23827
  if (responseMessage.tool_calls && responseMessage.tool_calls.length > 0) {
23828
+ const toolCallStartedAt = new Map();
23742
23829
  if (onProgress) {
23743
23830
  onProgress({
23744
23831
  content: responseMessage.content || '',
23745
23832
  modelName: rawResponse.model || modelName,
23746
23833
  timing: { start, complete: $getCurrentDate() },
23747
23834
  usage: totalUsage,
23748
- toolCalls: responseMessage.tool_calls.map((toolCall) => ({
23749
- name: toolCall.function.name,
23750
- arguments: toolCall.function.arguments,
23751
- result: '',
23752
- rawToolCall: toolCall,
23753
- })),
23835
+ toolCalls: responseMessage.tool_calls.map((toolCall) => {
23836
+ const calledAt = $getCurrentDate();
23837
+ if (toolCall.id) {
23838
+ toolCallStartedAt.set(toolCall.id, calledAt);
23839
+ }
23840
+ return {
23841
+ name: toolCall.function.name,
23842
+ arguments: toolCall.function.arguments,
23843
+ result: '',
23844
+ rawToolCall: toolCall,
23845
+ createdAt: calledAt,
23846
+ };
23847
+ }),
23754
23848
  rawPromptContent,
23755
23849
  rawRequest,
23756
23850
  rawResponse,
@@ -23759,6 +23853,9 @@ class OpenAiCompatibleExecutionTools {
23759
23853
  await forEachAsync(responseMessage.tool_calls, {}, async (toolCall) => {
23760
23854
  const functionName = toolCall.function.name;
23761
23855
  const functionArgs = toolCall.function.arguments;
23856
+ const calledAt = toolCall.id
23857
+ ? toolCallStartedAt.get(toolCall.id) || $getCurrentDate()
23858
+ : $getCurrentDate();
23762
23859
  const executionTools = this.options
23763
23860
  .executionTools;
23764
23861
  if (!executionTools || !executionTools.script) {
@@ -23769,6 +23866,7 @@ class OpenAiCompatibleExecutionTools {
23769
23866
  ? executionTools.script
23770
23867
  : [executionTools.script];
23771
23868
  let functionResponse;
23869
+ let errors;
23772
23870
  try {
23773
23871
  const scriptTool = scriptTools[0]; // <- TODO: [🧠] Which script tool to use?
23774
23872
  functionResponse = await scriptTool.execute({
@@ -23783,6 +23881,7 @@ class OpenAiCompatibleExecutionTools {
23783
23881
  catch (error) {
23784
23882
  assertsError(error);
23785
23883
  functionResponse = `Error: ${error.message}`;
23884
+ errors = [serializeError(error)];
23786
23885
  }
23787
23886
  messages.push({
23788
23887
  role: 'tool',
@@ -23794,6 +23893,8 @@ class OpenAiCompatibleExecutionTools {
23794
23893
  arguments: functionArgs,
23795
23894
  result: functionResponse,
23796
23895
  rawToolCall: toolCall,
23896
+ createdAt: calledAt,
23897
+ errors,
23797
23898
  });
23798
23899
  });
23799
23900
  continue;
@@ -25127,6 +25228,8 @@ class OpenAiAssistantExecutionTools extends OpenAiExecutionTools {
25127
25228
  // Create thread and run
25128
25229
  const threadAndRun = await client.beta.threads.createAndRun(rawRequest);
25129
25230
  let run = threadAndRun;
25231
+ const completedToolCalls = [];
25232
+ const toolCallStartedAt = new Map();
25130
25233
  // Poll until run completes or requires action
25131
25234
  while (run.status === 'queued' || run.status === 'in_progress' || run.status === 'requires_action') {
25132
25235
  if (run.status === 'requires_action' && ((_a = run.required_action) === null || _a === void 0 ? void 0 : _a.type) === 'submit_tool_outputs') {
@@ -25137,6 +25240,10 @@ class OpenAiAssistantExecutionTools extends OpenAiExecutionTools {
25137
25240
  if (toolCall.type === 'function') {
25138
25241
  const functionName = toolCall.function.name;
25139
25242
  const functionArgs = JSON.parse(toolCall.function.arguments);
25243
+ const calledAt = $getCurrentDate();
25244
+ if (toolCall.id) {
25245
+ toolCallStartedAt.set(toolCall.id, calledAt);
25246
+ }
25140
25247
  onProgress({
25141
25248
  content: '',
25142
25249
  modelName: 'assistant',
@@ -25151,6 +25258,7 @@ class OpenAiAssistantExecutionTools extends OpenAiExecutionTools {
25151
25258
  arguments: toolCall.function.arguments,
25152
25259
  result: '',
25153
25260
  rawToolCall: toolCall,
25261
+ createdAt: calledAt,
25154
25262
  },
25155
25263
  ],
25156
25264
  });
@@ -25168,6 +25276,7 @@ class OpenAiAssistantExecutionTools extends OpenAiExecutionTools {
25168
25276
  ? executionTools.script
25169
25277
  : [executionTools.script];
25170
25278
  let functionResponse;
25279
+ let errors;
25171
25280
  try {
25172
25281
  const scriptTool = scriptTools[0]; // <- TODO: [🧠] Which script tool to use?
25173
25282
  functionResponse = await scriptTool.execute({
@@ -25184,12 +25293,14 @@ class OpenAiAssistantExecutionTools extends OpenAiExecutionTools {
25184
25293
  }
25185
25294
  catch (error) {
25186
25295
  assertsError(error);
25296
+ const serializedError = serializeError(error);
25297
+ errors = [serializedError];
25187
25298
  functionResponse = spaceTrim$2((block) => `
25188
25299
 
25189
25300
  The invoked tool \`${functionName}\` failed with error:
25190
25301
 
25191
25302
  \`\`\`json
25192
- ${block(JSON.stringify(serializeError(error), null, 4))}
25303
+ ${block(JSON.stringify(serializedError, null, 4))}
25193
25304
  \`\`\`
25194
25305
 
25195
25306
  `);
@@ -25200,6 +25311,14 @@ class OpenAiAssistantExecutionTools extends OpenAiExecutionTools {
25200
25311
  tool_call_id: toolCall.id,
25201
25312
  output: functionResponse,
25202
25313
  });
25314
+ completedToolCalls.push({
25315
+ name: functionName,
25316
+ arguments: toolCall.function.arguments,
25317
+ result: functionResponse,
25318
+ rawToolCall: toolCall,
25319
+ createdAt: toolCall.id ? toolCallStartedAt.get(toolCall.id) || calledAt : calledAt,
25320
+ errors,
25321
+ });
25203
25322
  }
25204
25323
  }
25205
25324
  // Submit tool outputs
@@ -25239,6 +25358,7 @@ class OpenAiAssistantExecutionTools extends OpenAiExecutionTools {
25239
25358
  rawPromptContent,
25240
25359
  rawRequest,
25241
25360
  rawResponse: { run, messages: messages.data },
25361
+ toolCalls: completedToolCalls.length > 0 ? completedToolCalls : undefined,
25242
25362
  };
25243
25363
  onProgress(finalChunk);
25244
25364
  return exportJson({
@@ -27779,7 +27899,7 @@ function normalizeAgentName(rawAgentName) {
27779
27899
  */
27780
27900
  function createDefaultAgentName(agentSource) {
27781
27901
  const agentHash = computeAgentHash(agentSource);
27782
- return normalizeAgentName(`Agent ${agentHash.substring(0, 6)}`);
27902
+ return normalizeAgentName(`Agent ${agentHash.substring(0, LIMITS.SHORT_NAME_LENGTH)}`);
27783
27903
  }
27784
27904
 
27785
27905
  /**