@promptbook/core 0.112.0-30 → 0.112.0-32

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.
Files changed (59) hide show
  1. package/esm/index.es.js +137 -40
  2. package/esm/index.es.js.map +1 -1
  3. package/esm/src/_packages/components.index.d.ts +6 -0
  4. package/esm/src/_packages/types.index.d.ts +6 -0
  5. package/esm/src/book-2.0/agent-source/AgentReferenceResolver.d.ts +11 -0
  6. package/esm/src/book-2.0/agent-source/CreateAgentModelRequirementsOptions.d.ts +8 -0
  7. package/esm/src/book-2.0/agent-source/TeammateProfileResolver.d.ts +33 -0
  8. package/esm/src/book-2.0/agent-source/createTeamToolName.d.ts +7 -7
  9. package/esm/src/book-components/Chat/Chat/ChatActionsBar.d.ts +5 -0
  10. package/esm/src/book-components/Chat/Chat/ChatMessageItem.d.ts +17 -1
  11. package/esm/src/book-components/Chat/Chat/ChatMessageItem.test.d.ts +1 -1
  12. package/esm/src/book-components/Chat/Chat/ChatMessageList.d.ts +14 -0
  13. package/esm/src/book-components/Chat/Chat/ChatProps.d.ts +290 -0
  14. package/esm/src/book-components/Chat/Chat/ChatToolCallModal.d.ts +16 -0
  15. package/esm/src/book-components/Chat/Chat/renderAdvancedToolCallDetails.d.ts +4 -0
  16. package/esm/src/book-components/Chat/Chat/renderToolCallDetails.d.ts +9 -0
  17. package/esm/src/book-components/Chat/MarkdownContent/MarkdownContent.d.ts +2 -1
  18. package/esm/src/book-components/Chat/MarkdownContent/MarkdownContent.test.d.ts +2 -0
  19. package/esm/src/book-components/Chat/hooks/useChatCompleteNotification.d.ts +18 -0
  20. package/esm/src/book-components/Chat/hooks/useChatCompleteNotification.test.d.ts +2 -0
  21. package/esm/src/book-components/Chat/types/ChatMessage.d.ts +77 -1
  22. package/esm/src/book-components/Chat/utils/formatToolCallDateTime.d.ts +37 -0
  23. package/esm/src/book-components/Chat/utils/formatToolCallLocalTime.d.ts +11 -0
  24. package/esm/src/book-components/Chat/utils/formatToolCallTranslationTemplate.d.ts +10 -0
  25. package/esm/src/book-components/Chat/utils/getChatMessageTimingDisplay.d.ts +5 -1
  26. package/esm/src/book-components/Chat/utils/getToolCallChipletInfo.d.ts +26 -1
  27. package/esm/src/book-components/Chat/utils/timeoutToolCallPresentation.d.ts +26 -3
  28. package/esm/src/utils/toolCalls/mergeToolCalls.d.ts +1 -1
  29. package/esm/src/version.d.ts +1 -1
  30. package/package.json +1 -1
  31. package/umd/index.umd.js +137 -40
  32. package/umd/index.umd.js.map +1 -1
  33. package/umd/src/_packages/components.index.d.ts +6 -0
  34. package/umd/src/_packages/types.index.d.ts +6 -0
  35. package/umd/src/book-2.0/agent-source/AgentReferenceResolver.d.ts +11 -0
  36. package/umd/src/book-2.0/agent-source/CreateAgentModelRequirementsOptions.d.ts +8 -0
  37. package/umd/src/book-2.0/agent-source/TeammateProfileResolver.d.ts +33 -0
  38. package/umd/src/book-2.0/agent-source/createTeamToolName.d.ts +7 -7
  39. package/umd/src/book-components/Chat/Chat/ChatActionsBar.d.ts +5 -0
  40. package/umd/src/book-components/Chat/Chat/ChatMessageItem.d.ts +17 -1
  41. package/umd/src/book-components/Chat/Chat/ChatMessageItem.test.d.ts +1 -1
  42. package/umd/src/book-components/Chat/Chat/ChatMessageList.d.ts +14 -0
  43. package/umd/src/book-components/Chat/Chat/ChatProps.d.ts +290 -0
  44. package/umd/src/book-components/Chat/Chat/ChatToolCallModal.d.ts +16 -0
  45. package/umd/src/book-components/Chat/Chat/renderAdvancedToolCallDetails.d.ts +4 -0
  46. package/umd/src/book-components/Chat/Chat/renderToolCallDetails.d.ts +9 -0
  47. package/umd/src/book-components/Chat/MarkdownContent/MarkdownContent.d.ts +2 -1
  48. package/umd/src/book-components/Chat/MarkdownContent/MarkdownContent.test.d.ts +2 -0
  49. package/umd/src/book-components/Chat/hooks/useChatCompleteNotification.d.ts +18 -0
  50. package/umd/src/book-components/Chat/hooks/useChatCompleteNotification.test.d.ts +2 -0
  51. package/umd/src/book-components/Chat/types/ChatMessage.d.ts +77 -1
  52. package/umd/src/book-components/Chat/utils/formatToolCallDateTime.d.ts +37 -0
  53. package/umd/src/book-components/Chat/utils/formatToolCallLocalTime.d.ts +11 -0
  54. package/umd/src/book-components/Chat/utils/formatToolCallTranslationTemplate.d.ts +10 -0
  55. package/umd/src/book-components/Chat/utils/getChatMessageTimingDisplay.d.ts +5 -1
  56. package/umd/src/book-components/Chat/utils/getToolCallChipletInfo.d.ts +26 -1
  57. package/umd/src/book-components/Chat/utils/timeoutToolCallPresentation.d.ts +26 -3
  58. package/umd/src/utils/toolCalls/mergeToolCalls.d.ts +1 -1
  59. package/umd/src/version.d.ts +1 -1
