@promptbook/wizard 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
@@ -38,7 +38,7 @@ const BOOK_LANGUAGE_VERSION = '2.0.0';
38
38
  * @generated
39
39
  * @see https://github.com/webgptorg/promptbook
40
40
  */
41
- const PROMPTBOOK_ENGINE_VERSION = '0.112.0-30';
41
+ const PROMPTBOOK_ENGINE_VERSION = '0.112.0-31';
42
42
  /**
43
43
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
44
44
  * Note: [💞] Ignore a discrepancy between file name and entity name
@@ -38976,6 +38976,7 @@ class SelfLearningManager {
38976
38976
 
38977
38977
  - Decide what the agent should learn from this interaction.
38978
38978
  - Append new commitments at the end of the agent source.
38979
+ - Return only newly learned commitments, never repeat commitments that are already present.
38979
38980
  - Do not modify the current agent source, just return new commitments (KNOWLEDGE, RULE, etc.).
38980
38981
  - If there is nothing new to learn, return empty book code block
38981
38982
  - Wrap the commitments in a book code block.
@@ -39028,10 +39029,42 @@ class SelfLearningManager {
39028
39029
  */
39029
39030
  appendToAgentSource(section) {
39030
39031
  const currentSource = this.options.getAgentSource();
39031
- const newSource = padBook(validateBook(spaceTrim$1(currentSource) + section));
39032
+ const normalizedSection = normalizeBookSection(section);
39033
+ if (!normalizedSection) {
39034
+ return;
39035
+ }
39036
+ if (containsNormalizedBookSection(currentSource, normalizedSection)) {
39037
+ return;
39038
+ }
39039
+ const newSource = padBook(validateBook(`${normalizeBookSection(currentSource)}\n\n${normalizedSection}`));
39032
39040
  this.options.updateAgentSource(newSource);
39033
39041
  }
39034
39042
  }
39043
+ /**
39044
+ * Normalizes one book fragment for deduplication and append composition.
39045
+ *
39046
+ * @param section Raw fragment from self-learning workflow.
39047
+ * @returns Trimmed fragment, or empty string when nothing remains.
39048
+ * @private function of Agent
39049
+ */
39050
+ function normalizeBookSection(section) {
39051
+ return spaceTrim$1(section).replace(/\r\n/g, '\n');
39052
+ }
39053
+ /**
39054
+ * Checks whether one normalized fragment already exists inside the current source.
39055
+ *
39056
+ * @param agentSource Current source.
39057
+ * @param normalizedSection Candidate fragment expected to be normalized first.
39058
+ * @returns True when appending would duplicate an existing fragment.
39059
+ * @private function of Agent
39060
+ */
39061
+ function containsNormalizedBookSection(agentSource, normalizedSection) {
39062
+ if (!normalizedSection) {
39063
+ return true;
39064
+ }
39065
+ const normalizedSource = normalizeBookSection(agentSource);
39066
+ return normalizedSource.includes(normalizedSection);
39067
+ }
39035
39068
  /**
39036
39069
  * Determines whether the interaction runs in OpenAI-compatible JSON schema mode.
39037
39070
  *