@mastra/longmemeval 0.0.0-error-handler-fix-20251020202607 → 0.0.0-execa-dynamic-import-20260304221256

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.
Files changed (43) hide show
  1. package/CHANGELOG.md +847 -6
  2. package/LICENSE.md +15 -0
  3. package/docs/INVESTIGATION_WORKFLOW.md +314 -0
  4. package/package.json +34 -26
  5. package/scripts/download.ts +22 -1
  6. package/scripts/generate-wm-templates.ts +2 -1
  7. package/src/cli.ts +967 -155
  8. package/src/commands/__tests__/prepare.test.ts +11 -6
  9. package/src/commands/__tests__/run.test.ts +10 -8
  10. package/src/commands/clean.ts +147 -0
  11. package/src/commands/deterministic-ids.ts +126 -0
  12. package/src/commands/find-prohibited.ts +299 -0
  13. package/src/commands/investigate.ts +2437 -0
  14. package/src/commands/list-partial.ts +137 -0
  15. package/src/commands/obscure-thread-ids.ts +237 -0
  16. package/src/commands/partial-results.ts +198 -0
  17. package/src/commands/precompute-embeddings.ts +302 -0
  18. package/src/commands/prepare.ts +732 -105
  19. package/src/commands/reconcile.ts +383 -0
  20. package/src/commands/run.ts +1240 -121
  21. package/src/commands/sessions.ts +126 -0
  22. package/src/commands/sync.ts +152 -0
  23. package/src/commands/test-cleaned.ts +53 -0
  24. package/src/commands/test-incremental.ts +120 -0
  25. package/src/commands/test-messages.ts +95 -0
  26. package/src/commands/test-prohibited.ts +244 -0
  27. package/src/commands/test-thread.ts +136 -0
  28. package/src/commands/tokens.ts +625 -0
  29. package/src/config.ts +1253 -72
  30. package/src/data/types.ts +48 -6
  31. package/src/embeddings/cached-openai-embedding-model.ts +0 -1
  32. package/src/evaluation/longmemeval-metric.ts +186 -103
  33. package/src/processors/content-sanitizer.ts +153 -0
  34. package/src/processors/date-injector.ts +111 -0
  35. package/src/processors/index.ts +3 -0
  36. package/src/processors/observation-semantic-filter.ts +1142 -0
  37. package/src/retry-model.ts +5 -3
  38. package/src/storage/__tests__/benchmark-store.test.ts +18 -35
  39. package/src/storage/benchmark-store.ts +140 -153
  40. package/src/storage/benchmark-vector.ts +1 -1
  41. package/src/storage/index.ts +1 -0
  42. package/src/storage/persistable-inmemory.ts +133 -0
  43. package/src/test-utils/mock-model.ts +35 -0
@@ -0,0 +1,111 @@
1
+ import type { Processor, ProcessInputStepArgs } from '@mastra/core/processors';
2
+ import type { MastraDBMessage } from '@mastra/core/agent';
3
+
4
+ export interface DateInjectorConfig {
5
+ /**
6
+ * The date string to inject (in official LongMemEval format: "2023/05/30 (Tue) 23:40")
7
+ */
8
+ date: string;
9
+ }
10
+
11
+ /**
12
+ * Input processor that injects the current date into the user's message.
13
+ *
14
+ * This matches the official LongMemEval benchmark format where the date
15
+ * is part of the user prompt: "Current Date: {date}\nQuestion: {question}"
16
+ *
17
+ * By default, this processor runs AFTER RAG filtering, so the date
18
+ * becomes part of the RAG query. This is more authentic to the benchmark
19
+ * and may help RAG pick up on temporal relevance.
20
+ */
21
+ export class DateInjector implements Processor<'date-injector'> {
22
+ readonly id = 'date-injector' as const;
23
+ private date: string;
24
+
25
+ constructor(config: DateInjectorConfig) {
26
+ this.date = config.date;
27
+ }
28
+
29
+ processInputStep(args: ProcessInputStepArgs) {
30
+ const { messages, messageList } = args;
31
+
32
+ // Find the most recent user message
33
+ let lastUserIndex = -1;
34
+ for (let i = messages.length - 1; i >= 0; i--) {
35
+ if (messages[i].role === 'user') {
36
+ lastUserIndex = i;
37
+ break;
38
+ }
39
+ }
40
+
41
+ if (lastUserIndex === -1) {
42
+ return messageList;
43
+ }
44
+
45
+ const lastUserMessage = messages[lastUserIndex];
46
+ const originalContent = this.extractContent(lastUserMessage);
47
+
48
+ // Format: "Current Date: {date}\nQuestion: {question}"
49
+ // This matches the official LongMemEval prompt template
50
+ const newContent = `Current Date: ${this.date}\nQuestion: ${originalContent}`;
51
+
52
+ // Mutate the message content in place, preserving the original structure
53
+ const content = lastUserMessage.content;
54
+ if (content && typeof content === 'object' && 'format' in content && content.format === 2) {
55
+ // MastraMessageContentV2 format - update the nested content string
56
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
57
+ (content as any).content = newContent;
58
+ // Also update parts if they exist
59
+ if (Array.isArray((content as { parts?: unknown[] }).parts)) {
60
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
61
+ (content as any).parts = [{ type: 'text', text: newContent }];
62
+ }
63
+ } else {
64
+ // Simple string content or other format - replace directly
65
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
66
+ (lastUserMessage as any).content = newContent;
67
+ }
68
+
69
+ return messageList;
70
+ }
71
+
72
+ private extractContent(msg: MastraDBMessage): string {
73
+ const content = msg.content;
74
+
75
+ // Handle string content
76
+ if (typeof content === 'string') {
77
+ return content;
78
+ }
79
+
80
+ // Handle MastraMessageContentV2 format
81
+ if (content && typeof content === 'object' && 'format' in content && content.format === 2) {
82
+ if (typeof content.content === 'string' && content.content) {
83
+ return content.content;
84
+ }
85
+ if (Array.isArray(content.parts)) {
86
+ const textParts = content.parts
87
+ .filter(
88
+ (p): p is { type: 'text'; text: string } =>
89
+ p && typeof p === 'object' && p.type === 'text' && typeof p.text === 'string',
90
+ )
91
+ .map(p => p.text);
92
+ if (textParts.length > 0) {
93
+ return textParts.join(' ');
94
+ }
95
+ }
96
+ }
97
+
98
+ // Handle plain array content
99
+ if (Array.isArray(content)) {
100
+ const textParts = content
101
+ .filter(
102
+ (p): p is { type: 'text'; text: string } =>
103
+ p && typeof p === 'object' && p.type === 'text' && typeof p.text === 'string',
104
+ )
105
+ .map(p => p.text);
106
+ return textParts.join(' ') || '';
107
+ }
108
+
109
+ return '';
110
+ }
111
+ }
@@ -0,0 +1,3 @@
1
+ export * from './observation-semantic-filter';
2
+ export * from './date-injector';
3
+ export * from './content-sanitizer';