@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.
- package/CHANGELOG.md +847 -6
- package/LICENSE.md +15 -0
- package/docs/INVESTIGATION_WORKFLOW.md +314 -0
- package/package.json +34 -26
- package/scripts/download.ts +22 -1
- package/scripts/generate-wm-templates.ts +2 -1
- package/src/cli.ts +967 -155
- package/src/commands/__tests__/prepare.test.ts +11 -6
- package/src/commands/__tests__/run.test.ts +10 -8
- package/src/commands/clean.ts +147 -0
- package/src/commands/deterministic-ids.ts +126 -0
- package/src/commands/find-prohibited.ts +299 -0
- package/src/commands/investigate.ts +2437 -0
- package/src/commands/list-partial.ts +137 -0
- package/src/commands/obscure-thread-ids.ts +237 -0
- package/src/commands/partial-results.ts +198 -0
- package/src/commands/precompute-embeddings.ts +302 -0
- package/src/commands/prepare.ts +732 -105
- package/src/commands/reconcile.ts +383 -0
- package/src/commands/run.ts +1240 -121
- package/src/commands/sessions.ts +126 -0
- package/src/commands/sync.ts +152 -0
- package/src/commands/test-cleaned.ts +53 -0
- package/src/commands/test-incremental.ts +120 -0
- package/src/commands/test-messages.ts +95 -0
- package/src/commands/test-prohibited.ts +244 -0
- package/src/commands/test-thread.ts +136 -0
- package/src/commands/tokens.ts +625 -0
- package/src/config.ts +1253 -72
- package/src/data/types.ts +48 -6
- package/src/embeddings/cached-openai-embedding-model.ts +0 -1
- package/src/evaluation/longmemeval-metric.ts +186 -103
- package/src/processors/content-sanitizer.ts +153 -0
- package/src/processors/date-injector.ts +111 -0
- package/src/processors/index.ts +3 -0
- package/src/processors/observation-semantic-filter.ts +1142 -0
- package/src/retry-model.ts +5 -3
- package/src/storage/__tests__/benchmark-store.test.ts +18 -35
- package/src/storage/benchmark-store.ts +140 -153
- package/src/storage/benchmark-vector.ts +1 -1
- package/src/storage/index.ts +1 -0
- package/src/storage/persistable-inmemory.ts +133 -0
- 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
|
+
}
|