package/esm/index.es.js CHANGED
@@ -28,7 +28,7 @@ const BOOK_LANGUAGE_VERSION = '2.0.0';
28
28
  * @generated
29
29
  * @see https://github.com/webgptorg/promptbook
30
30
  */
31
- const PROMPTBOOK_ENGINE_VERSION = '0.112.0-30';
31
+ const PROMPTBOOK_ENGINE_VERSION = '0.112.0-32';
32
32
  /**
33
33
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
34
34
  * Note: [💞] Ignore a discrepancy between file name and entity name
@@ -14673,10 +14673,6 @@ class StyleCommitmentDefinition extends BaseCommitmentDefinition {
14673
14673
  * Prefix used for TEAM tool names.
14674
14674
  */
14675
14675
  const TEAM_TOOL_PREFIX = 'team_chat_';
14676
- /**
14677
- * Length of URL hash suffix appended to TEAM tool names.
14678
- */
14679
- const TEAM_TOOL_HASH_LENGTH = 10;
14680
14676
  /**
14681
14677
  * Fallback normalized name when teammate label is empty.
14682
14678
  */
@@ -14693,20 +14689,19 @@ function normalizeTeammateToolNamePart(teammateLabel) {
14693
14689
  return normalized || TEAM_TOOL_FALLBACK_NAME;
14694
14690
  }
14695
14691
  /**
14696
- * Builds a deterministic TEAM tool name from teammate identity.
14692
+ * Builds a deterministic TEAM tool name from the teammate label.
14697
14693
  *
14698
- * The readable part is based on teammate label while the hash suffix
14699
- * keeps uniqueness and stable mapping for the underlying teammate URL.
14694
+ * The tool name is derived solely from the human-readable label so that it
14695
+ * remains stable and predictable regardless of internal technical identifiers.
14700
14696
  *
14701
- * @param teammateUrl - Canonical teammate URL used at runtime.
14702
- * @param teammateLabel - Human-readable teammate label.
14703
- * @returns Deterministic TEAM tool name.
14697
+ * @param _teammateUrl - Canonical teammate URL (kept for API compatibility, not used).
14698
+ * @param teammateLabel - Human-readable teammate label used as the basis for the name.
14699
+ * @returns TEAM tool name derived from the label.
14704
14700
  * @private internal utility of TEAM commitments and chat UI mapping
14705
14701
  */
