@promptbook/core 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
@@ -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-29';
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
@@ -15464,7 +15464,11 @@ class UseCommitmentDefinition extends BaseCommitmentDefinition {
15464
15464
  *
15465
15465
  * @private internal constant for `aggregateUseCommitmentSystemMessages`
15466
15466
  */
15467
- const AGGREGATED_USE_COMMITMENT_TYPES = ['USE BROWSER', 'USE SEARCH ENGINE', 'USE TIME'];
15467
+ const AGGREGATED_USE_COMMITMENT_TYPES = [
15468
+ 'USE BROWSER',
15469
+ 'USE SEARCH ENGINE',
15470
+ 'USE TIME',
15471
+ ];
15468
15472
  /**
15469
15473
  * Prefix used for temporary in-system-message placeholders that preserve the first-occurrence position of aggregated `USE` sections.
15470
15474
  *
@@ -33697,6 +33701,7 @@ class SelfLearningManager {
33697
33701
 
33698
33702
  - Decide what the agent should learn from this interaction.
33699
33703
  - Append new commitments at the end of the agent source.
33704
+ - Return only newly learned commitments, never repeat commitments that are already present.
33700
33705
  - Do not modify the current agent source, just return new commitments (KNOWLEDGE, RULE, etc.).
33701
33706
  - If there is nothing new to learn, return empty book code block
33702
33707
  - Wrap the commitments in a book code block.
@@ -33749,10 +33754,42 @@ class SelfLearningManager {
33749
33754
  */
33750
33755
  appendToAgentSource(section) {
33751
33756
  const currentSource = this.options.getAgentSource();
33752
- 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}`));
33753
33765
  this.options.updateAgentSource(newSource);
33754
33766
  }
33755
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
+ }
33756
33793
  /**
33757
33794
  * Determines whether the interaction runs in OpenAI-compatible JSON schema mode.
33758
33795
  *