@promptbook/browser 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 +2 -2
  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
@@ -29,7 +29,7 @@ const BOOK_LANGUAGE_VERSION = '2.0.0';
29
29
  * @generated
30
30
  * @see https://github.com/webgptorg/promptbook
31
31
  */
32
- const PROMPTBOOK_ENGINE_VERSION = '0.112.0-30';
32
+ const PROMPTBOOK_ENGINE_VERSION = '0.112.0-32';
33
33
  /**
34
34
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
35
35
  * Note: [💞] Ignore a discrepancy between file name and entity name
@@ -9900,10 +9900,6 @@ class StyleCommitmentDefinition extends BaseCommitmentDefinition {
9900
9900
  * Prefix used for TEAM tool names.
9901
9901
  */
9902
9902
  const TEAM_TOOL_PREFIX = 'team_chat_';
9903
- /**
9904
- * Length of URL hash suffix appended to TEAM tool names.
9905
- */
9906
- const TEAM_TOOL_HASH_LENGTH = 10;
9907
9903
  /**
9908
9904
  * Fallback normalized name when teammate label is empty.
9909
9905
  */
@@ -9920,20 +9916,19 @@ function normalizeTeammateToolNamePart(teammateLabel) {
9920
9916
  return normalized || TEAM_TOOL_FALLBACK_NAME;
9921
9917
  }
9922
9918
  /**
9923
- * Builds a deterministic TEAM tool name from teammate identity.
9919
+ * Builds a deterministic TEAM tool name from the teammate label.
9924
9920
  *
9925
- * The readable part is based on teammate label while the hash suffix
9926
- * keeps uniqueness and stable mapping for the underlying teammate URL.
9921
+ * The tool name is derived solely from the human-readable label so that it
9922
+ * remains stable and predictable regardless of internal technical identifiers.
9927
9923
  *
9928
- * @param teammateUrl - Canonical teammate URL used at runtime.
9929
- * @param teammateLabel - Human-readable teammate label.
9930
- * @returns Deterministic TEAM tool name.
9924
+ * @param _teammateUrl - Canonical teammate URL (kept for API compatibility, not used).
9925
+ * @param teammateLabel - Human-readable teammate label used as the basis for the name.
9926
+ * @returns TEAM tool name derived from the label.
9931
9927
  * @private internal utility of TEAM commitments and chat UI mapping
9932
9928
  */
