mirror of
https://github.com/mastra-ai/mastra.git
synced 2026-11-17 08:44:46 +00:00
fix infinite await loop mastra entrypoint (#3513)
## Description
<!-- Provide a brief description of the changes in this PR -->
When bundling mastra with default storage, we end up in a weird place
where we await storage but also export mastra information that is used
in the dynamic import (I believe this is a rollup bug), this fixes it by
making sure the user mastra file is in a seperate chunk.
Before:
```
if (mastra.storage) {
await mastra.storage.init();
}
registerHook(AvailableHooks.ON_EVALUATION, async traceObject => {
if (mastra.storage) {
// Check for required fields
const logger = mastra?.getLogger();
const areFieldsValid = checkEvalStorageFields(traceObject, logger);
if (!areFieldsValid) return;
await mastra.storage.insert({
tableName: TABLE_EVALS,
record: {
input: traceObject.input,
output: traceObject.output,
result: JSON.stringify(traceObject.result || {}),
agent_name: traceObject.agentName,
metric_name: traceObject.metricName,
instructions: traceObject.instructions,
test_info: null,
global_run_id: traceObject.globalRunId,
run_id: traceObject.runId,
created_at: new Date().toISOString(),
},
});
}
});
export { MastraStorage as M, TABLE_WORKFLOW_SNAPSHOT as T, TABLE_THREADS as a, TABLE_MESSAGES as b, TABLE_EVALS as c, TABLE_TRACES as d };
```
After:
```
if (mastra.storage) {
await mastra.storage.init();
}
registerHook(AvailableHooks.ON_EVALUATION, async traceObject => {
if (mastra.storage) {
// Check for required fields
const logger = mastra?.getLogger();
const areFieldsValid = checkEvalStorageFields(traceObject, logger);
if (!areFieldsValid) return;
await mastra.storage.insert({
tableName: TABLE_EVALS,
record: {
input: traceObject.input,
output: traceObject.output,
result: JSON.stringify(traceObject.result || {}),
agent_name: traceObject.agentName,
metric_name: traceObject.metricName,
instructions: traceObject.instructions,
test_info: null,
global_run_id: traceObject.globalRunId,
run_id: traceObject.runId,
created_at: new Date().toISOString(),
},
});
}
});
```
## Related Issue(s)
<!-- Link to the issue(s) this PR addresses, using hashtag notation:
#123 -->
## Type of Change
- [x] Bug fix (non-breaking change that fixes an issue)
- [ ] New feature (non-breaking change that adds functionality)
- [ ] Breaking change (fix or feature that would cause existing
functionality to change)
- [ ] Documentation update
- [ ] Code refactoring
- [ ] Performance improvement
- [ ] Test update
## Checklist
- [x] I have performed a self-review of my own code
- [ ] I have made corresponding changes to the documentation (if
applicable)
- [ ] I have added tests that prove my fix is effective or that my
feature works
- [ ] New and existing unit tests pass locally with my changes
- [x] I have generated a changeset for this PR
This commit is contained in:
parent
a06aadc9bc
commit
ae6c5ce1a3
2 changed files with 11 additions and 1 deletions
Loading…
Add table
Add a link
Reference in a new issue