@promptbook/browser 0.112.0-29 → 0.112.0-31

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
@@ -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-29';
32
+ const PROMPTBOOK_ENGINE_VERSION = '0.112.0-31';
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
@@ -10691,7 +10691,11 @@ class UseCommitmentDefinition extends BaseCommitmentDefinition {
10691
10691
  *
10692
10692
  * @private internal constant for `aggregateUseCommitmentSystemMessages`
10693
10693
  */
10694
- const AGGREGATED_USE_COMMITMENT_TYPES = ['USE BROWSER', 'USE SEARCH ENGINE', 'USE TIME'];
10694
+ const AGGREGATED_USE_COMMITMENT_TYPES = [
10695
+ 'USE BROWSER',
10696
+ 'USE SEARCH ENGINE',
10697
+ 'USE TIME',
10698
+ ];
10695
10699
  /**
10696
10700
  * Prefix used for temporary in-system-message placeholders that preserve the first-occurrence position of aggregated `USE` sections.
10697
10701
  *
@@ -28659,6 +28663,7 @@ class SelfLearningManager {
28659
28663
 
28660
28664
  - Decide what the agent should learn from this interaction.
28661
28665
  - Append new commitments at the end of the agent source.
28666
+ - Return only newly learned commitments, never repeat commitments that are already present.
28662
28667
  - Do not modify the current agent source, just return new commitments (KNOWLEDGE, RULE, etc.).
28663
28668
  - If there is nothing new to learn, return empty book code block
28664
28669
  - Wrap the commitments in a book code block.
@@ -28711,10 +28716,42 @@ class SelfLearningManager {
28711
28716
  */
28712
28717
  appendToAgentSource(section) {
28713
28718
  const currentSource = this.options.getAgentSource();
28714
- const newSource = padBook(validateBook(spaceTrim$1(currentSource) + section));
28719
+ const normalizedSection = normalizeBookSection(section);
28720
+ if (!normalizedSection) {
28721
+ return;
28722
+ }
28723
+ if (containsNormalizedBookSection(currentSource, normalizedSection)) {
28724
+ return;
28725
+ }
28726
+ const newSource = padBook(validateBook(`${normalizeBookSection(currentSource)}\n\n${normalizedSection}`));
28715
28727
  this.options.updateAgentSource(newSource);
28716
28728
  }
28717
28729
  }
28730
+ /**
28731
+ * Normalizes one book fragment for deduplication and append composition.
28732
+ *
28733
+ * @param section Raw fragment from self-learning workflow.
28734
+ * @returns Trimmed fragment, or empty string when nothing remains.
28735
+ * @private function of Agent
28736
+ */
28737
+ function normalizeBookSection(section) {
28738
+ return spaceTrim$1(section).replace(/\r\n/g, '\n');
28739
+ }
28740
+ /**
28741
+ * Checks whether one normalized fragment already exists inside the current source.
28742
+ *
28743
+ * @param agentSource Current source.
28744
+ * @param normalizedSection Candidate fragment expected to be normalized first.
28745
+ * @returns True when appending would duplicate an existing fragment.
28746
+ * @private function of Agent
28747
+ */
28748
+ function containsNormalizedBookSection(agentSource, normalizedSection) {
28749
+ if (!normalizedSection) {
28750
+ return true;
28751
+ }
28752
+ const normalizedSource = normalizeBookSection(agentSource);
28753
+ return normalizedSource.includes(normalizedSection);
28754
+ }
28718
28755
  /**
28719
28756
  * Determines whether the interaction runs in OpenAI-compatible JSON schema mode.
28720
28757
  *