9933
- function createTeamToolName(teammateUrl, teammateLabel) {
9929
+ function createTeamToolName(_teammateUrl, teammateLabel) {
9934
9930
  const normalizedLabel = normalizeTeammateToolNamePart(teammateLabel);
9935
- const hash = computeHash(teammateUrl).substring(0, TEAM_TOOL_HASH_LENGTH);
9936
- return `${TEAM_TOOL_PREFIX}${normalizedLabel}_${hash}`;
9931
+ return `${TEAM_TOOL_PREFIX}${normalizedLabel}`;
9937
9932
  }
9938
9933
 
9939
9934
  const urlRegex = /https?:\/\/[^\s]+/gi;
@@ -10138,7 +10133,7 @@ class TeamCommitmentDefinition extends BaseCommitmentDefinition {
10138
10133
  `);
10139
10134
  }
10140
10135
  applyToAgentModelRequirements(requirements, content) {
10141
- var _a, _b;
10136
+ var _a, _b, _c;
10142
10137
  const trimmedContent = content.trim();
10143
10138
  if (!trimmedContent) {
10144
10139
  return requirements;
@@ -10150,14 +10145,18 @@ class TeamCommitmentDefinition extends BaseCommitmentDefinition {
10150
10145
  }
10151
10146
  const agentName = ((_a = requirements._metadata) === null || _a === void 0 ? void 0 : _a.agentName) || 'Agent';
10152
10147
  const existingTeammates = ((_b = requirements._metadata) === null || _b === void 0 ? void 0 : _b.teammates) || [];
10148
+ const preResolvedProfiles = (((_c = requirements._metadata) === null || _c === void 0 ? void 0 : _c.preResolvedTeammateProfiles) || {});
10153
10149
  const resolvedTeammates = resolveTeamTeammateLabels(trimmedContent, teammates);
10154
10150
  const teamEntries = resolvedTeammates.map((teammate) => {
10151
+ const profile = preResolvedProfiles[teammate.url];
10152
+ const resolvedLabel = (profile === null || profile === void 0 ? void 0 : profile.agentName) || teammate.label;
10155
10153
  const existingTeammate = existingTeammates.find((entry) => entry.url === teammate.url);
10156
10154
  return {
10157
10155
  toolName: ((existingTeammate === null || existingTeammate === void 0 ? void 0 : existingTeammate.toolName) ||
10158
- createTeamToolName(teammate.url, teammate.label)),
10159
- teammate,
10156
+ createTeamToolName(teammate.url, resolvedLabel)),
10157
+ teammate: { ...teammate, label: resolvedLabel },
10160
10158
  agentName,
10159
+ description: (profile === null || profile === void 0 ? void 0 : profile.personaDescription) || null,
10161
10160
  };
10162
10161
  });
10163
10162
  for (const entry of teamEntries) {
@@ -10169,9 +10168,12 @@ class TeamCommitmentDefinition extends BaseCommitmentDefinition {
10169
10168
  if (updatedTools.some((tool) => tool.name === entry.toolName)) {
10170
10169
  continue;
10171
10170
  }
10171
+ const toolDescription = entry.description
10172
+ ? `Consult teammate ${entry.teammate.label}\n${entry.description}`
10173
+ : `Consult teammate ${entry.teammate.label}`;
10172
10174
  updatedTools.push({
10173
10175
  name: entry.toolName,
10174
- description: `Consult teammate ${entry.teammate.label}`,
10176
+ description: toolDescription,
10175
10177
  parameters: {
10176
10178
  type: 'object',
10177
10179
  properties: {
@@ -10200,8 +10202,7 @@ class TeamCommitmentDefinition extends BaseCommitmentDefinition {
10200
10202
  toolName: entry.toolName,
10201
10203
  });
10202
10204
  }
10203
- const teamOverviewText = createTeamOverviewText(trimmedContent, teamEntries);
10204
- const teamSystemMessage = this.createSystemMessageSection('Teammates:', buildTeamSystemMessageBody(teamOverviewText, teamEntries));
10205
+ const teamSystemMessage = this.createSystemMessageSection('Teammates:', buildTeamSystemMessageBody(teamEntries));
10205
10206
  return this.appendToSystemMessage({
10206
10207
  ...requirements,
10207
10208
  tools: updatedTools,
@@ -10238,25 +10239,24 @@ function resolveTeamTeammateLabels(teamContent, teammates) {
10238
10239
  };
10239
10240
  });
10240
10241
  }
10241
- /**
10242
- * Rewrites TEAM commitment content into a URL-free teammate overview text.
10243
- */
10244
- function createTeamOverviewText(teamContent, teamEntries) {
10245
- let overviewText = teamContent;
10246
- for (const entry of teamEntries) {
10247
- overviewText = overviewText.split(entry.teammate.url).join(entry.teammate.label);
10248
- }
10249
- return overviewText.trim();
10250
- }
10251
10242
  /**
10252
10243
  * Builds the textual TEAM section body for the final system message.
10244
+ *
10245
+ * Each teammate is listed with its tool name and, when available, a one-line description.
10246
+ * Uses `spaceTrim` to ensure consistent whitespace and indentation.
10253
10247
  */
10254
- function buildTeamSystemMessageBody(teamOverviewText, teamEntries) {
10255
- const teammateLines = teamEntries.map((entry, index) => `${index + 1}) ${entry.teammate.label} tool \`${entry.toolName}\``);
10256
- if (!teamOverviewText) {
10257
- return teammateLines.join('\n');
10258
- }
10259
- return `${teamOverviewText}\n\n${teammateLines.join('\n')}`;
10248
+ function buildTeamSystemMessageBody(teamEntries) {
10249
+ const lines = teamEntries.map((entry, index) => {
10250
+ const toolLine = `${index + 1}) ${entry.teammate.label} tool \`${entry.toolName}\``;
10251
+ if (!entry.description) {
10252
+ return toolLine;
10253
+ }
10254
+ return spaceTrim$1(`
10255
+ ${toolLine}
10256
+ ${entry.description}
10257
+ `);
10258
+ });
10259
+ return lines.join('\n');
10260
10260
  }
10261
10261
  /**
10262
10262
  * Registers tool function and title for a teammate tool.
@@ -18282,13 +18282,23 @@ function getToolCallIdentity(toolCall) {
18282
18282
  */
