@promptbook/core 0.105.0-4 → 0.105.0-6

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
@@ -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.105.0-4';
30
+ const PROMPTBOOK_ENGINE_VERSION = '0.105.0-6';
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
@@ -12470,26 +12470,52 @@ function parseAgentSource(agentSource) {
12470
12470
  });
12471
12471
  continue;
12472
12472
  }
12473
+ if (commitment.type === 'FROM') {
12474
+ const content = spaceTrim$2(commitment.content).split('\n')[0] || '';
12475
+ if (content === 'Adam' || content === '' /* <- Note: Adam is implicit */) {
12476
+ continue;
12477
+ }
12478
+ let label = content;
12479
+ let iconName = 'SquareArrowOutUpRight'; // Inheritance remote
12480
+ if (content.startsWith('./') || content.startsWith('../') || content.startsWith('/')) {
12481
+ label = content.split('/').pop() || content;
12482
+ iconName = 'SquareArrowUpRight'; // Inheritance local
12483
+ }
12484
+ if (content === 'VOID') {
12485
+ label = 'VOID';
12486
+ iconName = 'ShieldAlert'; // [🧠] Or some other icon for VOID
12487
+ }
12488
+ capabilities.push({
12489
+ type: 'inheritance',
12490
+ label,
12491
+ iconName,
12492
+ agentUrl: content,
12493
+ });
12494
+ continue;
12495
+ }
12473
12496
  if (commitment.type === 'IMPORT') {
12474
12497
  const content = spaceTrim$2(commitment.content).split('\n')[0] || '';
12475
12498
  let label = content;
12476
- const iconName = 'Download';
12499
+ let iconName = 'ExternalLink'; // Import remote
12477
12500
  try {
12478
12501
  if (content.startsWith('http://') || content.startsWith('https://')) {
12479
12502
  const url = new URL(content);
12480
12503
  label = url.hostname.replace(/^www\./, '') + '.../' + url.pathname.split('/').pop();
12504
+ iconName = 'ExternalLink';
12481
12505
  }
12482
12506
  else if (content.startsWith('./') || content.startsWith('../') || content.startsWith('/')) {
12483
12507
  label = content.split('/').pop() || content;
12508
+ iconName = 'Link'; // Import local
12484
12509
  }
12485
12510
  }
12486
12511
  catch (e) {
12487
12512
  // Invalid URL or path, keep default label
12488
12513
  }
12489
12514
  capabilities.push({
12490
- type: 'knowledge',
12515
+ type: 'import',
12491
12516
  label,
12492
12517
  iconName,
12518
+ agentUrl: content,
12493
12519
  });
12494
12520
  continue;
12495
12521
  }
@@ -18802,20 +18828,29 @@ class OpenAiCompatibleExecutionTools {
18802
18828
  });
18803
18829
  return availableModels;
18804
18830
  }
18831
+ /**
18832
+ * Calls OpenAI compatible API to use a chat model.
18833
+ */
18805
18834
  /**
18806
18835
  * Calls OpenAI compatible API to use a chat model.
18807
18836
  */
18808
18837
  async callChatModel(prompt) {
18838
+ return this.callChatModelStream(prompt, () => { });
18839
+ }
18840
+ /**
18841
+ * Calls OpenAI compatible API to use a chat model with streaming.
18842
+ */
18843
+ async callChatModelStream(prompt, onProgress) {
18809
18844
  // Deep clone prompt and modelRequirements to avoid mutation across calls
18810
18845
  const clonedPrompt = JSON.parse(JSON.stringify(prompt));
18811
18846
  // Use local Set for retried parameters to ensure independence and thread safety
18812
18847
  const retriedUnsupportedParameters = new Set();
18813
- return this.callChatModelWithRetry(clonedPrompt, clonedPrompt.modelRequirements, [], retriedUnsupportedParameters);
18848
+ return this.callChatModelWithRetry(clonedPrompt, clonedPrompt.modelRequirements, [], retriedUnsupportedParameters, onProgress);
18814
18849
  }
18815
18850
  /**
18816
18851
  * Internal method that handles parameter retry for chat model calls
18817
18852
  */
