@mastra/server 0.18.1-alpha.0 → 0.19.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.
Files changed (48) hide show
  1. package/CHANGELOG.md +38 -0
  2. package/dist/{chunk-5N724Q2T.cjs → chunk-52UP7DFT.cjs} +23 -2
  3. package/dist/chunk-52UP7DFT.cjs.map +1 -0
  4. package/dist/{chunk-2GDLSAVJ.cjs → chunk-BKCWZLEL.cjs} +2 -2
  5. package/dist/{chunk-2GDLSAVJ.cjs.map → chunk-BKCWZLEL.cjs.map} +1 -1
  6. package/dist/{chunk-QNWXF57L.cjs → chunk-DWVU5R72.cjs} +2485 -210
  7. package/dist/chunk-DWVU5R72.cjs.map +1 -0
  8. package/dist/{chunk-BOVFMBXY.js → chunk-FUGNIXSQ.js} +4 -4
  9. package/dist/{chunk-BOVFMBXY.js.map → chunk-FUGNIXSQ.js.map} +1 -1
  10. package/dist/{chunk-CML3EOO5.cjs → chunk-GIM2ZSPB.cjs} +30 -16
  11. package/dist/chunk-GIM2ZSPB.cjs.map +1 -0
  12. package/dist/{chunk-NH7XUTIO.js → chunk-QGW2VHZU.js} +30 -16
  13. package/dist/chunk-QGW2VHZU.js.map +1 -0
  14. package/dist/{chunk-SXENNNR7.cjs → chunk-WPKD74PD.cjs} +4 -4
  15. package/dist/{chunk-SXENNNR7.cjs.map → chunk-WPKD74PD.cjs.map} +1 -1
  16. package/dist/{chunk-5KRXONRF.js → chunk-WUJLVNLU.js} +23 -3
  17. package/dist/chunk-WUJLVNLU.js.map +1 -0
  18. package/dist/{chunk-N5ID53SA.js → chunk-X3CRHW4S.js} +2471 -196
  19. package/dist/chunk-X3CRHW4S.js.map +1 -0
  20. package/dist/{chunk-IYJW2OVQ.js → chunk-XJOYGRTN.js} +2 -2
  21. package/dist/{chunk-IYJW2OVQ.js.map → chunk-XJOYGRTN.js.map} +1 -1
  22. package/dist/server/handlers/agent-builder.cjs +16 -16
  23. package/dist/server/handlers/agent-builder.d.ts +6 -0
  24. package/dist/server/handlers/agent-builder.d.ts.map +1 -1
  25. package/dist/server/handlers/agent-builder.js +1 -1
  26. package/dist/server/handlers/agents.cjs +17 -17
  27. package/dist/server/handlers/agents.js +1 -1
  28. package/dist/server/handlers/observability.cjs +8 -4
  29. package/dist/server/handlers/observability.d.ts +9 -1
  30. package/dist/server/handlers/observability.d.ts.map +1 -1
  31. package/dist/server/handlers/observability.js +1 -1
  32. package/dist/server/handlers/scores.cjs +7 -7
  33. package/dist/server/handlers/scores.d.ts +15 -15
  34. package/dist/server/handlers/scores.d.ts.map +1 -1
  35. package/dist/server/handlers/scores.js +1 -1
  36. package/dist/server/handlers/workflows.cjs +18 -18
  37. package/dist/server/handlers/workflows.d.ts +15 -7
  38. package/dist/server/handlers/workflows.d.ts.map +1 -1
  39. package/dist/server/handlers/workflows.js +1 -1
  40. package/dist/server/handlers.cjs +10 -10
  41. package/dist/server/handlers.js +5 -5
  42. package/package.json +7 -7
  43. package/dist/chunk-5KRXONRF.js.map +0 -1
  44. package/dist/chunk-5N724Q2T.cjs.map +0 -1
  45. package/dist/chunk-CML3EOO5.cjs.map +0 -1
  46. package/dist/chunk-N5ID53SA.js.map +0 -1
  47. package/dist/chunk-NH7XUTIO.js.map +0 -1
  48. package/dist/chunk-QNWXF57L.cjs.map +0 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,43 @@
1
1
  # @mastra/server
2
2
 