18283
18283
  function mergeToolCalls(existingToolCalls, incomingToolCalls) {
18284
18284
  if (!existingToolCalls || existingToolCalls.length === 0) {
18285
- return incomingToolCalls ? [...incomingToolCalls] : [];
18285
+ return incomingToolCalls ? deduplicatePreparationToolCalls([...incomingToolCalls]) : [];
18286
18286
  }
18287
18287
  if (!incomingToolCalls || incomingToolCalls.length === 0) {
18288
18288
  return [...existingToolCalls];
18289
18289
  }
18290
18290
  const mergedToolCalls = [...existingToolCalls];
18291
18291
  for (const incomingToolCall of incomingToolCalls) {
18292
+ if (isAssistantPreparationToolCall(incomingToolCall)) {
18293
+ // A new preparation phase always replaces any previous assistant_preparation tool
18294
+ // call, regardless of phase argument, so only one chip is ever shown at a time.
18295
+ const existingPreparationIndex = mergedToolCalls.findIndex(isAssistantPreparationToolCall);
18296
+ if (existingPreparationIndex !== -1) {
18297
+ mergedToolCalls.splice(existingPreparationIndex, 1);
18298
+ }
18299
+ mergedToolCalls.push(incomingToolCall);
18300
+ continue;
18301
+ }
18292
18302
  const incomingIdentity = getToolCallIdentity(incomingToolCall);
18293
18303
  const existingIndex = mergedToolCalls.findIndex((existingToolCall) => getToolCallIdentity(existingToolCall) === incomingIdentity);
18294
18304
  if (existingIndex === -1) {
@@ -18400,6 +18410,30 @@ function serializeValueForMerge(value) {
18400
18410
  return String(value);
18401
18411
  }
18402
18412
  }
18413
+ /**
18414
+ * Ensures at most one `assistant_preparation` tool call survives in the list,
18415
+ * keeping the last occurrence so the most recent preparation phase is shown.
18416
+ *
18417
+ * @param toolCalls - Mutable list to deduplicate in-place.
18418
+ * @returns The same array after removing redundant preparation entries.
18419
+ * @private helper of `mergeToolCalls`
18420
+ */
18421
+ function deduplicatePreparationToolCalls(toolCalls) {
18422
+ let lastPreparationIndex = -1;
18423
+ for (let index = toolCalls.length - 1; index >= 0; index--) {
18424
+ if (!isAssistantPreparationToolCall(toolCalls[index])) {
18425
+ continue;
18426
+ }
18427
+ if (lastPreparationIndex === -1) {
18428
+ lastPreparationIndex = index;
18429
+ }
18430
+ else {
18431
+ // Remove earlier duplicate — keep only the last (most recent) one.
18432
+ toolCalls.splice(index, 1);
18433
+ }
18434
+ }
18435
+ return toolCalls;
18436
+ }
18403
18437
 
18404
18438
  /**
18405
18439
  * Gets all tool titles provided by all commitments
@@ -22655,7 +22689,7 @@ function getSafeReferenceCommitmentFallback(commitmentType, originalContent) {
22655
22689
  * @private @@@
22656
22690
  */
22657
22691
  async function createAgentModelRequirementsWithCommitments(agentSource, modelName, options) {
22658
- var _a;
22692
+ var _a, _b, _c;
22659
22693
  const agentReferenceResolver = options === null || options === void 0 ? void 0 : options.agentReferenceResolver;
22660
22694
  // Parse the agent source to extract commitments
22661
22695
  const parseResult = parseAgentSourceWithCommitments(agentSource);
@@ -22723,6 +22757,36 @@ async function createAgentModelRequirementsWithCommitments(agentSource, modelNam
22723
22757
  if (commitment.type === 'CLOSED' && i !== filteredCommitments.length - 1) {
22724
22758
  continue;
22725
22759
  }
22760
+ // For TEAM commitments, pre-resolve teammate profiles if a resolver is provided
22761
+ // and store them in metadata before the commitment is applied.
22762
+ 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;
22763
+ if (commitment.type === 'TEAM' && (profileResolver === null || profileResolver === void 0 ? void 0 : profileResolver.resolveTeammateProfile)) {
22764
+ try {
22765
+ const parsedTeammates = parseTeamCommitmentContent(commitmentContent, { strict: false });
22766
+ const preResolved = {
22767
+ ...(_b = requirements._metadata) === null || _b === void 0 ? void 0 : _b.preResolvedTeammateProfiles,
22768
+ };
22769
+ for (const teammate of parsedTeammates) {
22770
+ if (preResolved[teammate.url]) {
22771
+ continue;
22772
+ }
22773
+ const profile = await profileResolver.resolveTeammateProfile(teammate.url);
22774
+ if (profile) {
22775
+ preResolved[teammate.url] = profile;
22776
+ }
22777
+ }
22778
+ requirements = {
22779
+ ...requirements,
22780
+ _metadata: {
22781
+ ...requirements._metadata,
22782
+ preResolvedTeammateProfiles: preResolved,
22783
+ },
22784
+ };
22785
+ }
22786
+ catch (error) {
22787
+ console.warn('Failed to pre-resolve teammate profiles for TEAM commitment:', error);
22788
+ }
22789
+ }
22726
22790
  const definition = getCommitmentDefinition(commitment.type);
22727
22791
  if (definition) {
22728
22792
  try {
@@ -22818,7 +22882,7 @@ async function createAgentModelRequirementsWithCommitments(agentSource, modelNam
22818
22882
  // Add example interactions to the system message
22819
22883
  const examples = [];
22820
22884
  // 1. Initial message as an example agent response
22821
- const initialMessage = (_a = parseResult.commitments.find((c) => c.type === 'INITIAL MESSAGE')) === null || _a === void 0 ? void 0 : _a.content;
22885
+ const initialMessage = (_c = parseResult.commitments.find((c) => c.type === 'INITIAL MESSAGE')) === null || _c === void 0 ? void 0 : _c.content;
22822
22886
  if (initialMessage) {
22823
22887
  examples.push(`Agent: ${initialMessage}`);
22824
22888
  }
@@ -28663,6 +28727,7 @@ class SelfLearningManager {
28663
28727
 
28664
28728
  - Decide what the agent should learn from this interaction.
28665
28729
  - Append new commitments at the end of the agent source.
28730
+ - Return only newly learned commitments, never repeat commitments that are already present.
28666
28731
  - Do not modify the current agent source, just return new commitments (KNOWLEDGE, RULE, etc.).
28667
28732
  - If there is nothing new to learn, return empty book code block
28668
28733
  - Wrap the commitments in a book code block.
@@ -28715,10 +28780,42 @@ class SelfLearningManager {
28715
28780
  */
28716
28781
  appendToAgentSource(section) {
28717
28782
  const currentSource = this.options.getAgentSource();
28718
- const newSource = padBook(validateBook(spaceTrim$1(currentSource) + section));
28783
+ const normalizedSection = normalizeBookSection(section);
28784
+ if (!normalizedSection) {
28785
+ return;
28786
+ }
28787
+ if (containsNormalizedBookSection(currentSource, normalizedSection)) {
28788
+ return;
28789
+ }
28790
+ const newSource = padBook(validateBook(`${normalizeBookSection(currentSource)}\n\n${normalizedSection}`));
28719
28791
  this.options.updateAgentSource(newSource);
28720
28792
  }
28721
28793
  }
28794
+ /**
28795
+ * Normalizes one book fragment for deduplication and append composition.
28796
+ *
28797
+ * @param section Raw fragment from self-learning workflow.
28798
+ * @returns Trimmed fragment, or empty string when nothing remains.
28799
+ * @private function of Agent
28800
+ */
28801
+ function normalizeBookSection(section) {
28802
+ return spaceTrim$1(section).replace(/\r\n/g, '\n');
28803
+ }
28804
+ /**
28805
+ * Checks whether one normalized fragment already exists inside the current source.
28806
+ *
28807
+ * @param agentSource Current source.
28808
+ * @param normalizedSection Candidate fragment expected to be normalized first.
28809
+ * @returns True when appending would duplicate an existing fragment.
28810
+ * @private function of Agent
28811
+ */
28812
+ function containsNormalizedBookSection(agentSource, normalizedSection) {
28813
+ if (!normalizedSection) {
28814
+ return true;
28815
+ }
28816
+ const normalizedSource = normalizeBookSection(agentSource);
28817
+ return normalizedSource.includes(normalizedSection);
28818
+ }
28722
28819
  /**
28723
28820
  * Determines whether the interaction runs in OpenAI-compatible JSON schema mode.
28724
28821
  *