@promptbook/cli 0.105.0-4 → 0.105.0-5

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
@@ -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-4';
50
+ const PROMPTBOOK_ENGINE_VERSION = '0.105.0-5';
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
@@ -23207,20 +23207,29 @@ class OpenAiCompatibleExecutionTools {
23207
23207
  });
23208
23208
  return availableModels;
23209
23209
  }
23210
+ /**
23211
+ * Calls OpenAI compatible API to use a chat model.
23212
+ */
23210
23213
  /**
23211
23214
  * Calls OpenAI compatible API to use a chat model.
23212
23215
  */
23213
23216
  async callChatModel(prompt) {
23217
+ return this.callChatModelStream(prompt, () => { });
23218
+ }
23219
+ /**
23220
+ * Calls OpenAI compatible API to use a chat model with streaming.
23221
+ */
23222
+ async callChatModelStream(prompt, onProgress) {
23214
23223
  // Deep clone prompt and modelRequirements to avoid mutation across calls
23215
23224
  const clonedPrompt = JSON.parse(JSON.stringify(prompt));
23216
23225
  // Use local Set for retried parameters to ensure independence and thread safety
23217
23226
  const retriedUnsupportedParameters = new Set();
23218
- return this.callChatModelWithRetry(clonedPrompt, clonedPrompt.modelRequirements, [], retriedUnsupportedParameters);
23227
+ return this.callChatModelWithRetry(clonedPrompt, clonedPrompt.modelRequirements, [], retriedUnsupportedParameters, onProgress);
23219
23228
  }
23220
23229
  /**
23221
23230
  * Internal method that handles parameter retry for chat model calls
23222
23231
  */
