agenr 2.1.0 → 3.0.0

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.
@@ -1,10 +1,10 @@
1
1
  import {
2
2
  projectClaimCentricRecallEntry,
3
3
  runProcedureRecall
4
- } from "./chunk-7TDALVPY.js";
4
+ } from "./chunk-ELR2HSVC.js";
5
5
  import {
6
6
  recall
7
- } from "./chunk-6T5RXGIR.js";
7
+ } from "./chunk-5LADPJ4C.js";
8
8
 
9
9
  // src/app/before-turn/service.ts
10
10
  var DEFAULT_MAX_DURABLE_ENTRIES = 1;
@@ -764,7 +764,194 @@ function formatErrorMessage(error) {
764
764
  return String(error);
765
765
  }
766
766
 
767
- // src/adapters/openclaw/format/memory-context.ts
767
+ // src/adapters/shared/memory-tool-format.ts
768
+ var DEFAULT_RECALL_LIMIT = 10;
769
+ var RESULT_SUBJECT_LOG_LIMIT = 5;
770
+ function truncate2(value, maxChars) {
771
+ if (value.length <= maxChars) {
772
+ return value;
773
+ }
774
+ return `${value.slice(0, maxChars - 3).trimEnd()}...`;
775
+ }
776
+ function sanitizeStoreToolParams(params) {
777
+ return {
778
+ type: params.type,
779
+ subject: params.subject,
780
+ ...params.importance !== void 0 ? { importance: params.importance } : {},
781
+ ...params.expiry !== void 0 ? { expiry: params.expiry } : {},
782
+ ...params.tags.length > 0 ? { tags: params.tags } : {},
783
+ contentLength: params.content.length,
784
+ ...params.sourceContext !== void 0 ? { sourceContextLength: params.sourceContext.length } : {},
785
+ ...params.supersedes !== void 0 ? { hasSupersedes: true } : {},
786
+ ...params.claimKey !== void 0 ? { hasClaimKey: true } : {},
787
+ ...params.validFrom !== void 0 ? { hasValidFrom: true } : {},
788
+ ...params.validTo !== void 0 ? { hasValidTo: true } : {}
789
+ };
790
+ }
791
+ function formatRecallToolSummary(params) {
792
+ const parts = [`query=${JSON.stringify(truncate2(params.query, 80))}`];
793
+ if (params.mode) {
794
+ parts.push(`mode=${params.mode}`);
795
+ }
796
+ if (params.limit !== void 0 && params.limit !== DEFAULT_RECALL_LIMIT) {
797
+ parts.push(`limit=${params.limit}`);
798
+ }
799
+ if (params.types.length > 0) {
800
+ parts.push(`types=${JSON.stringify(params.types)}`);
801
+ }
802
+ if (params.tags.length > 0) {
803
+ parts.push(`tags=${JSON.stringify(params.tags)}`);
804
+ }
805
+ if (params.asOf) {
806
+ parts.push(`as_of=${JSON.stringify(params.asOf)}`);
807
+ }
808
+ return parts.join(" ");
809
+ }
810
+ function sanitizeRecallToolParams(params) {
811
+ return {
812
+ query: params.query,
813
+ ...params.mode ? { mode: params.mode } : {},
814
+ ...params.limit !== void 0 ? { limit: params.limit } : {},
815
+ ...params.threshold !== void 0 ? { threshold: params.threshold } : {},
816
+ ...params.types.length > 0 ? { types: params.types } : {},
817
+ ...params.tags.length > 0 ? { tags: params.tags } : {},
818
+ ...params.asOf ? { asOf: params.asOf } : {}
819
+ };
820
+ }
821
+ function formatUnifiedRecallLogSummary(result) {
822
+ const procedureCount = result.procedureCandidates.length;
823
+ const procedureSummary = result.procedure ? ` [procedure: ${JSON.stringify(truncate2(result.procedure.title, 80))}]` : "";
824
+ const entrySubjects = result.entries.map((entry) => entry.entry.subject.trim()).filter((subject) => subject.length > 0);
825
+ const displayed = entrySubjects.slice(0, RESULT_SUBJECT_LOG_LIMIT).map((subject) => JSON.stringify(truncate2(subject, 80)));
826
+ const remaining = entrySubjects.length - RESULT_SUBJECT_LOG_LIMIT;
827
+ const suffix = displayed.length === 0 ? "" : ` [entry subjects: ${displayed.join(", ")}${remaining > 0 ? `, ... and ${remaining} more` : ""}]`;
828
+ const entryEpisodeSummary = `${result.episodes.length} episode${result.episodes.length === 1 ? "" : "s"}, ${result.entries.length} entr${result.entries.length === 1 ? "y" : "ies"}`;
829
+ if (procedureCount === 0 && !result.procedure) {
830
+ return `${entryEpisodeSummary}${suffix}`;
831
+ }
832
+ return `${procedureCount} procedure candidate${procedureCount === 1 ? "" : "s"}, ${entryEpisodeSummary}${procedureSummary}${suffix}`;
833
+ }
834
+ function buildRecallToolDetails(result, extraDetails = {}) {
835
+ return {
836
+ status: "ok",
837
+ count: result.count,
838
+ ...extraDetails,
839
+ routing: {
840
+ requested: result.routing.requested,
841
+ detectedIntent: result.routing.detectedIntent,
842
+ queried: result.routing.queried,
843
+ reason: result.routing.reason
844
+ },
845
+ ...result.asOf ? { asOf: result.asOf } : {},
846
+ ...result.timeWindow ? { timeWindow: result.timeWindow } : {},
847
+ ...result.procedure ? {
848
+ procedure: {
849
+ id: result.procedure.id,
850
+ procedureKey: result.procedure.procedure_key,
851
+ title: result.procedure.title,
852
+ goal: result.procedure.goal
853
+ }
854
+ } : {},
855
+ procedures: result.procedureCandidates.map((candidate) => ({
856
+ id: candidate.procedure.id,
857
+ procedureKey: candidate.procedure.procedure_key,
858
+ title: candidate.procedure.title,
859
+ goal: candidate.procedure.goal,
860
+ score: candidate.score,
861
+ lexicalScore: candidate.scores.lexical,
862
+ vectorScore: candidate.scores.vector
863
+ })),
864
+ procedureNotices: result.procedureNotices,
865
+ episodes: result.episodes.map((episode) => ({
866
+ id: episode.episode.id,
867
+ source: episode.episode.source,
868
+ sourceId: episode.episode.sourceId,
869
+ startedAt: episode.episode.startedAt,
870
+ endedAt: episode.episode.endedAt,
871
+ tags: episode.episode.tags,
872
+ score: episode.score,
873
+ activityLevel: episode.episode.activityLevel,
874
+ summary: episode.episode.summary,
875
+ whyMatched: describeEpisodeWhyMatched(episode.scores.semantic, episode.scores.temporal)
876
+ })),
877
+ entries: result.entries.map((entry) => ({
878
+ id: entry.entry.id,
879
+ subject: entry.entry.subject,
880
+ type: entry.entry.type,
881
+ expiry: entry.entry.expiry,
882
+ importance: entry.entry.importance,
883
+ score: entry.score,
884
+ tags: entry.entry.tags,
885
+ content: entry.entry.content
886
+ })),
887
+ projectedEntries: result.projectedEntries.map((entry) => ({
888
+ id: entry.entryId,
889
+ familyKey: entry.familyKey,
890
+ claimKey: entry.claimKey,
891
+ slotPolicy: entry.slotPolicy,
892
+ memoryState: entry.memoryState,
893
+ claimStatus: entry.claimStatus,
894
+ freshness: entry.freshness,
895
+ provenance: entry.provenance,
896
+ whySurfaced: entry.whySurfaced
897
+ })),
898
+ entryFamilies: result.entryFamilies.map((family) => ({
899
+ familyKey: family.familyKey,
900
+ claimKey: family.claimKey,
901
+ slotPolicy: family.slotPolicy,
902
+ subject: family.subject,
903
+ primaryEntryId: family.primary.entryId,
904
+ entries: family.entries.map((entry) => ({
905
+ id: entry.entryId,
906
+ memoryState: entry.memoryState,
907
+ claimStatus: entry.claimStatus
908
+ }))
909
+ })),
910
+ claimTransitions: result.claimTransitions,
911
+ notices: result.notices
912
+ };
913
+ }
914
+ function describeEpisodeWhyMatched(semanticScore, temporalScore) {
915
+ if (semanticScore > 0 && temporalScore > 0) {
916
+ return "Semantic match within the resolved time window.";
917
+ }
918
+ if (semanticScore > 0) {
919
+ return "Semantic match to the episode summary.";
920
+ }
921
+ if (temporalScore > 0) {
922
+ return "Session overlaps the resolved time window.";
923
+ }
924
+ return "Matched episodic recall ranking.";
925
+ }
926
+
927
+ // src/adapters/shared/injection/entry-lines.ts
928
+ var MAX_CONTENT_CHARS = 220;
929
+ function formatInjectionEntryHeader(item) {
930
+ const metadata = [
931
+ `rank ${item.rank}`,
932
+ item.entry.id,
933
+ item.entry.type,
934
+ item.entry.expiry,
935
+ `importance ${item.entry.importance}`,
936
+ item.score !== void 0 ? `score ${item.score.toFixed(2)}` : void 0
937
+ ].filter((value) => value !== void 0);
938
+ return `- [${metadata.join(" | ")}] ${item.entry.subject}`;
939
+ }
940
+ function formatInjectionEntryBodyLines(item) {
941
+ const lines = [` ${truncate2(item.entry.content.trim(), MAX_CONTENT_CHARS)}`];
942
+ lines.push(` why: ${item.whySurfaced.summary}`);
943
+ const metadata = [
944
+ item.entry.tags.length > 0 ? `tags: ${item.entry.tags.join(", ")}` : void 0,
945
+ item.freshnessLabel ? `freshness: ${item.freshnessLabel}` : void 0,
946
+ item.provenanceSummary ? `provenance: ${truncate2(item.provenanceSummary, MAX_CONTENT_CHARS)}` : void 0
947
+ ].filter((value) => value !== void 0);
948
+ if (metadata.length > 0) {
949
+ lines.push(` ${metadata.join(" | ")}`);
950
+ }
951
+ return lines;
952
+ }
953
+
954
+ // src/adapters/shared/injection/memory-context.ts
768
955
  var AGENR_MEMORY_CONTEXT_BLOCK_RE = /<agenr-memory-context>[\s\S]*?<\/agenr-memory-context>/giu;