18818
- async callChatModelWithRetry(prompt, currentModelRequirements, attemptStack = [], retriedUnsupportedParameters = new Set()) {
18853
+ async callChatModelWithRetry(prompt, currentModelRequirements, attemptStack = [], retriedUnsupportedParameters = new Set(), onProgress) {
18819
18854
  var _a;
18820
18855
  if (this.options.isVerbose) {
18821
18856
  console.info(`💬 ${this.title} callChatModel call`, { prompt, currentModelRequirements });
@@ -18921,6 +18956,23 @@ class OpenAiCompatibleExecutionTools {
18921
18956
  const usage = this.computeUsage(content || '', responseMessage.content || '', rawResponse);
18922
18957
  totalUsage = addUsage(totalUsage, usage);
18923
18958
  if (responseMessage.tool_calls && responseMessage.tool_calls.length > 0) {
18959
+ if (onProgress) {
18960
+ onProgress({
18961
+ content: responseMessage.content || '',
18962
+ modelName: rawResponse.model || modelName,
18963
+ timing: { start, complete: $getCurrentDate() },
18964
+ usage: totalUsage,
18965
+ toolCalls: responseMessage.tool_calls.map((toolCall) => ({
18966
+ name: toolCall.function.name,
18967
+ arguments: toolCall.function.arguments,
18968
+ result: '',
18969
+ rawToolCall: toolCall,
18970
+ })),
18971
+ rawPromptContent,
18972
+ rawRequest,
18973
+ rawResponse,
18974
+ });
18975
+ }
18924
18976
  await forEachAsync(responseMessage.tool_calls, {}, async (toolCall) => {
18925
18977
  const functionName = toolCall.function.name;
18926
18978
  const functionArgs = toolCall.function.arguments;
@@ -19048,7 +19100,7 @@ class OpenAiCompatibleExecutionTools {
19048
19100
  });
19049
19101
  // Remove the unsupported parameter and retry
19050
19102
  const modifiedModelRequirements = removeUnsupportedModelRequirement(currentModelRequirements, unsupportedParameter);
19051
- return this.callChatModelWithRetry(prompt, modifiedModelRequirements, attemptStack, retriedUnsupportedParameters);
19103
+ return this.callChatModelWithRetry(prompt, modifiedModelRequirements, attemptStack, retriedUnsupportedParameters, onProgress);
19052
19104
  }
19053
19105
  }
19054
19106
  throw new PipelineExecutionError(`Tool calling loop did not return a result from ${this.title}`);
@@ -19743,6 +19795,15 @@ class OpenAiAssistantExecutionTools extends OpenAiExecutionTools {
19743
19795
  // [🐱‍🚀] When tools are present, we need to use the non-streaming Runs API
19744
19796
  // because streaming doesn't support tool execution flow properly
19745
19797
  if (hasTools) {
19798
+ onProgress({
19799
+ content: '',
19800
+ modelName: 'assistant',
19801
+ timing: { start, complete: $getCurrentDate() },
19802
+ usage: UNCERTAIN_USAGE,
19803
+ rawPromptContent,
19804
+ rawRequest: null,
19805
+ rawResponse: null,
19806
+ });
19746
19807
  const rawRequest = {
19747
19808
  assistant_id: this.assistantId,
19748
19809
  thread: {
@@ -19766,6 +19827,23 @@ class OpenAiAssistantExecutionTools extends OpenAiExecutionTools {
19766
19827
  if (toolCall.type === 'function') {
19767
19828
  const functionName = toolCall.function.name;
19768
19829
  const functionArgs = JSON.parse(toolCall.function.arguments);
19830
+ onProgress({
19831
+ content: '',
19832
+ modelName: 'assistant',
19833
+ timing: { start, complete: $getCurrentDate() },
19834
+ usage: UNCERTAIN_USAGE,
19835
+ rawPromptContent,
19836
+ rawRequest: null,
19837
+ rawResponse: null,
19838
+ toolCalls: [
19839
+ {
19840
+ name: functionName,
19841
+ arguments: toolCall.function.arguments,
19842
+ result: '',
19843
+ rawToolCall: toolCall,
19844
+ },
19845
+ ],
19846
+ });
19769
19847
  if (this.options.isVerbose) {
19770
19848
  console.info(`🔧 Executing tool: ${functionName}`, functionArgs);
19771
19849
  }
@@ -20915,6 +20993,35 @@ class RemoteAgent extends Agent {
20915
20993
  doneReading = !!done;
20916
20994
  if (value) {
20917
20995
  const textChunk = decoder.decode(value, { stream: true });
20996
+ let isHandled = false;
20997
+ try {
20998
+ const lines = textChunk.split('\n');
20999
+ for (const line of lines) {
21000
+ const trimmedLine = line.trim();
21001
+ if (trimmedLine.startsWith('{') && trimmedLine.endsWith('}')) {
21002
+ const chunk = JSON.parse(trimmedLine);
21003
+ if (chunk.toolCalls) {
21004
+ onProgress({
21005
+ content,
21006
+ modelName: this.modelName,
21007
+ timing: {},
21008
+ usage: {},
21009
+ rawPromptContent: {},
21010
+ rawRequest: {},
21011
+ rawResponse: {},
21012
+ toolCalls: chunk.toolCalls,
21013
+ });
21014
+ isHandled = true;
21015
+ }
21016
+ }
21017
+ }
21018
+ }
21019
+ catch (error) {
21020
+ // Ignore non-json chunks
21021
+ }
21022
+ if (isHandled) {
21023
+ continue;
21024
+ }
20918
21025
  // console.debug('RemoteAgent chunk:', textChunk);
20919
21026
  content += textChunk;
20920
21027
  onProgress({