@mastra/inngest 0.12.0-alpha.1 → 0.12.3-alpha.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.
- package/.turbo/turbo-build.log +1 -1
- package/CHANGELOG.md +48 -0
- package/dist/index.cjs +19 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +4 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +19 -0
- package/dist/index.js.map +1 -1
- package/package.json +9 -9
- package/src/index.test.ts +90 -0
- package/src/index.ts +22 -0
package/src/index.test.ts
CHANGED
|
@@ -6,6 +6,8 @@ import { realtimeMiddleware } from '@inngest/realtime';
|
|
|
6
6
|
import { Agent } from '@mastra/core/agent';
|
|
7
7
|
import { Mastra } from '@mastra/core/mastra';
|
|
8
8
|
import { RuntimeContext } from '@mastra/core/runtime-context';
|
|
9
|
+
import type { MastraScorer } from '@mastra/core/scores';
|
|
10
|
+
import { createScorer, runExperiment } from '@mastra/core/scores';
|
|
9
11
|
import { Telemetry } from '@mastra/core/telemetry';
|
|
10
12
|
import { createTool } from '@mastra/core/tools';
|
|
11
13
|
import type { StreamEvent } from '@mastra/core/workflows';
|
|
@@ -7813,5 +7815,93 @@ describe('MastraInngestWorkflow', () => {
|
|
|
7813
7815
|
},
|
|
7814
7816
|
]);
|
|
7815
7817
|
});
|
|
7818
|
+
|
|
7819
|
+
describe('Workflow integration', () => {
|
|
7820
|
+
let mockScorers: MastraScorer[];
|
|
7821
|
+
beforeEach(() => {
|
|
7822
|
+
const createMockScorer = (name: string, score: number = 0.8): MastraScorer => {
|
|
7823
|
+
const scorer = createScorer({
|
|
7824
|
+
description: 'Mock scorer',
|
|
7825
|
+
name,
|
|
7826
|
+
}).generateScore(() => {
|
|
7827
|
+
return score;
|
|
7828
|
+
});
|
|
7829
|
+
|
|
7830
|
+
vi.spyOn(scorer, 'run');
|
|
7831
|
+
|
|
7832
|
+
return scorer;
|
|
7833
|
+
};
|
|
7834
|
+
|
|
7835
|
+
vi.clearAllMocks();
|
|
7836
|
+
mockScorers = [createMockScorer('toxicity', 0.9), createMockScorer('relevance', 0.7)];
|
|
7837
|
+
});
|
|
7838
|
+
|
|
7839
|
+
it('should run experiment with workflow target', async ctx => {
|
|
7840
|
+
const inngest = new Inngest({
|
|
7841
|
+
id: 'mastra',
|
|
7842
|
+
baseUrl: `http://localhost:${(ctx as any).inngestPort}`,
|
|
7843
|
+
middleware: [realtimeMiddleware()],
|
|
7844
|
+
});
|
|
7845
|
+
|
|
7846
|
+
const { createWorkflow, createStep } = init(inngest);
|
|
7847
|
+
|
|
7848
|
+
// Create a simple workflow
|
|
7849
|
+
const mockStep = createStep({
|
|
7850
|
+
id: 'test-step',
|
|
7851
|
+
inputSchema: z.object({ input: z.string() }),
|
|
7852
|
+
outputSchema: z.object({ output: z.string() }),
|
|
7853
|
+
execute: async ({ inputData }) => {
|
|
7854
|
+
return { output: `Processed: ${inputData.input}` };
|
|
7855
|
+
},
|
|
7856
|
+
});
|
|
7857
|
+
|
|
7858
|
+
const workflow = createWorkflow({
|
|
7859
|
+
id: 'test-workflow',
|
|
7860
|
+
inputSchema: z.object({ input: z.string() }),
|
|
7861
|
+
outputSchema: z.object({ output: z.string() }),
|
|
7862
|
+
})
|
|
7863
|
+
.then(mockStep)
|
|
7864
|
+
.commit();
|
|
7865
|
+
|
|
7866
|
+
const mastra = new Mastra({
|
|
7867
|
+
storage: new DefaultStorage({
|
|
7868
|
+
url: ':memory:',
|
|
7869
|
+
}),
|
|
7870
|
+
workflows: {
|
|
7871
|
+
'test-workflow': workflow,
|
|
7872
|
+
},
|
|
7873
|
+
server: {
|
|
7874
|
+
apiRoutes: [
|
|
7875
|
+
{
|
|
7876
|
+
path: '/inngest/api',
|
|
7877
|
+
method: 'ALL',
|
|
7878
|
+
createHandler: async ({ mastra }) => inngestServe({ mastra, inngest }),
|
|
7879
|
+
},
|
|
7880
|
+
],
|
|
7881
|
+
},
|
|
7882
|
+
});
|
|
7883
|
+
|
|
7884
|
+
const app = await createHonoServer(mastra);
|
|
7885
|
+
|
|
7886
|
+
const srv = (globServer = serve({
|
|
7887
|
+
fetch: app.fetch,
|
|
7888
|
+
port: (ctx as any).handlerPort,
|
|
7889
|
+
}));
|
|
7890
|
+
|
|
7891
|
+
await resetInngest();
|
|
7892
|
+
|
|
7893
|
+
const result = await runExperiment({
|
|
7894
|
+
data: [
|
|
7895
|
+
{ input: { input: 'Test input 1' }, groundTruth: 'Expected 1' },
|
|
7896
|
+
{ input: { input: 'Test input 2' }, groundTruth: 'Expected 2' },
|
|
7897
|
+
],
|
|
7898
|
+
scorers: [mockScorers[0]],
|
|
7899
|
+
target: workflow,
|
|
7900
|
+
});
|
|
7901
|
+
srv.close();
|
|
7902
|
+
expect(result.scores.toxicity).toBe(0.9);
|
|
7903
|
+
expect(result.summary.totalItems).toBe(2);
|
|
7904
|
+
});
|
|
7905
|
+
});
|
|
7816
7906
|
});
|
|
7817
7907
|
}, 40e3);
|
package/src/index.ts
CHANGED
|
@@ -1230,6 +1230,7 @@ export class InngestExecutionEngine extends DefaultExecutionEngine {
|
|
|
1230
1230
|
abortController,
|
|
1231
1231
|
runtimeContext,
|
|
1232
1232
|
writableStream,
|
|
1233
|
+
disableScorers,
|
|
1233
1234
|
tracingContext,
|
|
1234
1235
|
}: {
|
|
1235
1236
|
step: Step<string, any, any>;
|
|
@@ -1245,6 +1246,7 @@ export class InngestExecutionEngine extends DefaultExecutionEngine {
|
|
|
1245
1246
|
abortController: AbortController;
|
|
1246
1247
|
runtimeContext: RuntimeContext;
|
|
1247
1248
|
writableStream?: WritableStream<ChunkType>;
|
|
1249
|
+
disableScorers?: boolean;
|
|
1248
1250
|
tracingContext?: TracingContext;
|
|
1249
1251
|
}): Promise<StepResult<any, any, any, any>> {
|
|
1250
1252
|
const stepAISpan = tracingContext?.currentSpan?.createChildSpan({
|
|
@@ -1636,6 +1638,23 @@ export class InngestExecutionEngine extends DefaultExecutionEngine {
|
|
|
1636
1638
|
return { result: execResults, executionContext, stepResults };
|
|
1637
1639
|
});
|
|
1638
1640
|
|
|
1641
|
+
if (disableScorers !== false) {
|
|
1642
|
+
await this.inngestStep.run(`workflow.${executionContext.workflowId}.step.${step.id}.score`, async () => {
|
|
1643
|
+
if (step.scorers) {
|
|
1644
|
+
await this.runScorers({
|
|
1645
|
+
scorers: step.scorers,
|
|
1646
|
+
runId: executionContext.runId,
|
|
1647
|
+
input: prevOutput,
|
|
1648
|
+
output: stepRes.result,
|
|
1649
|
+
workflowId: executionContext.workflowId,
|
|
1650
|
+
stepId: step.id,
|
|
1651
|
+
runtimeContext,
|
|
1652
|
+
disableScorers,
|
|
1653
|
+
});
|
|
1654
|
+
}
|
|
1655
|
+
});
|
|
1656
|
+
}
|
|
1657
|
+
|
|
1639
1658
|
// @ts-ignore
|
|
1640
1659
|
Object.assign(executionContext.suspendedPaths, stepRes.executionContext.suspendedPaths);
|
|
1641
1660
|
// @ts-ignore
|
|
@@ -1704,6 +1723,7 @@ export class InngestExecutionEngine extends DefaultExecutionEngine {
|
|
|
1704
1723
|
abortController,
|
|
1705
1724
|
runtimeContext,
|
|
1706
1725
|
writableStream,
|
|
1726
|
+
disableScorers,
|
|
1707
1727
|
tracingContext,
|
|
1708
1728
|
}: {
|
|
1709
1729
|
workflowId: string;
|
|
@@ -1728,6 +1748,7 @@ export class InngestExecutionEngine extends DefaultExecutionEngine {
|
|
|
1728
1748
|
abortController: AbortController;
|
|
1729
1749
|
runtimeContext: RuntimeContext;
|
|
1730
1750
|
writableStream?: WritableStream<ChunkType>;
|
|
1751
|
+
disableScorers?: boolean;
|
|
1731
1752
|
tracingContext?: TracingContext;
|
|
1732
1753
|
}): Promise<StepResult<any, any, any, any>> {
|
|
1733
1754
|
const conditionalSpan = tracingContext?.currentSpan?.createChildSpan({
|
|
@@ -1855,6 +1876,7 @@ export class InngestExecutionEngine extends DefaultExecutionEngine {
|
|
|
1855
1876
|
abortController,
|
|
1856
1877
|
runtimeContext,
|
|
1857
1878
|
writableStream,
|
|
1879
|
+
disableScorers,
|
|
1858
1880
|
tracingContext: {
|
|
1859
1881
|
currentSpan: conditionalSpan,
|
|
1860
1882
|
},
|