23223
- async callChatModelWithRetry(prompt, currentModelRequirements, attemptStack = [], retriedUnsupportedParameters = new Set()) {
23232
+ async callChatModelWithRetry(prompt, currentModelRequirements, attemptStack = [], retriedUnsupportedParameters = new Set(), onProgress) {
23224
23233
  var _a;
23225
23234
  if (this.options.isVerbose) {
23226
23235
  console.info(`💬 ${this.title} callChatModel call`, { prompt, currentModelRequirements });
@@ -23326,6 +23335,23 @@ class OpenAiCompatibleExecutionTools {
23326
23335
  const usage = this.computeUsage(content || '', responseMessage.content || '', rawResponse);
23327
23336
  totalUsage = addUsage(totalUsage, usage);
23328
23337
  if (responseMessage.tool_calls && responseMessage.tool_calls.length > 0) {
23338
+ if (onProgress) {
23339
+ onProgress({
23340
+ content: responseMessage.content || '',
23341
+ modelName: rawResponse.model || modelName,
23342
+ timing: { start, complete: $getCurrentDate() },
23343
+ usage: totalUsage,
23344
+ toolCalls: responseMessage.tool_calls.map((toolCall) => ({
23345
+ name: toolCall.function.name,
23346
+ arguments: toolCall.function.arguments,
23347
+ result: '',
23348
+ rawToolCall: toolCall,
23349
+ })),
23350
+ rawPromptContent,
23351
+ rawRequest,
23352
+ rawResponse,
23353
+ });
23354
+ }
23329
23355
  await forEachAsync(responseMessage.tool_calls, {}, async (toolCall) => {
23330
23356
  const functionName = toolCall.function.name;
23331
23357
  const functionArgs = toolCall.function.arguments;
@@ -23453,7 +23479,7 @@ class OpenAiCompatibleExecutionTools {
23453
23479
  });
23454
23480
  // Remove the unsupported parameter and retry
23455
23481
  const modifiedModelRequirements = removeUnsupportedModelRequirement(currentModelRequirements, unsupportedParameter);
23456
- return this.callChatModelWithRetry(prompt, modifiedModelRequirements, attemptStack, retriedUnsupportedParameters);
23482
+ return this.callChatModelWithRetry(prompt, modifiedModelRequirements, attemptStack, retriedUnsupportedParameters, onProgress);
23457
23483
  }
23458
23484
  }
23459
23485
  throw new PipelineExecutionError(`Tool calling loop did not return a result from ${this.title}`);
@@ -24644,6 +24670,15 @@ class OpenAiAssistantExecutionTools extends OpenAiExecutionTools {
24644
24670
  // [🐱‍🚀] When tools are present, we need to use the non-streaming Runs API
24645
24671
  // because streaming doesn't support tool execution flow properly
24646
24672
  if (hasTools) {
24673
+ onProgress({
24674
+ content: '',
24675
+ modelName: 'assistant',
24676
+ timing: { start, complete: $getCurrentDate() },
24677
+ usage: UNCERTAIN_USAGE,
24678
+ rawPromptContent,
24679
+ rawRequest: null,
24680
+ rawResponse: null,
24681
+ });
24647
24682
  const rawRequest = {
24648
24683
  assistant_id: this.assistantId,
24649
24684
  thread: {
@@ -24667,6 +24702,23 @@ class OpenAiAssistantExecutionTools extends OpenAiExecutionTools {
24667
24702
  if (toolCall.type === 'function') {
24668
24703
  const functionName = toolCall.function.name;
24669
24704
  const functionArgs = JSON.parse(toolCall.function.arguments);
24705
+ onProgress({
24706
+ content: '',
24707
+ modelName: 'assistant',
24708
+ timing: { start, complete: $getCurrentDate() },
24709
+ usage: UNCERTAIN_USAGE,
24710
+ rawPromptContent,
24711
+ rawRequest: null,
24712
+ rawResponse: null,
24713
+ toolCalls: [
24714
+ {
24715
+ name: functionName,
24716
+ arguments: toolCall.function.arguments,
24717
+ result: '',
24718
+ rawToolCall: toolCall,
24719
+ },
24720
+ ],
24721
+ });
24670
24722
  if (this.options.isVerbose) {
24671
24723
  console.info(`🔧 Executing tool: ${functionName}`, functionArgs);
24672
24724
  }
@@ -27375,26 +27427,52 @@ function parseAgentSource(agentSource) {
27375
27427
  });
27376
27428
  continue;
27377
27429
  }
27430
+ if (commitment.type === 'FROM') {
27431
+ const content = spaceTrim$2(commitment.content).split('\n')[0] || '';
27432
+ if (content === 'Adam' || content === '' /* <- Note: Adam is implicit */) {
27433
+ continue;
27434
+ }
27435
+ let label = content;
27436
+ let iconName = 'SquareArrowOutUpRight'; // Inheritance remote
27437
+ if (content.startsWith('./') || content.startsWith('../') || content.startsWith('/')) {
27438
+ label = content.split('/').pop() || content;
27439
+ iconName = 'SquareArrowUpRight'; // Inheritance local
27440
+ }
27441
+ if (content === 'VOID') {
27442
+ label = 'VOID';
27443
+ iconName = 'ShieldAlert'; // [🧠] Or some other icon for VOID
27444
+ }
27445
+ capabilities.push({
27446
+ type: 'inheritance',
27447
+ label,
27448
+ iconName,
27449
+ agentUrl: content,
27450
+ });
27451
+ continue;
27452
+ }
27378
27453
  if (commitment.type === 'IMPORT') {
27379
27454
  const content = spaceTrim$2(commitment.content).split('\n')[0] || '';
27380
27455
  let label = content;
27381
- const iconName = 'Download';
27456
+ let iconName = 'ExternalLink'; // Import remote
27382
27457
  try {
27383
27458
  if (content.startsWith('http://') || content.startsWith('https://')) {
27384
27459
  const url = new URL(content);
27385
27460
  label = url.hostname.replace(/^www\./, '') + '.../' + url.pathname.split('/').pop();
27461
+ iconName = 'ExternalLink';
27386
27462
  }
27387
27463
  else if (content.startsWith('./') || content.startsWith('../') || content.startsWith('/')) {
27388
27464
  label = content.split('/').pop() || content;
27465
+ iconName = 'Link'; // Import local
27389
27466
  }
27390
27467
  }
27391
27468
  catch (e) {
27392
27469
  // Invalid URL or path, keep default label
27393
27470
  }
27394
27471
  capabilities.push({
27395
- type: 'knowledge',
27472
+ type: 'import',
27396
27473
  label,
27397
27474
  iconName,
27475
+ agentUrl: content,
27398
27476
  });
27399
27477
  continue;
27400
27478
  }