769
956
  var AGENR_MEMORY_CONTEXT_OPEN_RE = /<agenr-memory-context>/giu;
770
957
  var AGENR_MEMORY_CONTEXT_CLOSE_RE = /<\/agenr-memory-context>/giu;
@@ -786,8 +973,8 @@ function stripAgenrMemoryContext(content) {
786
973
  return content.replace(AGENR_MEMORY_CONTEXT_BLOCK_RE, " ").replace(AGENR_MEMORY_CONTEXT_OPEN_RE, " ").replace(AGENR_MEMORY_CONTEXT_CLOSE_RE, " ").replace(AGENR_MEMORY_CONTEXT_NOTE_RE, " ");
787
974
  }
788
975
 
789
- // src/adapters/openclaw/format/before-turn-format.ts
790
- var MAX_CONTENT_CHARS = 220;
976
+ // src/adapters/shared/injection/before-turn-format.ts
977
+ var MAX_CONTENT_CHARS2 = 220;
791
978
  function formatAgenrBeforeTurnRecall(patch) {
792
979
  if (patch.durableMemory.length === 0 && !patch.procedure) {
793
980
  return "";
@@ -800,8 +987,8 @@ function formatAgenrBeforeTurnRecall(patch) {
800
987
  if (patch.durableMemory.length > 0) {
801
988
  lines.push("### Relevant Durable Memory");
802
989
  for (const item of patch.durableMemory) {
803
- lines.push(formatEntryHeader(item));
804
- lines.push(...formatEntryBodyLines(item));
990
+ lines.push(formatInjectionEntryHeader(item));
991
+ lines.push(...formatInjectionEntryBodyLines(item));
805
992
  }
806
993
  lines.push("");
807
994
  }
@@ -813,30 +1000,6 @@ function formatAgenrBeforeTurnRecall(patch) {
813
1000
  }
814
1001
  return wrapAgenrMemoryContext(lines.join("\n").trim());
815
1002
  }
816
- function formatEntryHeader(item) {
817
- const metadata = [
818
- `rank ${item.rank}`,
819
- item.entry.id,
820
- item.entry.type,
821
- item.entry.expiry,
822
- `importance ${item.entry.importance}`,
823
- `score ${item.score.toFixed(2)}`
824
- ];
825
- return `- [${metadata.join(" | ")}] ${item.entry.subject}`;
826
- }
827
- function formatEntryBodyLines(item) {
828
- const lines = [` ${truncate2(item.entry.content.trim(), MAX_CONTENT_CHARS)}`];
829
- lines.push(` why: ${item.whySurfaced.summary}`);
830
- const metadata = [
831
- item.entry.tags.length > 0 ? `tags: ${item.entry.tags.join(", ")}` : void 0,
832
- item.freshnessLabel ? `freshness: ${item.freshnessLabel}` : void 0,
833
- item.provenanceSummary ? `provenance: ${truncate2(item.provenanceSummary, MAX_CONTENT_CHARS)}` : void 0
834
- ].filter((value) => value !== void 0);
835
- if (metadata.length > 0) {
836
- lines.push(` ${metadata.join(" | ")}`);
837
- }
838
- return lines;
839
- }
840
1003
  function formatProcedureHeader(suggestion) {
841
1004
  const metadata = [
842
1005
  suggestion.procedure.id,
@@ -848,39 +1011,29 @@ function formatProcedureHeader(suggestion) {
848
1011
  return `- [${metadata.join(" | ")}] ${suggestion.procedure.title}`;
849
1012
  }
850
1013
  function formatProcedureBodyLines(suggestion) {
851
- const lines = [` goal: ${truncate2(suggestion.procedure.goal.trim(), MAX_CONTENT_CHARS)}`];
1014
+ const lines = [` goal: ${truncate2(suggestion.procedure.goal.trim(), MAX_CONTENT_CHARS2)}`];
852
1015
  lines.push(` why: ${suggestion.whySurfaced.summary}`);
853
1016
  if (suggestion.procedure.when_to_use.length > 0) {
854
- lines.push(` when to use: ${truncate2(suggestion.procedure.when_to_use.join("; "), MAX_CONTENT_CHARS)}`);
1017
+ lines.push(` when to use: ${truncate2(suggestion.procedure.when_to_use.join("; "), MAX_CONTENT_CHARS2)}`);
855
1018
  }
856
1019
  if (suggestion.procedure.verification.length > 0) {
857
- lines.push(` verification: ${truncate2(suggestion.procedure.verification.join("; "), MAX_CONTENT_CHARS)}`);
1020
+ lines.push(` verification: ${truncate2(suggestion.procedure.verification.join("; "), MAX_CONTENT_CHARS2)}`);
858
1021
  }
859
1022
  return lines;
860
1023
  }
861
- function truncate2(value, maxChars) {
862
- if (value.length <= maxChars) {
863
- return value;
864
- }
865
- return `${value.slice(0, maxChars - 3).trimEnd()}...`;
866
- }
867
-
868
- // src/app/debug-artifacts/before-turn.ts
869
- var BEFORE_TURN_DEBUG_ARTIFACT_DEFAULT_TOP_K = 10;
870
- var BEFORE_TURN_DEBUG_ARTIFACT_MAX_TOP_K = 25;
871
-
872
- // src/app/debug-artifacts/recall.ts
873
- var RECALL_DEBUG_ARTIFACT_DEFAULT_TOP_K = 10;
874
- var RECALL_DEBUG_ARTIFACT_MAX_TOP_K = 25;
875
1024
 
876
1025
  export {
877
1026
  runBeforeTurn,
1027
+ truncate2 as truncate,
1028
+ sanitizeStoreToolParams,
1029
+ formatRecallToolSummary,
1030
+ sanitizeRecallToolParams,
1031
+ formatUnifiedRecallLogSummary,
1032
+ buildRecallToolDetails,
1033
+ formatInjectionEntryHeader,
1034
+ formatInjectionEntryBodyLines,
878
1035
  wrapAgenrMemoryContext,
879
1036
  containsAgenrMemoryContext,
880
1037
  stripAgenrMemoryContext,
881
- formatAgenrBeforeTurnRecall,
882
- BEFORE_TURN_DEBUG_ARTIFACT_DEFAULT_TOP_K,
883
- BEFORE_TURN_DEBUG_ARTIFACT_MAX_TOP_K,
884
- RECALL_DEBUG_ARTIFACT_DEFAULT_TOP_K,
885
- RECALL_DEBUG_ARTIFACT_MAX_TOP_K
1038
+ formatAgenrBeforeTurnRecall
886
1039
  };