14706
- function createTeamToolName(teammateUrl, teammateLabel) {
14702
+ function createTeamToolName(_teammateUrl, teammateLabel) {
14707
14703
  const normalizedLabel = normalizeTeammateToolNamePart(teammateLabel);
14708
- const hash = computeHash(teammateUrl).substring(0, TEAM_TOOL_HASH_LENGTH);
14709
- return `${TEAM_TOOL_PREFIX}${normalizedLabel}_${hash}`;
14704
+ return `${TEAM_TOOL_PREFIX}${normalizedLabel}`;
14710
14705
  }
14711
14706
 
14712
14707
  const urlRegex = /https?:\/\/[^\s]+/gi;
@@ -14911,7 +14906,7 @@ class TeamCommitmentDefinition extends BaseCommitmentDefinition {
14911
14906
  `);
14912
14907
  }
14913
14908
  applyToAgentModelRequirements(requirements, content) {
14914
- var _a, _b;
14909
+ var _a, _b, _c;
14915
14910
  const trimmedContent = content.trim();
14916
14911
  if (!trimmedContent) {
14917
14912
  return requirements;
@@ -14923,14 +14918,18 @@ class TeamCommitmentDefinition extends BaseCommitmentDefinition {
14923
14918
  }
14924
14919
  const agentName = ((_a = requirements._metadata) === null || _a === void 0 ? void 0 : _a.agentName) || 'Agent';
14925
14920
  const existingTeammates = ((_b = requirements._metadata) === null || _b === void 0 ? void 0 : _b.teammates) || [];
14921
+ const preResolvedProfiles = (((_c = requirements._metadata) === null || _c === void 0 ? void 0 : _c.preResolvedTeammateProfiles) || {});
14926
14922
  const resolvedTeammates = resolveTeamTeammateLabels(trimmedContent, teammates);
14927
14923
  const teamEntries = resolvedTeammates.map((teammate) => {
14924
+ const profile = preResolvedProfiles[teammate.url];
14925
+ const resolvedLabel = (profile === null || profile === void 0 ? void 0 : profile.agentName) || teammate.label;
14928
14926
  const existingTeammate = existingTeammates.find((entry) => entry.url === teammate.url);
14929
14927
  return {
14930
14928
  toolName: ((existingTeammate === null || existingTeammate === void 0 ? void 0 : existingTeammate.toolName) ||
14931
- createTeamToolName(teammate.url, teammate.label)),
14932
- teammate,
14929
+ createTeamToolName(teammate.url, resolvedLabel)),
14930
+ teammate: { ...teammate, label: resolvedLabel },
14933
14931
  agentName,
14932
+ description: (profile === null || profile === void 0 ? void 0 : profile.personaDescription) || null,
14934
14933
  };
14935
14934
  });
14936
14935
  for (const entry of teamEntries) {
@@ -14942,9 +14941,12 @@ class TeamCommitmentDefinition extends BaseCommitmentDefinition {
14942
14941
  if (updatedTools.some((tool) => tool.name === entry.toolName)) {
14943
14942
  continue;
14944
14943
  }
14944
+ const toolDescription = entry.description
14945
+ ? `Consult teammate ${entry.teammate.label}\n${entry.description}`
14946
+ : `Consult teammate ${entry.teammate.label}`;
14945
14947
  updatedTools.push({
14946
14948
  name: entry.toolName,
14947
- description: `Consult teammate ${entry.teammate.label}`,
14949
+ description: toolDescription,
14948
14950
  parameters: {
14949
14951
  type: 'object',
14950
14952
  properties: {
@@ -14973,8 +14975,7 @@ class TeamCommitmentDefinition extends BaseCommitmentDefinition {
14973
14975
  toolName: entry.toolName,
14974
14976
  });
14975
14977
  }
14976
- const teamOverviewText = createTeamOverviewText(trimmedContent, teamEntries);
14977
- const teamSystemMessage = this.createSystemMessageSection('Teammates:', buildTeamSystemMessageBody(teamOverviewText, teamEntries));
14978
+ const teamSystemMessage = this.createSystemMessageSection('Teammates:', buildTeamSystemMessageBody(teamEntries));
14978
14979
  return this.appendToSystemMessage({
14979
14980
  ...requirements,
14980
14981
  tools: updatedTools,
@@ -15011,25 +15012,24 @@ function resolveTeamTeammateLabels(teamContent, teammates) {
15011
15012
  };
15012
15013
  });
15013
15014
  }
15014
- /**
15015
- * Rewrites TEAM commitment content into a URL-free teammate overview text.
15016
- */
15017
- function createTeamOverviewText(teamContent, teamEntries) {
15018
- let overviewText = teamContent;
15019
- for (const entry of teamEntries) {
15020
- overviewText = overviewText.split(entry.teammate.url).join(entry.teammate.label);
15021
- }
15022
- return overviewText.trim();
15023
- }
15024
15015
  /**
15025
15016
  * Builds the textual TEAM section body for the final system message.
15017
+ *
15018
+ * Each teammate is listed with its tool name and, when available, a one-line description.
15019
+ * Uses `spaceTrim` to ensure consistent whitespace and indentation.
15026
15020
  */
15027
- function buildTeamSystemMessageBody(teamOverviewText, teamEntries) {
15028
- const teammateLines = teamEntries.map((entry, index) => `${index + 1}) ${entry.teammate.label} tool \`${entry.toolName}\``);
15029
- if (!teamOverviewText) {
15030
- return teammateLines.join('\n');
15031
- }
15032
- return `${teamOverviewText}\n\n${teammateLines.join('\n')}`;
15021
+ function buildTeamSystemMessageBody(teamEntries) {
15022
+ const lines = teamEntries.map((entry, index) => {
15023
+ const toolLine = `${index + 1}) ${entry.teammate.label} tool \`${entry.toolName}\``;
15024
+ if (!entry.description) {
15025
+ return toolLine;
15026
+ }
15027
+ return spaceTrim$1(`
15028
+ ${toolLine}
15029
+ ${entry.description}
15030
+ `);
15031
+ });
15032
+ return lines.join('\n');
15033
15033
  }
