@promptbook/core 0.112.0-30 → 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
@@ -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-31';
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
@@ -33701,6 +33701,7 @@ class SelfLearningManager {
33701
33701
 
33702
33702
  - Decide what the agent should learn from this interaction.
33703
33703
  - Append new commitments at the end of the agent source.
33704
+ - Return only newly learned commitments, never repeat commitments that are already present.
33704
33705
  - Do not modify the current agent source, just return new commitments (KNOWLEDGE, RULE, etc.).
33705
33706
  - If there is nothing new to learn, return empty book code block
33706
33707
  - Wrap the commitments in a book code block.
@@ -33753,10 +33754,42 @@ class SelfLearningManager {
33753
33754
  */
33754
33755
  appendToAgentSource(section) {
33755
33756
  const currentSource = this.options.getAgentSource();
33756
- const newSource = padBook(validateBook(spaceTrim$1(currentSource) + section));
33757
+ const normalizedSection = normalizeBookSection(section);
33758
+ if (!normalizedSection) {
33759
+ return;
33760
+ }
33761
+ if (containsNormalizedBookSection(currentSource, normalizedSection)) {
33762
+ return;
33763
+ }
33764
+ const newSource = padBook(validateBook(`${normalizeBookSection(currentSource)}\n\n${normalizedSection}`));
33757
33765
  this.options.updateAgentSource(newSource);
33758
33766
  }
33759
33767
  }
33768
+ /**
33769
+ * Normalizes one book fragment for deduplication and append composition.
33770
+ *
33771
+ * @param section Raw fragment from self-learning workflow.
33772
+ * @returns Trimmed fragment, or empty string when nothing remains.
33773
+ * @private function of Agent
33774
+ */
33775
+ function normalizeBookSection(section) {
33776
+ return spaceTrim$1(section).replace(/\r\n/g, '\n');
33777
+ }
33778
+ /**
33779
+ * Checks whether one normalized fragment already exists inside the current source.
33780
+ *
33781
+ * @param agentSource Current source.
33782
+ * @param normalizedSection Candidate fragment expected to be normalized first.
33783
+ * @returns True when appending would duplicate an existing fragment.
33784
+ * @private function of Agent
33785
+ */
33786
+ function containsNormalizedBookSection(agentSource, normalizedSection) {
33787
+ if (!normalizedSection) {
33788
+ return true;
33789
+ }
33790
+ const normalizedSource = normalizeBookSection(agentSource);
33791
+ return normalizedSource.includes(normalizedSection);
33792
+ }
33760
33793
  /**
33761
33794
  * Determines whether the interaction runs in OpenAI-compatible JSON schema mode.
33762
33795
  *