@promptbook/node 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
@@ -35,7 +35,7 @@ const BOOK_LANGUAGE_VERSION = '2.0.0';
35
35
  * @generated
36
36
  * @see https://github.com/webgptorg/promptbook
37
37
  */
38
- const PROMPTBOOK_ENGINE_VERSION = '0.112.0-30';
38
+ const PROMPTBOOK_ENGINE_VERSION = '0.112.0-31';
39
39
  /**
40
40
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
41
41
  * Note: [💞] Ignore a discrepancy between file name and entity name
@@ -34115,6 +34115,7 @@ class SelfLearningManager {
34115
34115
 
34116
34116
  - Decide what the agent should learn from this interaction.
34117
34117
  - Append new commitments at the end of the agent source.
34118
+ - Return only newly learned commitments, never repeat commitments that are already present.
34118
34119
  - Do not modify the current agent source, just return new commitments (KNOWLEDGE, RULE, etc.).
34119
34120
  - If there is nothing new to learn, return empty book code block
34120
34121
  - Wrap the commitments in a book code block.
@@ -34167,10 +34168,42 @@ class SelfLearningManager {
34167
34168
  */
34168
34169
  appendToAgentSource(section) {
34169
34170
  const currentSource = this.options.getAgentSource();
34170
- const newSource = padBook(validateBook(spaceTrim$1(currentSource) + section));
34171
+ const normalizedSection = normalizeBookSection(section);
34172
+ if (!normalizedSection) {
34173
+ return;
34174
+ }
34175
+ if (containsNormalizedBookSection(currentSource, normalizedSection)) {
34176
+ return;
34177
+ }
34178
+ const newSource = padBook(validateBook(`${normalizeBookSection(currentSource)}\n\n${normalizedSection}`));
34171
34179
  this.options.updateAgentSource(newSource);
34172
34180
  }
34173
34181
  }
34182
+ /**
34183
+ * Normalizes one book fragment for deduplication and append composition.
34184
+ *
34185
+ * @param section Raw fragment from self-learning workflow.
34186
+ * @returns Trimmed fragment, or empty string when nothing remains.
34187
+ * @private function of Agent
34188
+ */
34189
+ function normalizeBookSection(section) {
34190
+ return spaceTrim$1(section).replace(/\r\n/g, '\n');
34191
+ }
34192
+ /**
34193
+ * Checks whether one normalized fragment already exists inside the current source.
34194
+ *
34195
+ * @param agentSource Current source.
34196
+ * @param normalizedSection Candidate fragment expected to be normalized first.
34197
+ * @returns True when appending would duplicate an existing fragment.
34198
+ * @private function of Agent
34199
+ */
34200
+ function containsNormalizedBookSection(agentSource, normalizedSection) {
34201
+ if (!normalizedSection) {
34202
+ return true;
34203
+ }
34204
+ const normalizedSource = normalizeBookSection(agentSource);
34205
+ return normalizedSource.includes(normalizedSection);
34206
+ }
34174
34207
  /**
34175
34208
  * Determines whether the interaction runs in OpenAI-compatible JSON schema mode.
34176
34209
  *