15034
15034
  /**
15035
15035
  * Registers tool function and title for a teammate tool.
@@ -21782,7 +21782,7 @@ function getSafeReferenceCommitmentFallback(commitmentType, originalContent) {
21782
21782
  * @private @@@
21783
21783
  */
21784
21784
  async function createAgentModelRequirementsWithCommitments(agentSource, modelName, options) {
21785
- var _a;
21785
+ var _a, _b, _c;
21786
21786
  const agentReferenceResolver = options === null || options === void 0 ? void 0 : options.agentReferenceResolver;
21787
21787
  // Parse the agent source to extract commitments
21788
21788
  const parseResult = parseAgentSourceWithCommitments(agentSource);
@@ -21850,6 +21850,36 @@ async function createAgentModelRequirementsWithCommitments(agentSource, modelNam
21850
21850
  if (commitment.type === 'CLOSED' && i !== filteredCommitments.length - 1) {
21851
21851
  continue;
21852
21852
  }
21853
+ // For TEAM commitments, pre-resolve teammate profiles if a resolver is provided
21854
+ // and store them in metadata before the commitment is applied.
21855
+ const profileResolver = (_a = options === null || options === void 0 ? void 0 : options.teammateProfileResolver) !== null && _a !== void 0 ? _a : options === null || options === void 0 ? void 0 : options.agentReferenceResolver;
21856
+ if (commitment.type === 'TEAM' && (profileResolver === null || profileResolver === void 0 ? void 0 : profileResolver.resolveTeammateProfile)) {
21857
+ try {
21858
+ const parsedTeammates = parseTeamCommitmentContent(commitmentContent, { strict: false });
21859
+ const preResolved = {
21860
+ ...(_b = requirements._metadata) === null || _b === void 0 ? void 0 : _b.preResolvedTeammateProfiles,
21861
+ };
21862
+ for (const teammate of parsedTeammates) {
21863
+ if (preResolved[teammate.url]) {
21864
+ continue;
21865
+ }
21866
+ const profile = await profileResolver.resolveTeammateProfile(teammate.url);
21867
+ if (profile) {
21868
+ preResolved[teammate.url] = profile;
21869
+ }
21870
+ }
21871
+ requirements = {
21872
+ ...requirements,
21873
+ _metadata: {
21874
+ ...requirements._metadata,
21875
+ preResolvedTeammateProfiles: preResolved,
21876
+ },
21877
+ };
21878
+ }
21879
+ catch (error) {
21880
+ console.warn('Failed to pre-resolve teammate profiles for TEAM commitment:', error);
21881
+ }
21882
+ }
21853
21883
  const definition = getCommitmentDefinition(commitment.type);
21854
21884
  if (definition) {
21855
21885
  try {
@@ -21945,7 +21975,7 @@ async function createAgentModelRequirementsWithCommitments(agentSource, modelNam
21945
21975
  // Add example interactions to the system message
21946
21976
  const examples = [];
21947
21977
  // 1. Initial message as an example agent response
21948
- const initialMessage = (_a = parseResult.commitments.find((c) => c.type === 'INITIAL MESSAGE')) === null || _a === void 0 ? void 0 : _a.content;
21978
+ const initialMessage = (_c = parseResult.commitments.find((c) => c.type === 'INITIAL MESSAGE')) === null || _c === void 0 ? void 0 : _c.content;
21949
21979
  if (initialMessage) {
21950
21980
  examples.push(`Agent: ${initialMessage}`);
21951
21981
  }
@@ -33701,6 +33731,7 @@ class SelfLearningManager {
33701
33731
 
33702
33732
  - Decide what the agent should learn from this interaction.
33703
33733
  - Append new commitments at the end of the agent source.
33734
+ - Return only newly learned commitments, never repeat commitments that are already present.
33704
33735
  - Do not modify the current agent source, just return new commitments (KNOWLEDGE, RULE, etc.).
33705
33736
  - If there is nothing new to learn, return empty book code block
33706
33737
  - Wrap the commitments in a book code block.
@@ -33753,10 +33784,42 @@ class SelfLearningManager {
33753
33784
  */
33754
33785
  appendToAgentSource(section) {
33755
33786
  const currentSource = this.options.getAgentSource();
33756
- const newSource = padBook(validateBook(spaceTrim$1(currentSource) + section));
33787
+ const normalizedSection = normalizeBookSection(section);
33788
+ if (!normalizedSection) {
33789
+ return;
33790
+ }
33791
+ if (containsNormalizedBookSection(currentSource, normalizedSection)) {
33792
+ return;
33793
+ }
33794
+ const newSource = padBook(validateBook(`${normalizeBookSection(currentSource)}\n\n${normalizedSection}`));
33757
33795
  this.options.updateAgentSource(newSource);
33758
33796
  }
33759
33797
  }
33798
+ /**
33799
+ * Normalizes one book fragment for deduplication and append composition.
33800
+ *
33801
+ * @param section Raw fragment from self-learning workflow.
33802
+ * @returns Trimmed fragment, or empty string when nothing remains.
33803
+ * @private function of Agent
33804
+ */
33805
+ function normalizeBookSection(section) {
33806
+ return spaceTrim$1(section).replace(/\r\n/g, '\n');
33807
+ }
33808
+ /**
33809
+ * Checks whether one normalized fragment already exists inside the current source.
33810
+ *
33811
+ * @param agentSource Current source.
33812
+ * @param normalizedSection Candidate fragment expected to be normalized first.
33813
+ * @returns True when appending would duplicate an existing fragment.
33814
+ * @private function of Agent
33815
+ */
33816
+ function containsNormalizedBookSection(agentSource, normalizedSection) {
33817
+ if (!normalizedSection) {
33818
+ return true;
33819
+ }
33820
+ const normalizedSource = normalizeBookSection(agentSource);
33821
+ return normalizedSource.includes(normalizedSection);
33822
+ }
33760
33823
  /**
33761
33824
  * Determines whether the interaction runs in OpenAI-compatible JSON schema mode.
33762
33825
  *
@@ -34484,13 +34547,23 @@ function getToolCallIdentity(toolCall) {
34484
34547
  */
34485
34548
  function mergeToolCalls(existingToolCalls, incomingToolCalls) {
34486
34549
  if (!existingToolCalls || existingToolCalls.length === 0) {
34487
- return incomingToolCalls ? [...incomingToolCalls] : [];
34550
+ return incomingToolCalls ? deduplicatePreparationToolCalls([...incomingToolCalls]) : [];
34488
34551
  }
34489
34552
  if (!incomingToolCalls || incomingToolCalls.length === 0) {
34490
34553
  return [...existingToolCalls];
34491
34554
  }
34492
34555
  const mergedToolCalls = [...existingToolCalls];
34493
34556
  for (const incomingToolCall of incomingToolCalls) {
34557
+ if (isAssistantPreparationToolCall(incomingToolCall)) {
34558
+ // A new preparation phase always replaces any previous assistant_preparation tool
34559
+ // call, regardless of phase argument, so only one chip is ever shown at a time.
34560
+ const existingPreparationIndex = mergedToolCalls.findIndex(isAssistantPreparationToolCall);
34561
+ if (existingPreparationIndex !== -1) {
34562
+ mergedToolCalls.splice(existingPreparationIndex, 1);
34563
+ }
34564
+ mergedToolCalls.push(incomingToolCall);
34565
+ continue;
34566
+ }
34494
34567
  const incomingIdentity = getToolCallIdentity(incomingToolCall);
34495
34568
  const existingIndex = mergedToolCalls.findIndex((existingToolCall) => getToolCallIdentity(existingToolCall) === incomingIdentity);
34496
34569
  if (existingIndex === -1) {
@@ -34602,6 +34675,30 @@ function serializeValueForMerge(value) {
34602
34675
  return String(value);
34603
34676
  }
34604
34677
  }
34678
+ /**
34679
+ * Ensures at most one `assistant_preparation` tool call survives in the list,
34680
+ * keeping the last occurrence so the most recent preparation phase is shown.
34681
+ *
34682
+ * @param toolCalls - Mutable list to deduplicate in-place.
34683
+ * @returns The same array after removing redundant preparation entries.
34684
+ * @private helper of `mergeToolCalls`
34685
+ */
34686
+ function deduplicatePreparationToolCalls(toolCalls) {
34687
+ let lastPreparationIndex = -1;
34688
+ for (let index = toolCalls.length - 1; index >= 0; index--) {
34689
+ if (!isAssistantPreparationToolCall(toolCalls[index])) {
34690
+ continue;
34691
+ }
34692
+ if (lastPreparationIndex === -1) {
34693
+ lastPreparationIndex = index;
34694
+ }
34695
+ else {
34696
+ // Remove earlier duplicate — keep only the last (most recent) one.
34697
+ toolCalls.splice(index, 1);
34698
+ }
34699
+ }
34700
+ return toolCalls;
34701
+ }
34605
34702
 
34606
34703
  /**
34607
34704
  * Parses one failed remote agent response into a structured error.