3
+ ## 0.19.0
4
+
5
+ ### Patch Changes
6
+
7
+ - Support passing tracing options for start/resume workflows for server APIs and client sdk ([#8277](https://github.com/mastra-ai/mastra/pull/8277))
8
+
9
+ - add a way to hide the deploy mastra cloud button ([#8137](https://github.com/mastra-ai/mastra/pull/8137))
10
+
11
+ - Update peer deps ([#8154](https://github.com/mastra-ai/mastra/pull/8154))
12
+
13
+ - Add types in the streamVNext codepath, fixes for various issues across multiple packages surfaced from type issues, align return types. ([#8010](https://github.com/mastra-ai/mastra/pull/8010))
14
+
15
+ - Support tracing options for workflow streaming endpoints ([#8278](https://github.com/mastra-ai/mastra/pull/8278))
16
+
17
+ - Adjust deprecation warnings ([#8326](https://github.com/mastra-ai/mastra/pull/8326))
18
+
19
+ - When step is created from agent or tool, add the description and component key to show that ([#8151](https://github.com/mastra-ai/mastra/pull/8151))
20
+
21
+ - Add server apis to get scores by span ([#8237](https://github.com/mastra-ai/mastra/pull/8237))
22
+
23
+ - Updated dependencies [[`dc099b4`](https://github.com/mastra-ai/mastra/commit/dc099b40fb31147ba3f362f98d991892033c4c67), [`504438b`](https://github.com/mastra-ai/mastra/commit/504438b961bde211071186bba63a842c4e3db879), [`b342a68`](https://github.com/mastra-ai/mastra/commit/b342a68e1399cf1ece9ba11bda112db89d21118c), [`a7243e2`](https://github.com/mastra-ai/mastra/commit/a7243e2e58762667a6e3921e755e89d6bb0a3282), [`7fceb0a`](https://github.com/mastra-ai/mastra/commit/7fceb0a327d678e812f90f5387c5bc4f38bd039e), [`303a9c0`](https://github.com/mastra-ai/mastra/commit/303a9c0d7dd58795915979f06a0512359e4532fb), [`df64f9e`](https://github.com/mastra-ai/mastra/commit/df64f9ef814916fff9baedd861c988084e7c41de), [`370f8a6`](https://github.com/mastra-ai/mastra/commit/370f8a6480faec70fef18d72e5f7538f27004301), [`809eea0`](https://github.com/mastra-ai/mastra/commit/809eea092fa80c3f69b9eaf078d843b57fd2a88e), [`683e5a1`](https://github.com/mastra-ai/mastra/commit/683e5a1466e48b686825b2c11f84680f296138e4), [`3679378`](https://github.com/mastra-ai/mastra/commit/3679378673350aa314741dc826f837b1984149bc), [`7775bc2`](https://github.com/mastra-ai/mastra/commit/7775bc20bb1ad1ab24797fb420e4f96c65b0d8ec), [`623ffaf`](https://github.com/mastra-ai/mastra/commit/623ffaf2d969e11e99a0224633cf7b5a0815c857), [`9fc1613`](https://github.com/mastra-ai/mastra/commit/9fc16136400186648880fd990119ac15f7c02ee4), [`61f62aa`](https://github.com/mastra-ai/mastra/commit/61f62aa31bc88fe4ddf8da6240dbcfbeb07358bd), [`db1891a`](https://github.com/mastra-ai/mastra/commit/db1891a4707443720b7cd8a260dc7e1d49b3609c), [`e8f379d`](https://github.com/mastra-ai/mastra/commit/e8f379d390efa264c4e0874f9ac0cf8839b07777), [`652066b`](https://github.com/mastra-ai/mastra/commit/652066bd1efc6bb6813ba950ed1d7573e8b7d9d4), [`3e292ba`](https://github.com/mastra-ai/mastra/commit/3e292ba00837886d5d68a34cbc0d9b703c991883), [`418c136`](https://github.com/mastra-ai/mastra/commit/418c1366843d88e491bca3f87763899ce855ca29), [`ea8d386`](https://github.com/mastra-ai/mastra/commit/ea8d386cd8c5593664515fd5770c06bf2aa980ef), [`67b0f00`](https://github.com/mastra-ai/mastra/commit/67b0f005b520335c71fb85cbaa25df4ce8484a81), [`c2a4919`](https://github.com/mastra-ai/mastra/commit/c2a4919ba6797d8bdb1509e02287496eef69303e), [`c84b7d0`](https://github.com/mastra-ai/mastra/commit/c84b7d093c4657772140cbfd2b15ef72f3315ed5), [`0130986`](https://github.com/mastra-ai/mastra/commit/0130986fc62d0edcc626dd593282661dbb9af141)]:
24
+ - @mastra/core@0.19.0
25
+
26
+ ## 0.19.0-alpha.1
27
+
28
+ ### Patch Changes
29
+
30
+ - Support passing tracing options for start/resume workflows for server APIs and client sdk ([#8277](https://github.com/mastra-ai/mastra/pull/8277))
31
+
32
+ - Update peer deps ([#8154](https://github.com/mastra-ai/mastra/pull/8154))
33
+
34
+ - Support tracing options for workflow streaming endpoints ([#8278](https://github.com/mastra-ai/mastra/pull/8278))
35
+
36
+ - Add server apis to get scores by span ([#8237](https://github.com/mastra-ai/mastra/pull/8237))
37
+
38
+ - Updated dependencies [[`504438b`](https://github.com/mastra-ai/mastra/commit/504438b961bde211071186bba63a842c4e3db879), [`a7243e2`](https://github.com/mastra-ai/mastra/commit/a7243e2e58762667a6e3921e755e89d6bb0a3282), [`7fceb0a`](https://github.com/mastra-ai/mastra/commit/7fceb0a327d678e812f90f5387c5bc4f38bd039e), [`df64f9e`](https://github.com/mastra-ai/mastra/commit/df64f9ef814916fff9baedd861c988084e7c41de), [`809eea0`](https://github.com/mastra-ai/mastra/commit/809eea092fa80c3f69b9eaf078d843b57fd2a88e), [`683e5a1`](https://github.com/mastra-ai/mastra/commit/683e5a1466e48b686825b2c11f84680f296138e4), [`3679378`](https://github.com/mastra-ai/mastra/commit/3679378673350aa314741dc826f837b1984149bc), [`7775bc2`](https://github.com/mastra-ai/mastra/commit/7775bc20bb1ad1ab24797fb420e4f96c65b0d8ec), [`db1891a`](https://github.com/mastra-ai/mastra/commit/db1891a4707443720b7cd8a260dc7e1d49b3609c), [`e8f379d`](https://github.com/mastra-ai/mastra/commit/e8f379d390efa264c4e0874f9ac0cf8839b07777), [`652066b`](https://github.com/mastra-ai/mastra/commit/652066bd1efc6bb6813ba950ed1d7573e8b7d9d4), [`ea8d386`](https://github.com/mastra-ai/mastra/commit/ea8d386cd8c5593664515fd5770c06bf2aa980ef), [`c2a4919`](https://github.com/mastra-ai/mastra/commit/c2a4919ba6797d8bdb1509e02287496eef69303e), [`0130986`](https://github.com/mastra-ai/mastra/commit/0130986fc62d0edcc626dd593282661dbb9af141)]:
39
+ - @mastra/core@0.19.0-alpha.1
40
+
3
41
  ## 0.18.1-alpha.0
4
42
 
5
43
  ### Patch Changes
@@ -10,6 +10,7 @@ var observability_exports = {};
10
10
  chunkEMMSS5I5_cjs.__export(observability_exports, {
11
11
  getAITraceHandler: () => getAITraceHandler,
12
12
  getAITracesPaginatedHandler: () => getAITracesPaginatedHandler,
13
+ getScoresBySpan: () => getScoresBySpan,
13
14
  scoreTracesHandler: () => scoreTracesHandler
14
15
  });
15
16
  async function getAITraceHandler({ mastra, traceId }) {
@@ -100,10 +101,30 @@ async function scoreTracesHandler({ mastra, body }) {
100
101
  chunkRE4RPXT2_cjs.handleError(error, "Error processing trace scoring");
101
102
  }
102
103
  }
104
+ async function getScoresBySpan({
105
+ mastra,
106
+ traceId,
107
+ spanId,
108
+ pagination
109
+ }) {
110
+ try {
111
+ const storage = mastra.getStorage();
112
+ if (!storage) {
113
+ throw new chunk7NADHFD2_cjs.HTTPException(500, { message: "Storage is not available" });
114
+ }
115
+ if (!traceId || !spanId) {
116
+ throw new chunk7NADHFD2_cjs.HTTPException(400, { message: "Trace ID and span ID are required" });
117
+ }
118
+ return await storage.getScoresBySpan({ traceId, spanId, pagination });
119
+ } catch (error) {
120
+ return chunkRE4RPXT2_cjs.handleError(error, "Error getting scores by span");
121
+ }
122
+ }
103
123
 
104
124
  exports.getAITraceHandler = getAITraceHandler;
105
125
  exports.getAITracesPaginatedHandler = getAITracesPaginatedHandler;
126
+ exports.getScoresBySpan = getScoresBySpan;
106
127
  exports.observability_exports = observability_exports;
107
128
  exports.scoreTracesHandler = scoreTracesHandler;
108
- //# sourceMappingURL=chunk-5N724Q2T.cjs.map
109
- //# sourceMappingURL=chunk-5N724Q2T.cjs.map
129
+ //# sourceMappingURL=chunk-52UP7DFT.cjs.map
130
+ //# sourceMappingURL=chunk-52UP7DFT.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/server/handlers/observability.ts"],"names":["__export","HTTPException","handleError","scoreTraces"],"mappings":";;;;;;;;AAAA,IAAA,qBAAA,GAAA;AAAAA,0BAAA,CAAA,qBAAA,EAAA;AAAA,EAAA,iBAAA,EAAA,MAAA,iBAAA;AAAA,EAAA,2BAAA,EAAA,MAAA,2BAAA;AAAA,EAAA,eAAA,EAAA,MAAA,eAAA;AAAA,EAAA,kBAAA,EAAA,MAAA;AAAA,CAAA,CAAA;AAyBA,eAAsB,iBAAA,CAAkB,EAAE,MAAA,EAAQ,OAAA,EAAQ,EAA+C;AACvG,EAAA,IAAI;AACF,IAAA,IAAI,CAAC,OAAA,EAAS;AACZ,MAAA,MAAM,IAAIC,+BAAA,CAAc,GAAA,EAAK,EAAE,OAAA,EAAS,wBAAwB,CAAA;AAAA,IAClE;AAEA,IAAA,MAAM,OAAA,GAAU,OAAO,UAAA,EAAW;AAClC,I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,EAAK,EAAE,OAAA,EAAS,4BAA4B,CAAA;AAAA,IACtE;AAEA,IAAA,IAAI,CAAC,OAAA,IAAW,CAAC,MAAA,EAAQ;AACvB,MAAA,MAAM,IAAIA,+BAAA,CAAc,GAAA,EAAK,EAAE,OAAA,EAAS,qCAAqC,CAAA;AAAA,IAC/E;AAEA,IAAA,OAAO,MAAM,OAAA,CAAQ,eAAA,CAAgB,EAAE,OAAA,EAAS,MAAA,EAAQ,YAAY,CAAA;AAAA,EACtE,SAAS,KAAA,EAAO;AACd,IAAA,OAAOC,6BAAA,CAAY,OAAO,8BAA8B,CAAA;AAAA,EAC1D;AACF","file":"chunk-52UP7DFT.cjs","sourcesContent":["import type { AITracesPaginatedArg, StoragePagination } from '@mastra/core';\nimport { scoreTraces } from '@mastra/core/scores/scoreTraces';\nimport { HTTPException } from '../http-exception';\nimport type { Context } from '../types';\nimport { handleError } from './error';\n\ninterface ObservabilityContext extends Context {\n traceId?: string;\n body?: AITracesPaginatedArg;\n}\n\ninterface ScoreTracesContext extends Context {\n body?: {\n scorerName: string;\n targets: Array<{\n traceId: string;\n spanId?: string;\n }>;\n };\n}\n\n/**\n * Get a complete AI trace by trace ID\n * Returns all spans in the trace with their parent-child relationships\n */\nexport async function getAITraceHandler({ mastra, traceId }: ObservabilityContext & { traceId: string }) {\n try {\n if (!traceId) {\n throw new HTTPException(400, { message: 'Trace ID is required' });\n }\n\n const storage = mastra.getStorage();\n if (!storage) {\n throw new HTTPException(500, { message: 'Storage is not available' });\n }\n\n const trace = await storage.getAITrace(traceId);\n\n if (!trace) {\n throw new HTTPException(404, { message: `Trace with ID '${traceId}' not found` });\n }\n\n return trace;\n } catch (error) {\n handleError(error, 'Error getting AI trace');\n }\n}\n\n/**\n * Get paginated AI traces with filtering and pagination\n * Returns only root spans (parent spans) for pagination, not child spans\n */\nexport async function getAITracesPaginatedHandler({ mastra, body }: ObservabilityContext) {\n try {\n const storage = mastra.getStorage();\n if (!storage) {\n throw new HTTPException(500, { message: 'Storage is not available' });\n }\n\n if (!body) {\n throw new HTTPException(400, { message: 'Request body is required' });\n }\n\n const { filters, pagination } = body;\n\n if (pagination?.page && pagination.page < 0) {\n throw new HTTPException(400, { message: 'Page must be a non-negative integer' });\n }\n\n if (pagination?.perPage && pagination.perPage < 0) {\n throw new HTTPException(400, { message: 'Per page must be a non-negative integer' });\n }\n\n if (pagination?.dateRange) {\n const { start, end } = pagination.dateRange;\n\n if (start && !(start instanceof Date)) {\n throw new HTTPException(400, { message: 'Invalid date format in date range' });\n }\n\n if (end && !(end instanceof Date)) {\n throw new HTTPException(400, { message: 'Invalid date format in date range' });\n }\n }\n\n return storage.getAITracesPaginated({\n pagination,\n filters,\n });\n } catch (error) {\n handleError(error, 'Error getting AI traces paginated');\n }\n}\n\n/**\n * Score traces using a specified scorer\n * Fire-and-forget approach - returns immediately while scoring runs in background\n */\nexport async function scoreTracesHandler({ mastra, body }: ScoreTracesContext) {\n try {\n if (!body) {\n throw new HTTPException(400, { message: 'Request body is required' });\n }\n\n const { scorerName, targets } = body;\n\n if (!scorerName) {\n throw new HTTPException(400, { message: 'Scorer Name is required' });\n }\n\n if (!targets || targets.length === 0) {\n throw new HTTPException(400, { message: 'At least one target is required' });\n }\n\n const storage = mastra.getStorage();\n if (!storage) {\n throw new HTTPException(500, { message: 'Storage is not available' });\n }\n\n const scorer = mastra.getScorerByName(scorerName);\n if (!scorer) {\n throw new HTTPException(404, { message: `Scorer '${scorerName}' not found` });\n }\n\n const logger = mastra.getLogger();\n scoreTraces({\n scorerName,\n targets,\n mastra,\n }).catch(error => {\n logger?.error(`Background trace scoring failed: ${error.message}`, error);\n });\n\n // Return immediate response\n return {\n status: 'success',\n message: `Scoring started for ${targets.length} ${targets.length === 1 ? 'trace' : 'traces'}`,\n traceCount: targets.length,\n };\n } catch (error) {\n handleError(error, 'Error processing trace scoring');\n }\n}\n\nexport async function getScoresBySpan({\n mastra,\n traceId,\n spanId,\n pagination,\n}: Context & { traceId: string; spanId: string; pagination: StoragePagination }) {\n try {\n const storage = mastra.getStorage();\n if (!storage) {\n throw new HTTPException(500, { message: 'Storage is not available' });\n }\n\n if (!traceId || !spanId) {\n throw new HTTPException(400, { message: 'Trace ID and span ID are required' });\n }\n\n return await storage.getScoresBySpan({ traceId, spanId, pagination });\n } catch (error) {\n return handleError(error, 'Error getting scores by span');\n }\n}\n"]}
@@ -193,5 +193,5 @@ exports.getScoresByRunIdHandler = getScoresByRunIdHandler;
193
193
  exports.getScoresByScorerIdHandler = getScoresByScorerIdHandler;
194
194
  exports.saveScoreHandler = saveScoreHandler;
195
195
  exports.scores_exports = scores_exports;
196
- //# sourceMappingURL=chunk-2GDLSAVJ.cjs.map
197
- //# sourceMappingURL=chunk-2GDLSAVJ.cjs.map
196
+ //# sourceMappingURL=chunk-BKCWZLEL.cjs.map
197
+ //# sourceMappingURL=chunk-BKCWZLEL.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/server/handlers/scores.ts"],"names":["__export","handleError"],"mappings":";;;;;;AAAA,IAAA,cAAA,GAAA;AAAAA,0BAAA,CAAA,cAAA,EAAA;AAAA,EAAA,gBAAA,EAAA,MAAA,gBAAA;AAAA,EAAA,iBAAA,EAAA,MAAA,iBAAA;AAAA,EAAA,0BAAA,EAAA,MAAA,0BAAA;AAAA,EAAA,uBAAA,EAAA,MAAA,uBAAA;AAAA,EAAA,0BAAA,EAAA,MAAA,0BAAA;AAAA,EAAA,gBAAA,EAAA,MAAA;AAAA,CAAA,CAAA;AAMA,eAAe,oBAAA,CAAqB;AAAA,EAClC,MAAA;AAAA,EACA;AACF,CAAA,EAEG;AACD,EAAA,MAAM,MAAA,GAAS,OAAO,SAAA,EAAU;AAChC,EAAA,MAAM,SAAA,GAAY,OAAO,YAAA,EAAa;AAEtC,EAAA,MAAM,UAAA,uBAAiB,GAAA,EAGrB;AAEF,EAAA,KAAA,MAAW,CAAC,OAAA,EAAS,KAAK,KAAK,MAAA,CAAO,OAAA,CAAQ,MAAM,CAAA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ACA;AAAA,KACD,CAAA,IAAM,EAAE,UAAA,EAAY,EAAE,OAAO,CAAA,EAAG,IAAA,EAAM,CAAA,EAAG,OAAA,EAAS,GAAG,OAAA,EAAS,KAAA,EAAM,EAAG,MAAA,EAAQ,EAAC,EAAE;AAEnF,IAAA,OAAO;AAAA,MACL,YAAY,YAAA,CAAa,UAAA;AAAA,MACzB,MAAA,EAAQ,YAAA,CAAa,MAAA,CAAO,GAAA,CAAI,CAAA,KAAA,MAAU,EAAE,GAAG,KAAA,EAAO,GAAG,eAAA,CAAgB,KAAA,CAAM,OAAO,GAAE,CAAE;AAAA,KAC5F;AAAA,EACF,SAAS,KAAA,EAAO;AACd,IAAA,OAAOA,6BAAA,CAAY,OAAO,mCAAmC,CAAA;AAAA,EAC/D;AACF;AAEA,SAAS,gBAAgB,iBAAA,EAA4B;AACnD,EAAA,IAAI,CAAC,iBAAA,EAAmB;AACtB,IAAA,OAAO,EAAC;AAAA,EACV;AAEA,EAAA,MAAM,CAAC,OAAA,EAAS,MAAM,CAAA,GAAI,iBAAA,CAAkB,MAAM,GAAG,CAAA;AACrD,EAAA,OAAO,EAAE,SAAS,MAAA,EAAO;AAC3B;AAEA,eAAsB,gBAAA,CAAiB,EAAE,MAAA,EAAQ,KAAA,EAAM,EAAsC;AAC3F,EAAA,IAAI;AACF,IAAA,MAAM,MAAA,GAAU,MAAM,MAAA,CAAO,UAAA,IAAc,SAAA,GAAY,KAAK,KAAM,EAAC;AACnE,IAAA,OAAO,MAAA;AAAA,EACT,SAAS,KAAA,EAAO;AACd,IAAA,OAAOA,6BAAA,CAAY,OAAO,oBAAoB,CAAA;AAAA,EAChD;AACF","file":"chunk-2GDLSAVJ.cjs","sourcesContent":["import type { RuntimeContext } from '@mastra/core/runtime-context';\nimport type { MastraScorerEntry, ScoreRowData } from '@mastra/core/scores';\nimport type { StoragePagination } from '@mastra/core/storage';\nimport type { Context } from '../types';\nimport { handleError } from './error';\n\nasync function getScorersFromSystem({\n mastra,\n runtimeContext,\n}: Context & {\n runtimeContext: RuntimeContext;\n}) {\n const agents = mastra.getAgents();\n const workflows = mastra.getWorkflows();\n\n const scorersMap = new Map<\n string,\n MastraScorerEntry & { agentIds: string[]; agentNames: string[]; workflowIds: string[]; isRegistered: boolean }\n >();\n\n for (const [agentId, agent] of Object.entries(agents)) {\n const scorers =\n (await agent.getScorers({\n runtimeContext,\n })) || {};\n\n if (Object.keys(scorers).length > 0) {\n for (const [_scorerId, scorer] of Object.entries(scorers)) {\n const scorerName = scorer.scorer.name;\n if (scorersMap.has(scorerName)) {\n scorersMap.get(scorerName)?.agentIds.push(agentId);\n scorersMap.get(scorerName)?.agentNames.push(agent.name);\n } else {\n scorersMap.set(scorerName, {\n workflowIds: [],\n ...scorer,\n agentNames: [agent.name],\n agentIds: [agentId],\n isRegistered: false,\n });\n }\n }\n }\n }\n\n for (const [workflowId, workflow] of Object.entries(workflows)) {\n const scorers =\n (await workflow.getScorers({\n runtimeContext,\n })) || {};\n\n if (Object.keys(scorers).length > 0) {\n for (const [_scorerId, scorer] of Object.entries(scorers)) {\n const scorerName = scorer.scorer.name;\n if (scorersMap.has(scorerName)) {\n scorersMap.get(scorerName)?.workflowIds.push(workflowId);\n } else {\n scorersMap.set(scorerName, {\n agentIds: [],\n agentNames: [],\n ...scorer,\n workflowIds: [workflowId],\n isRegistered: false,\n });\n }\n }\n }\n }\n\n const registeredScorers = await mastra.getScorers();\n for (const [_scorerId, scorer] of Object.entries(registeredScorers || {})) {\n const scorerName = scorer.name;\n if (scorersMap.has(scorerName)) {\n scorersMap.get(scorerName)!.isRegistered = true;\n } else {\n scorersMap.set(scorerName, {\n scorer: scorer,\n agentIds: [],\n agentNames: [],\n workflowIds: [],\n isRegistered: true,\n });\n }\n }\n\n return Object.fromEntries(scorersMap.entries());\n}\n\nexport async function getScorersHandler({ mastra, runtimeContext }: Context & { runtimeContext: RuntimeContext }) {\n const scorers = await getScorersFromSystem({\n mastra,\n runtimeContext,\n });\n\n return scorers;\n}\n\nexport async function getScorerHandler({\n mastra,\n scorerId,\n runtimeContext,\n}: Context & { scorerId: string; runtimeContext: RuntimeContext }) {\n const scorers = await getScorersFromSystem({\n mastra,\n runtimeContext,\n });\n\n const scorer = scorers[scorerId];\n\n if (!scorer) {\n return null;\n }\n\n return scorer;\n}\n\nexport async function getScoresByRunIdHandler({\n mastra,\n runId,\n pagination,\n}: Context & { runId: string; pagination: StoragePagination }) {\n try {\n const scoreResults = (await mastra.getStorage()?.getScoresByRunId?.({\n runId,\n pagination,\n })) || { pagination: { total: 0, page: 0, perPage: 0, hasMore: false }, scores: [] };\n return {\n pagination: scoreResults.pagination,\n scores: scoreResults.scores.map(score => ({ ...score, ...getTraceDetails(score.traceId) })),\n };\n } catch (error) {\n return handleError(error, 'Error getting scores by run id');\n }\n}\n\nexport async function getScoresByScorerIdHandler({\n mastra,\n scorerId,\n pagination,\n entityId,\n entityType,\n}: Context & { scorerId: string; pagination: StoragePagination; entityId?: string; entityType?: string }) {\n try {\n const scoreResults = (await mastra.getStorage()?.getScoresByScorerId?.({\n scorerId,\n pagination,\n entityId,\n entityType,\n })) || { pagination: { total: 0, page: 0, perPage: 0, hasMore: false }, scores: [] };\n return {\n pagination: scoreResults.pagination,\n scores: scoreResults.scores.map(score => ({ ...score, ...getTraceDetails(score.traceId) })),\n };\n } catch (error) {\n return handleError(error, 'Error getting scores by scorer id');\n }\n}\n\nexport async function getScoresByEntityIdHandler({\n mastra,\n entityId,\n entityType,\n pagination,\n}: Context & { entityId: string; entityType: string; pagination: StoragePagination }) {\n try {\n let entityIdToUse = entityId;\n\n if (entityType === 'AGENT') {\n const agent = mastra.getAgentById(entityId);\n entityIdToUse = agent.id;\n } else if (entityType === 'WORKFLOW') {\n const workflow = mastra.getWorkflowById(entityId);\n entityIdToUse = workflow.id;\n }\n\n const scoreResults = (await mastra.getStorage()?.getScoresByEntityId?.({\n entityId: entityIdToUse,\n entityType,\n pagination,\n })) || { pagination: { total: 0, page: 0, perPage: 0, hasMore: false }, scores: [] };\n\n return {\n pagination: scoreResults.pagination,\n scores: scoreResults.scores.map(score => ({ ...score, ...getTraceDetails(score.traceId) })),\n };\n } catch (error) {\n return handleError(error, 'Error getting scores by entity id');\n }\n}\n\nfunction getTraceDetails(traceIdWithSpanId?: string) {\n if (!traceIdWithSpanId) {\n return {};\n }\n\n const [traceId, spanId] = traceIdWithSpanId.split('-');\n return { traceId, spanId };\n}\n\nexport async function saveScoreHandler({ mastra, score }: Context & { score: ScoreRowData }) {\n try {\n const scores = (await mastra.getStorage()?.saveScore?.(score)) || [];\n return scores;\n } catch (error) {\n return handleError(error, 'Error saving score');\n }\n}\n"]}
1
+ {"version":3,"sources":["../src/server/handlers/scores.ts"],"names":["__export","handleError"],"mappings":";;;;;;AAAA,IAAA,cAAA,GAAA;AAAAA,0BAAA,CAAA,cAAA,EAAA;AAAA,EAAA,gBAAA,EAAA,MAAA,gBAAA;AAAA,EAAA,iBAAA,EAAA,MAAA,iBAAA;AAAA,EAAA,0BAAA,EAAA,MAAA,0BAAA;AAAA,EAAA,uBAAA,EAAA,MAAA,uBAAA;AAAA,EAAA,0BAAA,EAAA,MAAA,0BAAA;AAAA,EAAA,gBAAA,EAAA,MAAA;AAAA,CAAA,CAAA;AAMA,eAAe,oBAAA,CAAqB;AAAA,EAClC,MAAA;AAAA,EACA;AACF,CAAA,EAEG;AACD,EAAA,MAAM,MAAA,GAAS,OAAO,SAAA,EAAU;AAChC,EAAA,MAAM,SAAA,GAAY,OAAO,YAAA,EAAa;AAEtC,EAAA,MAAM,UAAA,uBAAiB,GAAA,EAGrB;AAEF,EAAA,KAAA,MAAW,CAAC,OAAA,EAAS,KAAK,KAAK,MAAA,CAAO,OAAA,CAAQ,MAAM,CAAA,EAAG;AACrD,IAAA,MAAM,OAAA,GACH,MAAM,KAAA,CAAM,UAAA,CAAW;AAAA,MACtB;AAAA,KACD,KAAM,EAAC;AAEV,IAAA,IAAI,MAAA,CAAO,IAAA,CAAK,OAAO,CAAA,CAAE,S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AE;AAEnF,IAAA,OAAO;AAAA,MACL,YAAY,YAAA,CAAa,UAAA;AAAA,MACzB,MAAA,EAAQ,YAAA,CAAa,MAAA,CAAO,GAAA,CAAI,CAAA,KAAA,MAAU,EAAE,GAAG,KAAA,EAAO,GAAG,eAAA,CAAgB,KAAA,CAAM,OAAO,GAAE,CAAE;AAAA,KAC5F;AAAA,EACF,SAAS,KAAA,EAAO;AACd,IAAA,OAAOA,6BAAA,CAAY,OAAO,mCAAmC,CAAA;AAAA,EAC/D;AACF;AAGA,SAAS,gBAAgB,iBAAA,EAA4B;AACnD,EAAA,IAAI,CAAC,iBAAA,EAAmB;AACtB,IAAA,OAAO,EAAC;AAAA,EACV;AAEA,EAAA,MAAM,CAAC,OAAA,EAAS,MAAM,CAAA,GAAI,iBAAA,CAAkB,MAAM,GAAG,CAAA;AACrD,EAAA,OAAO,EAAE,SAAS,MAAA,EAAO;AAC3B;AAEA,eAAsB,gBAAA,CAAiB,EAAE,MAAA,EAAQ,KAAA,EAAM,EAAsC;AAC3F,EAAA,IAAI;AACF,IAAA,MAAM,MAAA,GAAU,MAAM,MAAA,CAAO,UAAA,IAAc,SAAA,GAAY,KAAK,KAAM,EAAC;AACnE,IAAA,OAAO,MAAA;AAAA,EACT,SAAS,KAAA,EAAO;AACd,IAAA,OAAOA,6BAAA,CAAY,OAAO,oBAAoB,CAAA;AAAA,EAChD;AACF","file":"chunk-BKCWZLEL.cjs","sourcesContent":["import type { RuntimeContext } from '@mastra/core/runtime-context';\nimport type { MastraScorerEntry, ScoreRowData } from '@mastra/core/scores';\nimport type { StoragePagination } from '@mastra/core/storage';\nimport type { Context } from '../types';\nimport { handleError } from './error';\n\nasync function getScorersFromSystem({\n mastra,\n runtimeContext,\n}: Context & {\n runtimeContext: RuntimeContext;\n}) {\n const agents = mastra.getAgents();\n const workflows = mastra.getWorkflows();\n\n const scorersMap = new Map<\n string,\n MastraScorerEntry & { agentIds: string[]; agentNames: string[]; workflowIds: string[]; isRegistered: boolean }\n >();\n\n for (const [agentId, agent] of Object.entries(agents)) {\n const scorers =\n (await agent.getScorers({\n runtimeContext,\n })) || {};\n\n if (Object.keys(scorers).length > 0) {\n for (const [_scorerId, scorer] of Object.entries(scorers)) {\n const scorerName = scorer.scorer.name;\n if (scorersMap.has(scorerName)) {\n scorersMap.get(scorerName)?.agentIds.push(agentId);\n scorersMap.get(scorerName)?.agentNames.push(agent.name);\n } else {\n scorersMap.set(scorerName, {\n workflowIds: [],\n ...scorer,\n agentNames: [agent.name],\n agentIds: [agentId],\n isRegistered: false,\n });\n }\n }\n }\n }\n\n for (const [workflowId, workflow] of Object.entries(workflows)) {\n const scorers =\n (await workflow.getScorers({\n runtimeContext,\n })) || {};\n\n if (Object.keys(scorers).length > 0) {\n for (const [_scorerId, scorer] of Object.entries(scorers)) {\n const scorerName = scorer.scorer.name;\n if (scorersMap.has(scorerName)) {\n scorersMap.get(scorerName)?.workflowIds.push(workflowId);\n } else {\n scorersMap.set(scorerName, {\n agentIds: [],\n agentNames: [],\n ...scorer,\n workflowIds: [workflowId],\n isRegistered: false,\n });\n }\n }\n }\n }\n\n const registeredScorers = await mastra.getScorers();\n for (const [_scorerId, scorer] of Object.entries(registeredScorers || {})) {\n const scorerName = scorer.name;\n if (scorersMap.has(scorerName)) {\n scorersMap.get(scorerName)!.isRegistered = true;\n } else {\n scorersMap.set(scorerName, {\n scorer: scorer,\n agentIds: [],\n agentNames: [],\n workflowIds: [],\n isRegistered: true,\n });\n }\n }\n\n return Object.fromEntries(scorersMap.entries());\n}\n\nexport async function getScorersHandler({ mastra, runtimeContext }: Context & { runtimeContext: RuntimeContext }) {\n const scorers = await getScorersFromSystem({\n mastra,\n runtimeContext,\n });\n\n return scorers;\n}\n\nexport async function getScorerHandler({\n mastra,\n scorerId,\n runtimeContext,\n}: Context & { scorerId: string; runtimeContext: RuntimeContext }) {\n const scorers = await getScorersFromSystem({\n mastra,\n runtimeContext,\n });\n\n const scorer = scorers[scorerId];\n\n if (!scorer) {\n return null;\n }\n\n return scorer;\n}\n\nexport async function getScoresByRunIdHandler({\n mastra,\n runId,\n pagination,\n}: Context & { runId: string; pagination: StoragePagination }) {\n try {\n const scoreResults = (await mastra.getStorage()?.getScoresByRunId?.({\n runId,\n pagination,\n })) || { pagination: { total: 0, page: 0, perPage: 0, hasMore: false }, scores: [] };\n return {\n pagination: scoreResults.pagination,\n scores: scoreResults.scores.map(score => ({ ...score, ...getTraceDetails(score.traceId) })),\n };\n } catch (error) {\n return handleError(error, 'Error getting scores by run id');\n }\n}\n\nexport async function getScoresByScorerIdHandler({\n mastra,\n scorerId,\n pagination,\n entityId,\n entityType,\n}: Context & { scorerId: string; pagination: StoragePagination; entityId?: string; entityType?: string }) {\n try {\n const scoreResults = (await mastra.getStorage()?.getScoresByScorerId?.({\n scorerId,\n pagination,\n entityId,\n entityType,\n })) || { pagination: { total: 0, page: 0, perPage: 0, hasMore: false }, scores: [] };\n return {\n pagination: scoreResults.pagination,\n scores: scoreResults.scores.map(score => ({ ...score, ...getTraceDetails(score.traceId) })),\n };\n } catch (error) {\n return handleError(error, 'Error getting scores by scorer id');\n }\n}\n\nexport async function getScoresByEntityIdHandler({\n mastra,\n entityId,\n entityType,\n pagination,\n}: Context & { entityId: string; entityType: string; pagination: StoragePagination }) {\n try {\n let entityIdToUse = entityId;\n\n if (entityType === 'AGENT') {\n const agent = mastra.getAgentById(entityId);\n entityIdToUse = agent.id;\n } else if (entityType === 'WORKFLOW') {\n const workflow = mastra.getWorkflowById(entityId);\n entityIdToUse = workflow.id;\n }\n\n const scoreResults = (await mastra.getStorage()?.getScoresByEntityId?.({\n entityId: entityIdToUse,\n entityType,\n pagination,\n })) || { pagination: { total: 0, page: 0, perPage: 0, hasMore: false }, scores: [] };\n\n return {\n pagination: scoreResults.pagination,\n scores: scoreResults.scores.map(score => ({ ...score, ...getTraceDetails(score.traceId) })),\n };\n } catch (error) {\n return handleError(error, 'Error getting scores by entity id');\n }\n}\n\n// Legacy function to get trace and span details\nfunction getTraceDetails(traceIdWithSpanId?: string) {\n if (!traceIdWithSpanId) {\n return {};\n }\n\n const [traceId, spanId] = traceIdWithSpanId.split('-');\n return { traceId, spanId };\n}\n\nexport async function saveScoreHandler({ mastra, score }: Context & { score: ScoreRowData }) {\n try {\n const scores = (await mastra.getStorage()?.saveScore?.(score)) || [];\n return scores;\n } catch (error) {\n return handleError(error, 'Error saving score');\n }\n}\n"]}