@promptbook/node 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
@@ -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-29';
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
@@ -19188,7 +19188,11 @@ class UseCommitmentDefinition extends BaseCommitmentDefinition {
19188
19188
  *
19189
19189
  * @private internal constant for `aggregateUseCommitmentSystemMessages`
19190
19190
  */
19191
- const AGGREGATED_USE_COMMITMENT_TYPES = ['USE BROWSER', 'USE SEARCH ENGINE', 'USE TIME'];
19191
+ const AGGREGATED_USE_COMMITMENT_TYPES = [
19192
+ 'USE BROWSER',
19193
+ 'USE SEARCH ENGINE',
19194
+ 'USE TIME',
19195
+ ];
19192
19196
  /**
19193
19197
  * Prefix used for temporary in-system-message placeholders that preserve the first-occurrence position of aggregated `USE` sections.
19194
19198
  *
@@ -34111,6 +34115,7 @@ class SelfLearningManager {
34111
34115
 
34112
34116
  - Decide what the agent should learn from this interaction.
34113
34117
  - Append new commitments at the end of the agent source.
34118
+ - Return only newly learned commitments, never repeat commitments that are already present.
34114
34119
  - Do not modify the current agent source, just return new commitments (KNOWLEDGE, RULE, etc.).
34115
34120
  - If there is nothing new to learn, return empty book code block
34116
34121
  - Wrap the commitments in a book code block.
@@ -34163,10 +34168,42 @@ class SelfLearningManager {
34163
34168
  */
34164
34169
  appendToAgentSource(section) {
34165
34170
  const currentSource = this.options.getAgentSource();
34166
- 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}`));
34167
34179
  this.options.updateAgentSource(newSource);
34168
34180
  }
34169
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
+ }
34170
34207
  /**
34171
34208
  * Determines whether the interaction runs in OpenAI-compatible JSON schema mode.
34172
34209
  *