@mastra/server 1.80.0 → 1.81.0-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.
Files changed (86) hide show
  1. package/dist/_types/@mastra_schema-compat/dist/_types/@internal_ai-sdk-v4/dist/index.d.ts +51 -12
  2. package/dist/_types/@mastra_schema-compat/dist/_types/@internal_ai-sdk-v5/dist/index.d.ts +144 -42
  3. package/dist/_types/@mastra_schema-compat/dist/_types/@internal_ai-v6/dist/index.d.ts +53 -14
  4. package/dist/{agent-builder-DXhQCXod.cjs → agent-builder-DIEX-as5.cjs} +2 -2
  5. package/dist/{agent-builder-DXhQCXod.cjs.map → agent-builder-DIEX-as5.cjs.map} +1 -1
  6. package/dist/{agent-builder-CrmZ77IU.js → agent-builder-XhBB0Svr.js} +2 -2
  7. package/dist/{agent-builder-CrmZ77IU.js.map → agent-builder-XhBB0Svr.js.map} +1 -1
  8. package/dist/{api-schema-manifest-JUFooPZG.js → api-schema-manifest-BVPhF1ZS.js} +2 -2
  9. package/dist/{api-schema-manifest-JUFooPZG.js.map → api-schema-manifest-BVPhF1ZS.js.map} +1 -1
  10. package/dist/{api-schema-manifest-CwFjht0V.cjs → api-schema-manifest-BWId44SV.cjs} +2 -2
  11. package/dist/{api-schema-manifest-CwFjht0V.cjs.map → api-schema-manifest-BWId44SV.cjs.map} +1 -1
  12. package/dist/{dist-qgP3izdE.cjs → dist-BK1fCE4z.cjs} +1 -1
  13. package/dist/{dist-DK9HHAgo.js → dist-BLjE21MA.js} +2143 -2025
  14. package/dist/dist-BLjE21MA.js.map +1 -0
  15. package/dist/{dist-DXDt4qI1.cjs → dist-OpNBTIST.cjs} +2191 -2031
  16. package/dist/dist-OpNBTIST.cjs.map +1 -0
  17. package/dist/dist-_M1jEPcL.js +1 -0
  18. package/dist/docs/SKILL.md +1 -1
  19. package/dist/docs/assets/SOURCE_MAP.json +1 -1
  20. package/dist/docs/references/reference-observability-tracing-advanced-queries.md +33 -16
  21. package/dist/{memory-DQXCDswv.js → memory-BTR95ujT.js} +3 -3
  22. package/dist/{memory-DQXCDswv.js.map → memory-BTR95ujT.js.map} +1 -1
  23. package/dist/{memory-DpKQ1Quf.cjs → memory-Buhi6kZ-.cjs} +3 -3
  24. package/dist/{memory-DpKQ1Quf.cjs.map → memory-Buhi6kZ-.cjs.map} +1 -1
  25. package/dist/{observability-65rZOqJk.js → observability-BgIU0otL.js} +2 -2
  26. package/dist/{observability-65rZOqJk.js.map → observability-BgIU0otL.js.map} +1 -1
  27. package/dist/{observability-CFKSxaff.cjs → observability-DHuljMXO.cjs} +2 -2
  28. package/dist/{observability-CFKSxaff.cjs.map → observability-DHuljMXO.cjs.map} +1 -1
  29. package/dist/{observability-new-endpoints-CDeHfFNP.cjs → observability-new-endpoints-CaTskbSh.cjs} +12 -3
  30. package/dist/observability-new-endpoints-CaTskbSh.cjs.map +1 -0
  31. package/dist/{observability-new-endpoints-B6MRJ5Rb.js → observability-new-endpoints-CsUP8y2j.js} +13 -4
  32. package/dist/observability-new-endpoints-CsUP8y2j.js.map +1 -0
  33. package/dist/{probe-image-size-DqKTuApZ.cjs → probe-image-size-BIZUe8Bp.cjs} +50 -678
  34. package/dist/probe-image-size-BIZUe8Bp.cjs.map +1 -0
  35. package/dist/{probe-image-size-BLtXo-AD.js → probe-image-size-BqH96zcz.js} +50 -678
  36. package/dist/probe-image-size-BqH96zcz.js.map +1 -0
  37. package/dist/{routes-CbwRkg8_.cjs → routes-By3cLbPV.cjs} +5 -5
  38. package/dist/{routes-CbwRkg8_.cjs.map → routes-By3cLbPV.cjs.map} +1 -1
  39. package/dist/{routes-M2U8U4Jl.js → routes-CBrxFxzL.js} +5 -5
  40. package/dist/{routes-M2U8U4Jl.js.map → routes-CBrxFxzL.js.map} +1 -1
  41. package/dist/server/handlers/agent-builder.cjs +1 -1
  42. package/dist/server/handlers/agent-builder.js +1 -1
  43. package/dist/server/handlers/memory.cjs +1 -1
  44. package/dist/server/handlers/memory.js +1 -1
  45. package/dist/server/handlers/observability-new-endpoints.cjs +1 -1
  46. package/dist/server/handlers/observability-new-endpoints.d.ts +36 -4
  47. package/dist/server/handlers/observability-new-endpoints.d.ts.map +1 -1
  48. package/dist/server/handlers/observability-new-endpoints.js +1 -1
  49. package/dist/server/handlers/observability-shared.cjs +27 -0
  50. package/dist/server/handlers/observability-shared.cjs.map +1 -1
  51. package/dist/server/handlers/observability-shared.d.ts +10 -0
  52. package/dist/server/handlers/observability-shared.d.ts.map +1 -1
  53. package/dist/server/handlers/observability-shared.js +24 -1
  54. package/dist/server/handlers/observability-shared.js.map +1 -1
  55. package/dist/server/handlers/observability.cjs +2 -2
  56. package/dist/server/handlers/observability.js +2 -2
  57. package/dist/server/handlers/system.cjs +2 -2
  58. package/dist/server/handlers/system.d.ts +4 -0
  59. package/dist/server/handlers/system.d.ts.map +1 -1
  60. package/dist/server/handlers/system.js +2 -2
  61. package/dist/server/handlers.cjs +3 -3
  62. package/dist/server/handlers.js +3 -3
  63. package/dist/server/schemas/index.cjs +1 -1
  64. package/dist/server/schemas/index.js +1 -1
  65. package/dist/server/schemas/system.d.ts +4 -0
  66. package/dist/server/schemas/system.d.ts.map +1 -1
  67. package/dist/server/server-adapter/index.cjs +1 -1
  68. package/dist/server/server-adapter/index.js +1 -1
  69. package/dist/server/server-adapter/routes/observability.d.ts +18 -2
  70. package/dist/server/server-adapter/routes/observability.d.ts.map +1 -1
  71. package/dist/server/server-adapter/routes/system.d.ts +4 -0
  72. package/dist/server/server-adapter/routes/system.d.ts.map +1 -1
  73. package/dist/{system-DGfJlOxK.cjs → system-BxHpBJiq.cjs} +3 -1
  74. package/dist/system-BxHpBJiq.cjs.map +1 -0
  75. package/dist/{system-B8L_G4oo.js → system-CxwzIMsy.js} +3 -1
  76. package/dist/system-CxwzIMsy.js.map +1 -0
  77. package/package.json +6 -6
  78. package/dist/dist-C_xVj979.js +0 -1
  79. package/dist/dist-DK9HHAgo.js.map +0 -1
  80. package/dist/dist-DXDt4qI1.cjs.map +0 -1
  81. package/dist/observability-new-endpoints-B6MRJ5Rb.js.map +0 -1
  82. package/dist/observability-new-endpoints-CDeHfFNP.cjs.map +0 -1
  83. package/dist/probe-image-size-BLtXo-AD.js.map +0 -1
  84. package/dist/probe-image-size-DqKTuApZ.cjs.map +0 -1
  85. package/dist/system-B8L_G4oo.js.map +0 -1
  86. package/dist/system-DGfJlOxK.cjs.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"observability-shared.js","names":["candidate"],"sources":["../../../src/server/handlers/observability-shared.ts"],"sourcesContent":["import type { Mastra } from '@mastra/core';\nimport { coreFeatures } from '@mastra/core/features';\nimport type {\n MastraCompositeStore,\n ObservabilityStorage,\n ScoresStorage,\n TraceQueryIssue,\n TrustedTraceQueryScalarPredicate,\n TrustedThreadPredicate,\n TrustedTraceQueryPredicate,\n} from '@mastra/core/storage';\nimport * as coreStorage from '@mastra/core/storage';\nimport { z } from 'zod/v4';\nimport { HTTPException } from '../http-exception';\nimport type { ServerRoute } from '../server-adapter/routes';\nimport { wrapSchemaForQueryParams } from '../server-adapter/routes/route-builder';\nimport {\n deltaCursorSchema,\n deltaLimitSchema,\n listModeSchema,\n paginationArgsSchema,\n} from './observability-list-query-schemas';\n\nexport const OBSERVABILITY_DELTA_POLLING_FEATURE = 'observability-delta-polling';\nexport const OBSERVABILITY_DELTA_POLLING_UPGRADE_MESSAGE =\n 'Delta polling requires a newer @mastra/core with observability delta polling support. Please upgrade.';\nconst OBSERVABILITY_TRACE_QUERY_STORAGE_FEATURE = 'trace-query';\nconst OBSERVABILITY_TRACE_AGGREGATE_STORAGE_FEATURE = 'trace-aggregate';\nconst OBSERVABILITY_SPAN_QUERY_STORAGE_FEATURE = 'span-query';\nconst OBSERVABILITY_SPAN_AGGREGATE_STORAGE_FEATURE = 'span-aggregate';\nconst SPAN_QUERY_CONTEXT_FIELDS = new Set([\n 'traceId',\n 'spanId',\n 'parentSpanId',\n 'threadId',\n 'resourceId',\n 'requestId',\n 'serviceName',\n 'experimentId',\n 'environment',\n 'executionSource',\n 'parentEntityType',\n 'parentEntityId',\n 'parentEntityName',\n 'rootEntityType',\n 'rootEntityId',\n 'rootEntityName',\n]);\nconst OBSERVABILITY_TRACE_QUERY_ROOT_DURATION_STORAGE_FEATURE = 'trace-query-root-duration';\nconst OBSERVABILITY_TRACE_QUERY_CONTEXT_IDS_STORAGE_FEATURE = 'trace-query-context-ids';\nconst TRACE_QUERY_CONTEXT_ID_FIELDS = new Set(['runId', 'sessionId', 'userId', 'organizationId']);\nconst OBSERVABILITY_TRACE_QUERY_TIME_TO_FIRST_CHUNK_STORAGE_FEATURE = 'trace-query-time-to-first-chunk';\nconst TRACE_QUERY_TIME_TO_FIRST_CHUNK_FIELDS = new Set(['timeToFirstChunkMs']);\nconst OBSERVABILITY_TRACE_QUERY_ROOT_SPAN_FIELDS_STORAGE_FEATURE = 'trace-query-root-span-fields';\nconst OBSERVABILITY_TRACE_QUERY_ROOT_ENTITY_ID_STORAGE_FEATURE = 'trace-query-root-entity-id';\n// Trace-scope fields read from the root span, keyed by the storage feature that added their SQL.\nconst TRACE_QUERY_ROOT_SPAN_FIELD_FEATURES = new Map([\n ['name', OBSERVABILITY_TRACE_QUERY_ROOT_SPAN_FIELDS_STORAGE_FEATURE],\n ['spanType', OBSERVABILITY_TRACE_QUERY_ROOT_SPAN_FIELDS_STORAGE_FEATURE],\n ['entityId', OBSERVABILITY_TRACE_QUERY_ROOT_ENTITY_ID_STORAGE_FEATURE],\n]);\nconst OBSERVABILITY_TRACE_QUERY_TIME_TO_FIRST_CHUNK_SORT_STORAGE_FEATURE = 'trace-query-time-to-first-chunk-sort';\nconst OBSERVABILITY_TRACE_QUERY_DISCOVERY_STORAGE_FEATURE = 'trace-query-discovery';\nconst OBSERVABILITY_THREAD_QUERY_STORAGE_FEATURE = 'thread-query';\nconst OBSERVABILITY_TRACE_QUERY_TENANT_SCOPE_STORAGE_FEATURE = 'trace-query-tenant-scope';\nconst OBSERVABILITY_FEEDBACK_STORAGE_FEATURE = 'feedback';\nexport const OBSERVABILITY_TRACE_QUERY_TENANT_SCOPE_CORE_FEATURE = 'observability-trace-query-tenant-scope';\nexport const OBSERVABILITY_TRACE_QUERY_TENANT_SCOPE_UPGRADE_MESSAGE =\n 'Trusted tenant scope requires a newer @mastra/core with trace-query tenant scope support. Please upgrade.';\n\nexport function supportsTraceQueryDiscoveryCore() {\n return (\n coreStorage.getTraceQueryFieldsArgsSchema !== undefined &&\n coreStorage.getTraceQueryFieldsResponseSchema !== undefined &&\n coreStorage.getTraceQueryValuesArgsSchema !== undefined &&\n coreStorage.getTraceQueryValuesResponseSchema !== undefined &&\n typeof coreStorage.planTraceQueryObservedFields === 'function' &&\n typeof coreStorage.planTraceQueryValues === 'function' &&\n typeof coreStorage.getTraceQueryCanonicalFieldDescriptors === 'function' &&\n typeof coreStorage.TraceQueryResourceLimitError === 'function'\n );\n}\n\nexport function supportsTraceAggregateCore() {\n return (\n coreStorage.traceAggregateRequestSchema !== undefined &&\n coreStorage.traceAggregateResponseSchema !== undefined &&\n typeof coreStorage.planTraceAggregate === 'function'\n );\n}\n\nexport function supportsSpanAggregateCore() {\n return (\n coreStorage.spanAggregateRequestSchema !== undefined &&\n coreStorage.spanAggregateResponseSchema !== undefined &&\n typeof coreStorage.planSpanAggregate === 'function'\n );\n}\n\nexport function supportsSpanQueryCore() {\n return (\n coreStorage.spanQueryRequestSchema !== undefined &&\n coreStorage.spanQueryResponseSchema !== undefined &&\n typeof coreStorage.planSpanQuery === 'function'\n );\n}\n\nexport const OBSERVABILITY_LIST_ENDPOINTS = {\n traces: 'traces',\n branches: 'branches',\n logs: 'logs',\n metrics: 'metrics',\n scores: 'scores',\n feedback: 'feedback',\n} as const;\n\nexport type ObservabilityListEndpoint =\n (typeof OBSERVABILITY_LIST_ENDPOINTS)[keyof typeof OBSERVABILITY_LIST_ENDPOINTS];\nconst OBSERVABILITY_DELTA_POLLING_STORAGE_FEATURE = 'delta-polling';\n\nfunction getFeatures(observabilityStore: ObservabilityStorage): readonly string[] | undefined {\n const candidate = observabilityStore as ObservabilityStorage & {\n getFeatures?: () => readonly string[] | undefined;\n };\n return candidate.getFeatures?.();\n}\n\n/** Retrieves MastraCompositeStore or throws 500 if unavailable. */\nexport function getStorage(mastra: Mastra): MastraCompositeStore {\n const storage = mastra.getStorage();\n if (!storage) {\n throw new HTTPException(500, { message: 'Storage is not available' });\n }\n return storage;\n}\n\n/** Retrieves the observability storage domain or throws 501 if unavailable. */\nexport async function getObservabilityStore(mastra: Mastra): Promise<ObservabilityStorage> {\n const storage = getStorage(mastra);\n const observability = await storage.getStore('observability');\n if (!observability) {\n // 501, not 500: a missing or explicitly disabled observability domain\n // (e.g. `domains: { observability: false }`) is a capability gap, not a\n // server failure — matching the other 501s in this file.\n throw new HTTPException(501, { message: 'Observability storage domain is not available' });\n }\n return observability;\n}\n\n/** Retrieves the scores storage domain or throws 501 if unavailable. */\nexport async function getScoresStore(mastra: Mastra): Promise<ScoresStorage> {\n const storage = getStorage(mastra);\n const scores = await storage.getStore('scores');\n if (!scores) {\n throw new HTTPException(501, { message: 'Scores storage domain is not available' });\n }\n return scores;\n}\n\nexport function assertObservabilityTraceQuerySupported(observabilityStore: ObservabilityStorage) {\n if (getFeatures(observabilityStore)?.includes(OBSERVABILITY_TRACE_QUERY_STORAGE_FEATURE)) return;\n\n throw new HTTPException(501, {\n message: 'Advanced trace queries are not supported by the configured observability store',\n });\n}\n\nexport function supportsObservabilityTraceAggregate(observabilityStore: ObservabilityStorage) {\n return getFeatures(observabilityStore)?.includes(OBSERVABILITY_TRACE_AGGREGATE_STORAGE_FEATURE) === true;\n}\n\nexport function assertObservabilityTraceAggregateSupported(observabilityStore: ObservabilityStorage) {\n if (supportsObservabilityTraceAggregate(observabilityStore)) return;\n\n throw new HTTPException(501, {\n message: 'Trace aggregation is not supported by the configured observability store',\n });\n}\n\nexport function assertObservabilitySpanAggregateSupported(observabilityStore: ObservabilityStorage) {\n if (getFeatures(observabilityStore)?.includes(OBSERVABILITY_SPAN_AGGREGATE_STORAGE_FEATURE)) return;\n\n throw new HTTPException(501, {\n message: 'Span aggregation is not supported by the configured observability store',\n });\n}\n\nexport function assertObservabilitySpanQuerySupported(observabilityStore: ObservabilityStorage) {\n if (getFeatures(observabilityStore)?.includes(OBSERVABILITY_SPAN_QUERY_STORAGE_FEATURE)) return;\n\n throw new HTTPException(501, {\n message: 'Span queries are not supported by the configured observability store',\n });\n}\n\nexport function assertObservabilitySpanQueryFieldsSupported(\n observabilityStore: ObservabilityStorage,\n predicate: TrustedTraceQueryScalarPredicate | undefined,\n) {\n if (!predicate || getFeatures(observabilityStore)?.includes('span-query-context-fields')) return;\n if (predicate.type === 'boolean') {\n for (const arg of predicate.args) assertObservabilitySpanQueryFieldsSupported(observabilityStore, arg);\n } else if (predicate.type === 'not') {\n assertObservabilitySpanQueryFieldsSupported(observabilityStore, predicate.arg);\n } else if (SPAN_QUERY_CONTEXT_FIELDS.has(predicate.field)) {\n throw new coreStorage.TraceQueryValidationError([\n {\n code: 'field_not_allowed',\n path: ['where'],\n message: `Filtering by ${predicate.field} requires an updated storage adapter with span query context-field support.`,\n },\n ]);\n }\n}\n\nfunction usesRootDuration(predicate: TrustedTraceQueryPredicate | TrustedThreadPredicate | undefined): boolean {\n if (!predicate) return false;\n if (predicate.type === 'boolean') return predicate.args.some(usesRootDuration);\n if (predicate.type === 'not') return usesRootDuration(predicate.arg);\n if (predicate.type === 'relation') {\n return predicate.collection === 'traces' && usesRootDuration(predicate.predicate);\n }\n return predicate.field === 'durationMs';\n}\n\nexport function supportsObservabilityTraceQueryRootDuration(observabilityStore: ObservabilityStorage) {\n return getFeatures(observabilityStore)?.includes(OBSERVABILITY_TRACE_QUERY_ROOT_DURATION_STORAGE_FEATURE) === true;\n}\n\nexport function assertObservabilityTraceQueryRootDurationSupported(\n observabilityStore: ObservabilityStorage,\n predicate: TrustedTraceQueryPredicate | TrustedThreadPredicate | undefined,\n) {\n if (!usesRootDuration(predicate) || supportsObservabilityTraceQueryRootDuration(observabilityStore)) return;\n\n throw new HTTPException(501, {\n message: 'Root duration predicates are not supported by the configured observability store',\n });\n}\n\n/** Whether any scalar predicate, at any depth and inside any relation, names one of `fields`. */\nfunction usesField(\n predicate: TrustedTraceQueryPredicate | TrustedThreadPredicate | undefined,\n fields: ReadonlySet<string>,\n): boolean {\n if (!predicate) return false;\n if (predicate.type === 'boolean') return predicate.args.some(arg => usesField(arg, fields));\n if (predicate.type === 'not') return usesField(predicate.arg, fields);\n if (predicate.type === 'relation') return usesField(predicate.predicate, fields);\n return fields.has(predicate.field);\n}\n\nexport function supportsObservabilityTraceQueryContextIds(observabilityStore: ObservabilityStorage) {\n return getFeatures(observabilityStore)?.includes(OBSERVABILITY_TRACE_QUERY_CONTEXT_IDS_STORAGE_FEATURE) === true;\n}\n\nexport function isTraceQueryContextIdField(path: string): boolean {\n return TRACE_QUERY_CONTEXT_ID_FIELDS.has(path);\n}\n\nexport function assertObservabilityTraceQueryContextIdsSupported(\n observabilityStore: ObservabilityStorage,\n predicate: TrustedTraceQueryPredicate | TrustedThreadPredicate | undefined,\n) {\n if (\n !usesField(predicate, TRACE_QUERY_CONTEXT_ID_FIELDS) ||\n supportsObservabilityTraceQueryContextIds(observabilityStore)\n ) {\n return;\n }\n\n throw new HTTPException(501, {\n message: 'Context identifier predicates are not supported by the configured observability store',\n });\n}\n\nexport function supportsObservabilityTraceQueryTimeToFirstChunk(observabilityStore: ObservabilityStorage) {\n return (\n getFeatures(observabilityStore)?.includes(OBSERVABILITY_TRACE_QUERY_TIME_TO_FIRST_CHUNK_STORAGE_FEATURE) === true\n );\n}\n\n/** Covers trace, thread and span query predicates, including `spans` and `traces` relations. */\nexport function assertObservabilityTraceQueryTimeToFirstChunkSupported(\n observabilityStore: ObservabilityStorage,\n predicate: TrustedTraceQueryPredicate | TrustedThreadPredicate | undefined,\n) {\n if (\n !usesField(predicate, TRACE_QUERY_TIME_TO_FIRST_CHUNK_FIELDS) ||\n supportsObservabilityTraceQueryTimeToFirstChunk(observabilityStore)\n ) {\n return;\n }\n\n throw new HTTPException(501, {\n message: 'Time to first chunk predicates are not supported by the configured observability store',\n });\n}\n\nfunction rootSpanFieldIssues(\n observabilityStore: ObservabilityStorage,\n predicate: TrustedTraceQueryPredicate | TrustedThreadPredicate | undefined,\n): TraceQueryIssue[] {\n if (!predicate) return [];\n if (predicate.type === 'boolean') return predicate.args.flatMap(arg => rootSpanFieldIssues(observabilityStore, arg));\n if (predicate.type === 'not') return rootSpanFieldIssues(observabilityStore, predicate.arg);\n // Only trace-scope root span fields read the root; inside `spans.some` they are long-supported span fields.\n if (predicate.type === 'relation') {\n return predicate.collection === 'traces' ? rootSpanFieldIssues(observabilityStore, predicate.predicate) : [];\n }\n return supportsObservabilityTraceQueryRootSpanField(observabilityStore, predicate.field)\n ? []\n : [rootSpanFieldIssue(['where'], predicate.field)];\n}\n\nfunction rootSpanFieldIssue(path: Array<string | number>, field: string): TraceQueryIssue {\n return {\n code: 'field_not_allowed',\n path,\n message: `Root span ${field} requires an updated storage adapter with trace-query root span field support.`,\n };\n}\n\n/**\n * Whether the store can serve `path` at trace scope. Fields that don't read the root span are\n * always supported here; other gates cover them.\n */\nexport function supportsObservabilityTraceQueryRootSpanField(observabilityStore: ObservabilityStorage, path: string) {\n const feature = TRACE_QUERY_ROOT_SPAN_FIELD_FEATURES.get(path);\n return feature === undefined || getFeatures(observabilityStore)?.includes(feature) === true;\n}\n\n/**\n * Stores that predate a trace-scope root span field have no SQL for it and would fail with a\n * 500, so requests that use it are rejected as invalid instead.\n */\nexport function assertObservabilityTraceQueryRootSpanFieldsSupported(\n observabilityStore: ObservabilityStorage,\n plan: {\n where?: TrustedTraceQueryPredicate | TrustedThreadPredicate;\n dimensions?: readonly string[];\n measures?: ReadonlyArray<{ type: string; field?: string }>;\n },\n) {\n const supported = (field: string) => supportsObservabilityTraceQueryRootSpanField(observabilityStore, field);\n const issues = [\n ...rootSpanFieldIssues(observabilityStore, plan.where),\n ...(plan.dimensions ?? []).flatMap((dimension, index) =>\n supported(dimension) ? [] : [rootSpanFieldIssue(['groupBy', index], dimension)],\n ),\n ...(plan.measures ?? []).flatMap((measure, index) =>\n measure.type === 'countDistinct' && measure.field !== undefined && !supported(measure.field)\n ? [rootSpanFieldIssue(['measures', index], measure.field)]\n : [],\n ),\n ];\n if (issues.length > 0) throw new coreStorage.TraceQueryValidationError(issues);\n}\n\nexport function assertObservabilityTraceQueryRootSpanValuesSupported(\n observabilityStore: ObservabilityStorage,\n plan: { predicateScope: string; path: string },\n) {\n if (plan.predicateScope !== 'trace') return;\n if (supportsObservabilityTraceQueryRootSpanField(observabilityStore, plan.path)) return;\n throw new coreStorage.TraceQueryValidationError([rootSpanFieldIssue(['path'], plan.path)]);\n}\n\nexport function supportsObservabilityTraceQueryTimeToFirstChunkSort(observabilityStore: ObservabilityStorage) {\n return (\n getFeatures(observabilityStore)?.includes(OBSERVABILITY_TRACE_QUERY_TIME_TO_FIRST_CHUNK_SORT_STORAGE_FEATURE) ===\n true\n );\n}\n\n/** Covers the sort of trace and span queries. */\nexport function assertObservabilityTraceQueryTimeToFirstChunkSortSupported(\n observabilityStore: ObservabilityStorage,\n orderBy: { field: string },\n) {\n if (\n !TRACE_QUERY_TIME_TO_FIRST_CHUNK_FIELDS.has(orderBy.field) ||\n supportsObservabilityTraceQueryTimeToFirstChunkSort(observabilityStore)\n ) {\n return;\n }\n\n throw new HTTPException(501, {\n message: 'Sorting by time to first chunk is not supported by the configured observability store',\n });\n}\n\nexport function assertObservabilityTraceQueryDiscoverySupported(observabilityStore: ObservabilityStorage) {\n if (getFeatures(observabilityStore)?.includes(OBSERVABILITY_TRACE_QUERY_DISCOVERY_STORAGE_FEATURE)) return;\n\n throw new HTTPException(501, {\n message: 'Trace query discovery is not supported by the configured observability store',\n });\n}\n\n/**\n * A scoped request must never run unscoped: a store that predates tenant scope would\n * silently ignore `plan.scope` and return every tenant's rows, so it is rejected instead.\n * Unscoped requests are unaffected.\n */\nexport function assertObservabilityTraceQueryTenantScopeSupported(\n observabilityStore: ObservabilityStorage,\n scope: coreStorage.TraceQueryTenantScope | undefined,\n) {\n if (scope === undefined) return;\n if (getFeatures(observabilityStore)?.includes(OBSERVABILITY_TRACE_QUERY_TENANT_SCOPE_STORAGE_FEATURE)) return;\n\n throw new HTTPException(501, {\n message: 'The configured observability store cannot enforce the trusted tenant scope',\n });\n}\n\nexport function assertObservabilityThreadQuerySupported(observabilityStore: ObservabilityStorage) {\n if (getFeatures(observabilityStore)?.includes(OBSERVABILITY_THREAD_QUERY_STORAGE_FEATURE)) return;\n\n throw new HTTPException(501, {\n message: 'Advanced thread queries are not supported by the configured observability store',\n });\n}\n\n/**\n * Returns true when the store's class chain overrides `method` below the class\n * that first declares it (the `ObservabilityStorage` base, whose default\n * throws `*_NOT_IMPLEMENTED`). Walks the store's own prototype chain instead of\n * comparing against this package's `ObservabilityStorage.prototype`, so it\n * works for stores built against older or duplicated `@mastra/core` installs\n * and for stores that predate {@link ObservabilityStorage.getFeatures}.\n */\nfunction implementsObservabilityStorageMethod(observabilityStore: object, method: string): boolean {\n if (Object.prototype.hasOwnProperty.call(observabilityStore, method)) return true;\n\n let resolvedOwner: object | undefined;\n let declaringBase: object | undefined;\n for (\n let proto: object | null = Object.getPrototypeOf(observabilityStore);\n proto && proto !== Object.prototype;\n proto = Object.getPrototypeOf(proto)\n ) {\n if (Object.prototype.hasOwnProperty.call(proto, method)) {\n resolvedOwner ??= proto;\n declaringBase = proto;\n }\n }\n return resolvedOwner !== undefined && resolvedOwner !== declaringBase;\n}\n\nexport type ObservabilityDiscoveryCapabilities = {\n entityTypes: boolean;\n entityNames: boolean;\n serviceNames: boolean;\n environments: boolean;\n tags: boolean;\n metrics: boolean;\n};\n\nexport type ObservabilityStorageCapabilities = {\n metrics: boolean;\n logs: boolean;\n discovery: ObservabilityDiscoveryCapabilities;\n deltaPolling: boolean;\n traceQuery: boolean;\n traceQueryRootDuration: boolean;\n traceQueryContextIds: boolean;\n traceQueryTimeToFirstChunk: boolean;\n traceQueryRootSpanFields: boolean;\n traceQueryRootEntityId: boolean;\n traceQueryTimeToFirstChunkSort: boolean;\n traceQueryDiscovery: boolean;\n traceQueryTenantScope: boolean;\n traceAggregate: boolean;\n threadQuery: boolean;\n threadQueryRows: boolean;\n spanQuery: boolean;\n spanQueryContextFields: boolean;\n spanAggregate: boolean;\n /** Days of traces the store keeps. Omitted when the store does not report a limit. */\n traceRetentionDays?: number;\n feedback: boolean;\n};\n\nexport const NO_OBSERVABILITY_STORAGE_CAPABILITIES: ObservabilityStorageCapabilities = {\n metrics: false,\n logs: false,\n discovery: {\n entityTypes: false,\n entityNames: false,\n serviceNames: false,\n environments: false,\n tags: false,\n metrics: false,\n },\n deltaPolling: false,\n traceQuery: false,\n traceQueryRootDuration: false,\n traceQueryContextIds: false,\n traceQueryTimeToFirstChunk: false,\n traceQueryRootSpanFields: false,\n traceQueryRootEntityId: false,\n traceQueryTimeToFirstChunkSort: false,\n traceQueryDiscovery: false,\n traceQueryTenantScope: false,\n traceAggregate: false,\n threadQuery: false,\n threadQueryRows: false,\n spanQuery: false,\n spanAggregate: false,\n spanQueryContextFields: false,\n feedback: false,\n};\n\n/**\n * Resolves which optional observability APIs the configured store can serve.\n *\n * Feature declarations (`getFeatures()`) are optional. When a store declares\n * a feature list, that list is final. Stores without `getFeatures()` predate\n * declarations: metrics, logs and filter discovery are detected by whether the\n * store implements the underlying method, so those packages report accurately\n * without being upgraded. Delta polling and the trace/thread query APIs depend\n * on runtime behavior a method check can't see, so they are only reported for\n * stores that declare them. Feedback is also declaration-only: Studio hides\n * the feedback UI behind this flag, and store versions that implement feedback\n * without declaring it simply don't advertise it until upgraded.\n */\nexport function getObservabilityStorageCapabilities(\n observabilityStore: ObservabilityStorage,\n): ObservabilityStorageCapabilities {\n const declaredFeatures = getFeatures(observabilityStore);\n const features = declaredFeatures ?? [];\n const newApiCore = coreFeatures.has('observability:v1.13.2');\n const declares = (feature: string) => features.includes(feature);\n // Undeclared stores must implement every method behind the feature.\n const supports = (feature: string, methods: readonly string[]) => {\n if (!newApiCore) return false;\n if (!declaredFeatures) {\n return methods.every(method => implementsObservabilityStorageMethod(observabilityStore, method));\n }\n return declares(feature);\n };\n // Stores released before the per-endpoint discovery features existed declare\n // `trace-query` and implement every discovery method, so treat it as implying discovery.\n const supportsDiscovery = (feature: string, methods: readonly string[]) =>\n supports(feature, methods) || (newApiCore && declares(OBSERVABILITY_TRACE_QUERY_STORAGE_FEATURE));\n const traceQuery =\n newApiCore &&\n typeof coreStorage.planTraceQuery === 'function' &&\n declares(OBSERVABILITY_TRACE_QUERY_STORAGE_FEATURE);\n const threadQuery =\n newApiCore &&\n typeof coreStorage.planThreadQuery === 'function' &&\n declares(OBSERVABILITY_THREAD_QUERY_STORAGE_FEATURE);\n const spanQuery = newApiCore && supportsSpanQueryCore() && declares(OBSERVABILITY_SPAN_QUERY_STORAGE_FEATURE);\n\n return {\n // `listMetrics` is left out: it backs a newer route that metric dashboards don't use,\n // and older stores that implement the OLAP methods predate it.\n metrics: supports('metrics', [\n 'getMetricAggregate',\n 'getMetricBreakdown',\n 'getMetricTimeSeries',\n 'getMetricPercentiles',\n ]),\n logs: supports('logs', ['listLogs']),\n discovery: {\n entityTypes: supportsDiscovery('entity-type-discovery', ['getEntityTypes']),\n entityNames: supportsDiscovery('entity-name-discovery', ['getEntityNames']),\n serviceNames: supportsDiscovery('service-name-discovery', ['getServiceNames']),\n environments: supportsDiscovery('environment-discovery', ['getEnvironments']),\n tags: supportsDiscovery('tag-discovery', ['getTags']),\n metrics: supportsDiscovery('metric-discovery', ['getMetricNames', 'getMetricLabelKeys', 'getMetricLabelValues']),\n },\n deltaPolling:\n coreFeatures.has(OBSERVABILITY_DELTA_POLLING_FEATURE) && declares(OBSERVABILITY_DELTA_POLLING_STORAGE_FEATURE),\n traceQuery,\n traceQueryRootDuration:\n (traceQuery || threadQuery) && declares(OBSERVABILITY_TRACE_QUERY_ROOT_DURATION_STORAGE_FEATURE),\n traceQueryContextIds:\n (traceQuery || threadQuery) && declares(OBSERVABILITY_TRACE_QUERY_CONTEXT_IDS_STORAGE_FEATURE),\n traceQueryTimeToFirstChunk:\n (traceQuery || threadQuery || spanQuery) &&\n declares(OBSERVABILITY_TRACE_QUERY_TIME_TO_FIRST_CHUNK_STORAGE_FEATURE),\n traceQueryRootSpanFields:\n (traceQuery || threadQuery) && declares(OBSERVABILITY_TRACE_QUERY_ROOT_SPAN_FIELDS_STORAGE_FEATURE),\n traceQueryRootEntityId:\n (traceQuery || threadQuery) && declares(OBSERVABILITY_TRACE_QUERY_ROOT_ENTITY_ID_STORAGE_FEATURE),\n traceQueryTimeToFirstChunkSort:\n (traceQuery || spanQuery) && declares(OBSERVABILITY_TRACE_QUERY_TIME_TO_FIRST_CHUNK_SORT_STORAGE_FEATURE),\n traceQueryDiscovery:\n newApiCore && supportsTraceQueryDiscoveryCore() && declares(OBSERVABILITY_TRACE_QUERY_DISCOVERY_STORAGE_FEATURE),\n traceQueryTenantScope:\n (traceQuery || threadQuery) &&\n coreFeatures.has(OBSERVABILITY_TRACE_QUERY_TENANT_SCOPE_CORE_FEATURE) &&\n declares(OBSERVABILITY_TRACE_QUERY_TENANT_SCOPE_STORAGE_FEATURE),\n traceAggregate:\n newApiCore && supportsTraceAggregateCore() && declares(OBSERVABILITY_TRACE_AGGREGATE_STORAGE_FEATURE),\n threadQuery,\n threadQueryRows:\n threadQuery && typeof coreStorage.planThreadRowsQuery === 'function' && declares('thread-query-rows'),\n spanQuery,\n spanQueryContextFields: spanQuery && declares('span-query-context-fields'),\n spanAggregate: newApiCore && supportsSpanAggregateCore() && declares(OBSERVABILITY_SPAN_AGGREGATE_STORAGE_FEATURE),\n feedback: newApiCore && declares(OBSERVABILITY_FEEDBACK_STORAGE_FEATURE),\n };\n}\n\n/**\n * Matches the `OBSERVABILITY_STORAGE_*_NOT_IMPLEMENTED` MastraError the base\n * observability store throws for every optional method a store doesn't\n * implement. Checked by id (not `instanceof`) so it holds across duplicated\n * `@mastra/core` installs.\n */\nfunction isObservabilityStorageNotImplementedError(error: unknown): boolean {\n const id = error && typeof error === 'object' && 'id' in error ? error.id : undefined;\n return typeof id === 'string' && id.startsWith('OBSERVABILITY_STORAGE_') && id.endsWith('_NOT_IMPLEMENTED');\n}\n\n/**\n * Discovery is optional for observability stores. When the configured store\n * doesn't implement a discovery method, answer with an empty result instead of\n * a 500 so filter lookups degrade quietly on stores without discovery support.\n * Clients should check `observabilityStorageCapabilities.discovery` from\n * `GET /system/packages` before calling these routes.\n */\nexport async function withDiscoveryFallback<T>(run: () => Promise<T>, empty: T): Promise<T> {\n try {\n return await run();\n } catch (error) {\n if (isObservabilityStorageNotImplementedError(error)) return empty;\n throw error;\n }\n}\n\nexport function assertObservabilityDeltaSupported(\n observabilityStore: ObservabilityStorage,\n endpoint: ObservabilityListEndpoint,\n) {\n if (!coreFeatures.has(OBSERVABILITY_DELTA_POLLING_FEATURE)) {\n throw new HTTPException(501, {\n message: `${OBSERVABILITY_DELTA_POLLING_UPGRADE_MESSAGE} (endpoint: ${endpoint})`,\n });\n }\n\n if (getFeatures(observabilityStore)?.includes(OBSERVABILITY_DELTA_POLLING_STORAGE_FEATURE)) {\n return;\n }\n\n throw new HTTPException(501, {\n message: `Delta polling is not supported by the configured observability store for ${endpoint}`,\n });\n}\n\nexport interface RouteDetails {\n method: ServerRoute['method'];\n path: `/${string}`;\n summary: string;\n description: string;\n requiresPermission?: ServerRoute['requiresPermission'];\n}\n\nexport const NEW_ROUTE_DEFS = {\n QUERY_TRACES: {\n method: 'POST',\n path: '/observability/traces/query',\n summary: 'Query traces',\n description:\n 'Returns completed logical traces or distinct thread groups matching an advanced trace query. Thread grouping remains supported but is deprecated; use queryTraceThreads instead.',\n requiresPermission: 'observability:read',\n },\n\n AGGREGATE_TRACES: {\n method: 'POST',\n path: '/observability/traces/aggregate',\n summary: 'Aggregate traces',\n description:\n 'Returns grouped and optionally time-bucketed measures (counts, durations, error rates) over completed logical traces matching an advanced trace predicate',\n requiresPermission: 'observability:read',\n },\n\n QUERY_THREADS: {\n method: 'POST',\n path: '/observability/threads/query',\n summary: 'Query threads',\n description:\n 'Returns full-history thread rows with activity timestamps, first/last traces, previews and context fields',\n requiresPermission: 'observability:read',\n },\n\n QUERY_SPANS: {\n method: 'POST',\n path: '/observability/spans/query',\n summary: 'Query spans',\n description: 'Returns completed spans matching a span predicate, one row per span, with cursor pagination',\n requiresPermission: 'observability:read',\n },\n\n AGGREGATE_SPANS: {\n method: 'POST',\n path: '/observability/spans/aggregate',\n summary: 'Aggregate spans',\n description:\n 'Returns grouped and optionally time-bucketed measures (counts, durations, error rates, tokens, cost) over completed spans matching a span predicate',\n requiresPermission: 'observability:read',\n },\n\n GET_TRACE_QUERY_FIELDS: {\n method: 'POST',\n path: '/observability/traces/query/fields',\n summary: 'Discover trace query fields',\n description: 'Returns canonical query fields and observed top-level string metadata fields',\n requiresPermission: 'observability:read',\n },\n\n GET_TRACE_QUERY_VALUES: {\n method: 'POST',\n path: '/observability/traces/query/values',\n summary: 'Discover trace query values',\n description: 'Returns bounded string value suggestions and occurrence counts for one eligible query field',\n requiresPermission: 'observability:read',\n },\n\n LIST_METRICS: {\n method: 'GET',\n path: '/observability/metrics',\n summary: 'List metrics',\n description: 'Returns a paginated list of metrics with optional filtering and sorting',\n },\n\n LIST_LOGS: {\n method: 'GET',\n path: '/observability/logs',\n summary: 'List logs',\n description: 'Returns a paginated list of logs with optional filtering and sorting',\n },\n\n LIST_SCORES: {\n method: 'GET',\n path: '/observability/scores',\n summary: 'List scores',\n description: 'Returns a paginated list of scores with optional filtering and sorting',\n },\n\n CREATE_SCORE: {\n method: 'POST',\n path: '/observability/scores',\n summary: 'Create a score',\n description: 'Creates a single score record in the observability store',\n },\n\n DELETE_SCORES: {\n method: 'DELETE',\n path: '/observability/scores',\n summary: 'Delete scores',\n description: 'Deletes score records by scoreId, optionally scoped to a tenant',\n requiresPermission: 'observability:delete',\n },\n\n GET_SCORE: {\n method: 'GET',\n path: '/observability/scores/:scoreId',\n summary: 'Get score',\n description: 'Returns a single score by scoreId',\n },\n\n GET_SCORE_AGGREGATE: {\n method: 'POST',\n path: '/observability/scores/aggregate',\n summary: 'Get score aggregate',\n description: 'Returns an aggregated score value with optional period-over-period comparison',\n requiresPermission: 'observability:read',\n },\n\n GET_SCORE_BREAKDOWN: {\n method: 'POST',\n path: '/observability/scores/breakdown',\n summary: 'Get score breakdown',\n description: 'Returns score values grouped by specified dimensions',\n requiresPermission: 'observability:read',\n },\n\n GET_SCORE_TIME_SERIES: {\n method: 'POST',\n path: '/observability/scores/timeseries',\n summary: 'Get score time series',\n description: 'Returns score values bucketed by time interval with optional grouping',\n requiresPermission: 'observability:read',\n },\n\n GET_SCORE_PERCENTILES: {\n method: 'POST',\n path: '/observability/scores/percentiles',\n summary: 'Get score percentiles',\n description: 'Returns percentile values for a score bucketed by time interval',\n requiresPermission: 'observability:read',\n },\n\n LIST_FEEDBACK: {\n method: 'GET',\n path: '/observability/feedback',\n summary: 'List feedback',\n description: 'Returns a paginated list of feedback with optional filtering and sorting',\n },\n\n CREATE_FEEDBACK: {\n method: 'POST',\n path: '/observability/feedback',\n summary: 'Create feedback',\n description: 'Creates a single feedback record in the observability store',\n },\n\n DELETE_FEEDBACK: {\n method: 'DELETE',\n path: '/observability/feedback',\n summary: 'Delete feedback',\n description: 'Deletes feedback records by feedbackId, optionally scoped to a tenant',\n requiresPermission: 'observability:delete',\n },\n\n UPDATE_FEEDBACK_REVIEW_STATUS: {\n method: 'PATCH',\n path: '/observability/feedback/:feedbackId/review-status',\n summary: 'Update feedback review status',\n description: \"Updates a feedback record's review workflow status\",\n requiresPermission: 'observability:write',\n },\n\n GET_FEEDBACK_AGGREGATE: {\n method: 'POST',\n path: '/observability/feedback/aggregate',\n summary: 'Get feedback aggregate',\n description: 'Returns an aggregated numeric feedback value with optional period-over-period comparison',\n requiresPermission: 'observability:read',\n },\n\n GET_FEEDBACK_BREAKDOWN: {\n method: 'POST',\n path: '/observability/feedback/breakdown',\n summary: 'Get feedback breakdown',\n description: 'Returns numeric feedback values grouped by specified dimensions',\n requiresPermission: 'observability:read',\n },\n\n GET_FEEDBACK_TIME_SERIES: {\n method: 'POST',\n path: '/observability/feedback/timeseries',\n summary: 'Get feedback time series',\n description: 'Returns numeric feedback values bucketed by time interval with optional grouping',\n requiresPermission: 'observability:read',\n },\n\n GET_FEEDBACK_PERCENTILES: {\n method: 'POST',\n path: '/observability/feedback/percentiles',\n summary: 'Get feedback percentiles',\n description: 'Returns percentile values for numeric feedback bucketed by time interval',\n requiresPermission: 'observability:read',\n },\n\n GET_METRIC_AGGREGATE: {\n method: 'POST',\n path: '/observability/metrics/aggregate',\n summary: 'Get metric aggregate',\n description: 'Returns an aggregated metric value with optional period-over-period comparison',\n requiresPermission: 'observability:read',\n },\n\n GET_METRIC_BREAKDOWN: {\n method: 'POST',\n path: '/observability/metrics/breakdown',\n summary: 'Get metric breakdown',\n description: 'Returns metric values grouped by specified dimensions',\n requiresPermission: 'observability:read',\n },\n\n GET_METRIC_TIME_SERIES: {\n method: 'POST',\n path: '/observability/metrics/timeseries',\n summary: 'Get metric time series',\n description: 'Returns metric values bucketed by time interval with optional grouping',\n requiresPermission: 'observability:read',\n },\n\n GET_METRIC_PERCENTILES: {\n method: 'POST',\n path: '/observability/metrics/percentiles',\n summary: 'Get metric percentiles',\n description: 'Returns percentile values for a metric bucketed by time interval',\n requiresPermission: 'observability:read',\n },\n\n GET_METRIC_NAMES: {\n method: 'GET',\n path: '/observability/discovery/metric-names',\n summary: 'Get metric names',\n description: 'Returns distinct metric names with optional prefix filtering',\n },\n\n GET_METRIC_LABEL_KEYS: {\n method: 'GET',\n path: '/observability/discovery/metric-label-keys',\n summary: 'Get metric label keys',\n description: 'Returns distinct label keys for a given metric',\n },\n\n GET_METRIC_LABEL_VALUES: {\n method: 'GET',\n path: '/observability/discovery/metric-label-values',\n summary: 'Get label values',\n description: 'Returns distinct values for a given metric label key',\n },\n\n GET_ENTITY_TYPES: {\n method: 'GET',\n path: '/observability/discovery/entity-types',\n summary: 'Get entity types',\n description: 'Returns distinct entity types from observability data',\n },\n\n GET_ENTITY_NAMES: {\n method: 'GET',\n path: '/observability/discovery/entity-names',\n summary: 'Get entity names',\n description: 'Returns distinct entity names with optional type filtering',\n },\n\n GET_SERVICE_NAMES: {\n method: 'GET',\n path: '/observability/discovery/service-names',\n summary: 'Get service names',\n description: 'Returns distinct service names from observability data',\n },\n\n GET_ENVIRONMENTS: {\n method: 'GET',\n path: '/observability/discovery/environments',\n summary: 'Get environments',\n description: 'Returns distinct environments from observability data',\n },\n\n GET_TAGS: {\n method: 'GET',\n path: '/observability/discovery/tags',\n summary: 'Get tags',\n description: 'Returns distinct tags with optional entity type filtering',\n },\n\n GET_CAPABILITIES: {\n method: 'GET',\n path: '/observability/capabilities',\n summary: 'Get observability capabilities',\n description:\n 'Returns which optional observability APIs the configured observability storage supports. Every flag is false when no observability storage is configured.',\n },\n} as const satisfies Record<string, RouteDetails>;\n\nexport type NewRoutesKey = keyof typeof NEW_ROUTE_DEFS;\nexport type NewRoutesDefinitions = (typeof NEW_ROUTE_DEFS)[NewRoutesKey];\n\nexport function createObservabilityListQuerySchema<\n TFilter extends z.ZodObject<z.ZodRawShape>,\n TOrderBy extends z.ZodObject<z.ZodRawShape>,\n>(filterSchema: TFilter, orderBySchema: TOrderBy) {\n const unwrapDefault = (schema: unknown) => {\n const zodSchema = schema as z.ZodTypeAny;\n return zodSchema instanceof z.ZodDefault ? zodSchema.unwrap() : zodSchema;\n };\n const paginationShape = paginationArgsSchema.shape as unknown as Record<string, z.ZodTypeAny>;\n const orderByShape = orderBySchema.shape as unknown as Record<string, z.ZodTypeAny>;\n\n const pageSchema = unwrapDefault(paginationShape.page);\n const perPageSchema = unwrapDefault(paginationShape.perPage);\n const fieldSchema = orderByShape.field ? unwrapDefault(orderByShape.field) : z.never().optional();\n const directionSchema = orderByShape.direction ? unwrapDefault(orderByShape.direction) : z.never().optional();\n\n return wrapSchemaForQueryParams(\n z\n .object({\n ...filterSchema.shape,\n page: pageSchema,\n perPage: perPageSchema,\n field: fieldSchema,\n direction: directionSchema,\n mode: listModeSchema.optional(),\n after: deltaCursorSchema.optional(),\n limit: deltaLimitSchema,\n })\n .partial(),\n ).superRefine((value, ctx) => {\n const isDelta = value.mode === 'delta';\n const hasPagination = value.page !== undefined || value.perPage !== undefined;\n const hasOrderBy = value.field !== undefined || value.direction !== undefined;\n const hasAfter = value.after !== undefined;\n const hasLimit = value.limit !== undefined;\n\n if (isDelta) {\n if (hasPagination) {\n if (value.page !== undefined) {\n ctx.addIssue({\n code: z.ZodIssueCode.custom,\n path: ['page'],\n message: '`page` is not allowed when `mode=delta`',\n });\n }\n if (value.perPage !== undefined) {\n ctx.addIssue({\n code: z.ZodIssueCode.custom,\n path: ['perPage'],\n message: '`perPage` is not allowed when `mode=delta`',\n });\n }\n }\n if (hasOrderBy) {\n if (value.field !== undefined) {\n ctx.addIssue({\n code: z.ZodIssueCode.custom,\n path: ['field'],\n message: '`field` is not allowed when `mode=delta`',\n });\n }\n if (value.direction !== undefined) {\n ctx.addIssue({\n code: z.ZodIssueCode.custom,\n path: ['direction'],\n message: '`direction` is not allowed when `mode=delta`',\n });\n }\n }\n return;\n }\n\n if (hasAfter) {\n ctx.addIssue({\n code: z.ZodIssueCode.custom,\n path: ['after'],\n message: '`after` is only allowed when `mode=delta`',\n });\n }\n if (hasLimit) {\n ctx.addIssue({\n code: z.ZodIssueCode.custom,\n path: ['limit'],\n message: '`limit` is only allowed when `mode=delta`',\n });\n }\n });\n}\n"],"mappings":";;;;;;;AAuBA,MAAa,sCAAsC;AACnD,MAAa,8CACX;AACF,MAAM,4CAA4C;AAClD,MAAM,gDAAgD;AACtD,MAAM,2CAA2C;AACjD,MAAM,+CAA+C;AACrD,MAAM,4CAA4B,IAAI,IAAI;CACxC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;C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AEL;GACA,IAAI,YAAY;IACd,IAAI,MAAM,UAAU,KAAA,GAClB,IAAI,SAAS;KACX,MAAM,EAAE,aAAa;KACrB,MAAM,CAAC,OAAO;KACd,SAAS;IACX,CAAC;IAEH,IAAI,MAAM,cAAc,KAAA,GACtB,IAAI,SAAS;KACX,MAAM,EAAE,aAAa;KACrB,MAAM,CAAC,WAAW;KAClB,SAAS;IACX,CAAC;GAEL;GACA;EACF;EAEA,IAAI,UACF,IAAI,SAAS;GACX,MAAM,EAAE,aAAa;GACrB,MAAM,CAAC,OAAO;GACd,SAAS;EACX,CAAC;EAEH,IAAI,UACF,IAAI,SAAS;GACX,MAAM,EAAE,aAAa;GACrB,MAAM,CAAC,OAAO;GACd,SAAS;EACX,CAAC;CAEL,CAAC;AACH"}
1
+ {"version":3,"file":"observability-shared.js","names":["candidate"],"sources":["../../../src/server/handlers/observability-shared.ts"],"sourcesContent":["import type { Mastra } from '@mastra/core';\nimport { coreFeatures } from '@mastra/core/features';\nimport type {\n MastraCompositeStore,\n ObservabilityStorage,\n ScoresStorage,\n TraceQueryIssue,\n TrustedTraceQueryScalarPredicate,\n TrustedThreadPredicate,\n TrustedTraceQueryPredicate,\n} from '@mastra/core/storage';\nimport * as coreStorage from '@mastra/core/storage';\nimport { z } from 'zod/v4';\nimport { HTTPException } from '../http-exception';\nimport type { ServerRoute } from '../server-adapter/routes';\nimport { wrapSchemaForQueryParams } from '../server-adapter/routes/route-builder';\nimport {\n deltaCursorSchema,\n deltaLimitSchema,\n listModeSchema,\n paginationArgsSchema,\n} from './observability-list-query-schemas';\n\nexport const OBSERVABILITY_DELTA_POLLING_FEATURE = 'observability-delta-polling';\nexport const OBSERVABILITY_DELTA_POLLING_UPGRADE_MESSAGE =\n 'Delta polling requires a newer @mastra/core with observability delta polling support. Please upgrade.';\nconst OBSERVABILITY_TRACE_QUERY_STORAGE_FEATURE = 'trace-query';\nconst OBSERVABILITY_TRACE_AGGREGATE_STORAGE_FEATURE = 'trace-aggregate';\nconst OBSERVABILITY_SPAN_QUERY_STORAGE_FEATURE = 'span-query';\nconst OBSERVABILITY_SPAN_AGGREGATE_STORAGE_FEATURE = 'span-aggregate';\nconst SPAN_QUERY_CONTEXT_FIELDS = new Set([\n 'traceId',\n 'spanId',\n 'parentSpanId',\n 'threadId',\n 'resourceId',\n 'requestId',\n 'serviceName',\n 'experimentId',\n 'environment',\n 'executionSource',\n 'parentEntityType',\n 'parentEntityId',\n 'parentEntityName',\n 'rootEntityType',\n 'rootEntityId',\n 'rootEntityName',\n]);\nconst OBSERVABILITY_TRACE_QUERY_ROOT_DURATION_STORAGE_FEATURE = 'trace-query-root-duration';\nconst OBSERVABILITY_TRACE_QUERY_CONTEXT_IDS_STORAGE_FEATURE = 'trace-query-context-ids';\nconst TRACE_QUERY_CONTEXT_ID_FIELDS = new Set(['runId', 'sessionId', 'userId', 'organizationId']);\nconst OBSERVABILITY_TRACE_QUERY_TIME_TO_FIRST_CHUNK_STORAGE_FEATURE = 'trace-query-time-to-first-chunk';\nconst TRACE_QUERY_TIME_TO_FIRST_CHUNK_FIELDS = new Set(['timeToFirstChunkMs']);\nconst OBSERVABILITY_TRACE_QUERY_TIME_TO_FIRST_TOKEN_STORAGE_FEATURE = 'trace-query-time-to-first-token';\nconst TRACE_QUERY_TIME_TO_FIRST_TOKEN_FIELDS = new Set(['timeToFirstTokenMs']);\nconst OBSERVABILITY_TRACE_QUERY_ROOT_SPAN_FIELDS_STORAGE_FEATURE = 'trace-query-root-span-fields';\nconst OBSERVABILITY_TRACE_QUERY_ROOT_ENTITY_ID_STORAGE_FEATURE = 'trace-query-root-entity-id';\n// Trace-scope fields read from the root span, keyed by the storage feature that added their SQL.\nconst TRACE_QUERY_ROOT_SPAN_FIELD_FEATURES = new Map([\n ['name', OBSERVABILITY_TRACE_QUERY_ROOT_SPAN_FIELDS_STORAGE_FEATURE],\n ['spanType', OBSERVABILITY_TRACE_QUERY_ROOT_SPAN_FIELDS_STORAGE_FEATURE],\n ['entityId', OBSERVABILITY_TRACE_QUERY_ROOT_ENTITY_ID_STORAGE_FEATURE],\n]);\nconst OBSERVABILITY_TRACE_QUERY_TIME_TO_FIRST_CHUNK_SORT_STORAGE_FEATURE = 'trace-query-time-to-first-chunk-sort';\nconst OBSERVABILITY_TRACE_QUERY_TIME_TO_FIRST_TOKEN_SORT_STORAGE_FEATURE = 'trace-query-time-to-first-token-sort';\nconst OBSERVABILITY_TRACE_QUERY_DISCOVERY_STORAGE_FEATURE = 'trace-query-discovery';\nconst OBSERVABILITY_THREAD_QUERY_STORAGE_FEATURE = 'thread-query';\nconst OBSERVABILITY_TRACE_QUERY_TENANT_SCOPE_STORAGE_FEATURE = 'trace-query-tenant-scope';\nconst OBSERVABILITY_FEEDBACK_STORAGE_FEATURE = 'feedback';\nexport const OBSERVABILITY_TRACE_QUERY_TENANT_SCOPE_CORE_FEATURE = 'observability-trace-query-tenant-scope';\nexport const OBSERVABILITY_TRACE_QUERY_TENANT_SCOPE_UPGRADE_MESSAGE =\n 'Trusted tenant scope requires a newer @mastra/core with trace-query tenant scope support. Please upgrade.';\n\nexport function supportsTraceQueryDiscoveryCore() {\n return (\n coreStorage.getTraceQueryFieldsArgsSchema !== undefined &&\n coreStorage.getTraceQueryFieldsResponseSchema !== undefined &&\n coreStorage.getTraceQueryValuesArgsSchema !== undefined &&\n coreStorage.getTraceQueryValuesResponseSchema !== undefined &&\n typeof coreStorage.planTraceQueryObservedFields === 'function' &&\n typeof coreStorage.planTraceQueryValues === 'function' &&\n typeof coreStorage.getTraceQueryCanonicalFieldDescriptors === 'function' &&\n typeof coreStorage.TraceQueryResourceLimitError === 'function'\n );\n}\n\nexport function supportsTraceAggregateCore() {\n return (\n coreStorage.traceAggregateRequestSchema !== undefined &&\n coreStorage.traceAggregateResponseSchema !== undefined &&\n typeof coreStorage.planTraceAggregate === 'function'\n );\n}\n\nexport function supportsSpanAggregateCore() {\n return (\n coreStorage.spanAggregateRequestSchema !== undefined &&\n coreStorage.spanAggregateResponseSchema !== undefined &&\n typeof coreStorage.planSpanAggregate === 'function'\n );\n}\n\nexport function supportsSpanQueryCore() {\n return (\n coreStorage.spanQueryRequestSchema !== undefined &&\n coreStorage.spanQueryResponseSchema !== undefined &&\n typeof coreStorage.planSpanQuery === 'function'\n );\n}\n\nexport const OBSERVABILITY_LIST_ENDPOINTS = {\n traces: 'traces',\n branches: 'branches',\n logs: 'logs',\n metrics: 'metrics',\n scores: 'scores',\n feedback: 'feedback',\n} as const;\n\nexport type ObservabilityListEndpoint =\n (typeof OBSERVABILITY_LIST_ENDPOINTS)[keyof typeof OBSERVABILITY_LIST_ENDPOINTS];\nconst OBSERVABILITY_DELTA_POLLING_STORAGE_FEATURE = 'delta-polling';\n\nfunction getFeatures(observabilityStore: ObservabilityStorage): readonly string[] | undefined {\n const candidate = observabilityStore as ObservabilityStorage & {\n getFeatures?: () => readonly string[] | undefined;\n };\n return candidate.getFeatures?.();\n}\n\n/** Retrieves MastraCompositeStore or throws 500 if unavailable. */\nexport function getStorage(mastra: Mastra): MastraCompositeStore {\n const storage = mastra.getStorage();\n if (!storage) {\n throw new HTTPException(500, { message: 'Storage is not available' });\n }\n return storage;\n}\n\n/** Retrieves the observability storage domain or throws 501 if unavailable. */\nexport async function getObservabilityStore(mastra: Mastra): Promise<ObservabilityStorage> {\n const storage = getStorage(mastra);\n const observability = await storage.getStore('observability');\n if (!observability) {\n // 501, not 500: a missing or explicitly disabled observability domain\n // (e.g. `domains: { observability: false }`) is a capability gap, not a\n // server failure — matching the other 501s in this file.\n throw new HTTPException(501, { message: 'Observability storage domain is not available' });\n }\n return observability;\n}\n\n/** Retrieves the scores storage domain or throws 501 if unavailable. */\nexport async function getScoresStore(mastra: Mastra): Promise<ScoresStorage> {\n const storage = getStorage(mastra);\n const scores = await storage.getStore('scores');\n if (!scores) {\n throw new HTTPException(501, { message: 'Scores storage domain is not available' });\n }\n return scores;\n}\n\nexport function assertObservabilityTraceQuerySupported(observabilityStore: ObservabilityStorage) {\n if (getFeatures(observabilityStore)?.includes(OBSERVABILITY_TRACE_QUERY_STORAGE_FEATURE)) return;\n\n throw new HTTPException(501, {\n message: 'Advanced trace queries are not supported by the configured observability store',\n });\n}\n\nexport function supportsObservabilityTraceAggregate(observabilityStore: ObservabilityStorage) {\n return getFeatures(observabilityStore)?.includes(OBSERVABILITY_TRACE_AGGREGATE_STORAGE_FEATURE) === true;\n}\n\nexport function assertObservabilityTraceAggregateSupported(observabilityStore: ObservabilityStorage) {\n if (supportsObservabilityTraceAggregate(observabilityStore)) return;\n\n throw new HTTPException(501, {\n message: 'Trace aggregation is not supported by the configured observability store',\n });\n}\n\nexport function assertObservabilitySpanAggregateSupported(observabilityStore: ObservabilityStorage) {\n if (getFeatures(observabilityStore)?.includes(OBSERVABILITY_SPAN_AGGREGATE_STORAGE_FEATURE)) return;\n\n throw new HTTPException(501, {\n message: 'Span aggregation is not supported by the configured observability store',\n });\n}\n\nexport function assertObservabilitySpanQuerySupported(observabilityStore: ObservabilityStorage) {\n if (getFeatures(observabilityStore)?.includes(OBSERVABILITY_SPAN_QUERY_STORAGE_FEATURE)) return;\n\n throw new HTTPException(501, {\n message: 'Span queries are not supported by the configured observability store',\n });\n}\n\nexport function assertObservabilitySpanQueryFieldsSupported(\n observabilityStore: ObservabilityStorage,\n predicate: TrustedTraceQueryScalarPredicate | undefined,\n) {\n if (!predicate || getFeatures(observabilityStore)?.includes('span-query-context-fields')) return;\n if (predicate.type === 'boolean') {\n for (const arg of predicate.args) assertObservabilitySpanQueryFieldsSupported(observabilityStore, arg);\n } else if (predicate.type === 'not') {\n assertObservabilitySpanQueryFieldsSupported(observabilityStore, predicate.arg);\n } else if (SPAN_QUERY_CONTEXT_FIELDS.has(predicate.field)) {\n throw new coreStorage.TraceQueryValidationError([\n {\n code: 'field_not_allowed',\n path: ['where'],\n message: `Filtering by ${predicate.field} requires an updated storage adapter with span query context-field support.`,\n },\n ]);\n }\n}\n\nfunction usesRootDuration(predicate: TrustedTraceQueryPredicate | TrustedThreadPredicate | undefined): boolean {\n if (!predicate) return false;\n if (predicate.type === 'boolean') return predicate.args.some(usesRootDuration);\n if (predicate.type === 'not') return usesRootDuration(predicate.arg);\n if (predicate.type === 'relation') {\n return predicate.collection === 'traces' && usesRootDuration(predicate.predicate);\n }\n return predicate.field === 'durationMs';\n}\n\nexport function supportsObservabilityTraceQueryRootDuration(observabilityStore: ObservabilityStorage) {\n return getFeatures(observabilityStore)?.includes(OBSERVABILITY_TRACE_QUERY_ROOT_DURATION_STORAGE_FEATURE) === true;\n}\n\nexport function assertObservabilityTraceQueryRootDurationSupported(\n observabilityStore: ObservabilityStorage,\n predicate: TrustedTraceQueryPredicate | TrustedThreadPredicate | undefined,\n) {\n if (!usesRootDuration(predicate) || supportsObservabilityTraceQueryRootDuration(observabilityStore)) return;\n\n throw new HTTPException(501, {\n message: 'Root duration predicates are not supported by the configured observability store',\n });\n}\n\n/** Whether any scalar predicate, at any depth and inside any relation, names one of `fields`. */\nfunction usesField(\n predicate: TrustedTraceQueryPredicate | TrustedThreadPredicate | undefined,\n fields: ReadonlySet<string>,\n): boolean {\n if (!predicate) return false;\n if (predicate.type === 'boolean') return predicate.args.some(arg => usesField(arg, fields));\n if (predicate.type === 'not') return usesField(predicate.arg, fields);\n if (predicate.type === 'relation') return usesField(predicate.predicate, fields);\n return fields.has(predicate.field);\n}\n\nexport function supportsObservabilityTraceQueryContextIds(observabilityStore: ObservabilityStorage) {\n return getFeatures(observabilityStore)?.includes(OBSERVABILITY_TRACE_QUERY_CONTEXT_IDS_STORAGE_FEATURE) === true;\n}\n\nexport function isTraceQueryContextIdField(path: string): boolean {\n return TRACE_QUERY_CONTEXT_ID_FIELDS.has(path);\n}\n\nexport function assertObservabilityTraceQueryContextIdsSupported(\n observabilityStore: ObservabilityStorage,\n predicate: TrustedTraceQueryPredicate | TrustedThreadPredicate | undefined,\n) {\n if (\n !usesField(predicate, TRACE_QUERY_CONTEXT_ID_FIELDS) ||\n supportsObservabilityTraceQueryContextIds(observabilityStore)\n ) {\n return;\n }\n\n throw new HTTPException(501, {\n message: 'Context identifier predicates are not supported by the configured observability store',\n });\n}\n\nexport function supportsObservabilityTraceQueryTimeToFirstChunk(observabilityStore: ObservabilityStorage) {\n return (\n getFeatures(observabilityStore)?.includes(OBSERVABILITY_TRACE_QUERY_TIME_TO_FIRST_CHUNK_STORAGE_FEATURE) === true\n );\n}\n\n/** Covers trace, thread and span query predicates, including `spans` and `traces` relations. */\nexport function assertObservabilityTraceQueryTimeToFirstChunkSupported(\n observabilityStore: ObservabilityStorage,\n predicate: TrustedTraceQueryPredicate | TrustedThreadPredicate | undefined,\n) {\n if (\n !usesField(predicate, TRACE_QUERY_TIME_TO_FIRST_CHUNK_FIELDS) ||\n supportsObservabilityTraceQueryTimeToFirstChunk(observabilityStore)\n ) {\n return;\n }\n\n throw new HTTPException(501, {\n message: 'Time to first chunk predicates are not supported by the configured observability store',\n });\n}\n\nexport function supportsObservabilityTraceQueryTimeToFirstToken(observabilityStore: ObservabilityStorage) {\n return (\n getFeatures(observabilityStore)?.includes(OBSERVABILITY_TRACE_QUERY_TIME_TO_FIRST_TOKEN_STORAGE_FEATURE) === true\n );\n}\n\n/** Covers trace, thread and span query predicates, including `spans` and `traces` relations. */\nexport function assertObservabilityTraceQueryTimeToFirstTokenSupported(\n observabilityStore: ObservabilityStorage,\n predicate: TrustedTraceQueryPredicate | TrustedThreadPredicate | undefined,\n) {\n if (\n !usesField(predicate, TRACE_QUERY_TIME_TO_FIRST_TOKEN_FIELDS) ||\n supportsObservabilityTraceQueryTimeToFirstToken(observabilityStore)\n ) {\n return;\n }\n\n throw new HTTPException(501, {\n message: 'Time to first token predicates are not supported by the configured observability store',\n });\n}\n\nfunction rootSpanFieldIssues(\n observabilityStore: ObservabilityStorage,\n predicate: TrustedTraceQueryPredicate | TrustedThreadPredicate | undefined,\n): TraceQueryIssue[] {\n if (!predicate) return [];\n if (predicate.type === 'boolean') return predicate.args.flatMap(arg => rootSpanFieldIssues(observabilityStore, arg));\n if (predicate.type === 'not') return rootSpanFieldIssues(observabilityStore, predicate.arg);\n // Only trace-scope root span fields read the root; inside `spans.some` they are long-supported span fields.\n if (predicate.type === 'relation') {\n return predicate.collection === 'traces' ? rootSpanFieldIssues(observabilityStore, predicate.predicate) : [];\n }\n return supportsObservabilityTraceQueryRootSpanField(observabilityStore, predicate.field)\n ? []\n : [rootSpanFieldIssue(['where'], predicate.field)];\n}\n\nfunction rootSpanFieldIssue(path: Array<string | number>, field: string): TraceQueryIssue {\n return {\n code: 'field_not_allowed',\n path,\n message: `Root span ${field} requires an updated storage adapter with trace-query root span field support.`,\n };\n}\n\n/**\n * Whether the store can serve `path` at trace scope. Fields that don't read the root span are\n * always supported here; other gates cover them.\n */\nexport function supportsObservabilityTraceQueryRootSpanField(observabilityStore: ObservabilityStorage, path: string) {\n const feature = TRACE_QUERY_ROOT_SPAN_FIELD_FEATURES.get(path);\n return feature === undefined || getFeatures(observabilityStore)?.includes(feature) === true;\n}\n\n/**\n * Stores that predate a trace-scope root span field have no SQL for it and would fail with a\n * 500, so requests that use it are rejected as invalid instead.\n */\nexport function assertObservabilityTraceQueryRootSpanFieldsSupported(\n observabilityStore: ObservabilityStorage,\n plan: {\n where?: TrustedTraceQueryPredicate | TrustedThreadPredicate;\n dimensions?: readonly string[];\n measures?: ReadonlyArray<{ type: string; field?: string }>;\n },\n) {\n const supported = (field: string) => supportsObservabilityTraceQueryRootSpanField(observabilityStore, field);\n const issues = [\n ...rootSpanFieldIssues(observabilityStore, plan.where),\n ...(plan.dimensions ?? []).flatMap((dimension, index) =>\n supported(dimension) ? [] : [rootSpanFieldIssue(['groupBy', index], dimension)],\n ),\n ...(plan.measures ?? []).flatMap((measure, index) =>\n measure.type === 'countDistinct' && measure.field !== undefined && !supported(measure.field)\n ? [rootSpanFieldIssue(['measures', index], measure.field)]\n : [],\n ),\n ];\n if (issues.length > 0) throw new coreStorage.TraceQueryValidationError(issues);\n}\n\nexport function assertObservabilityTraceQueryRootSpanValuesSupported(\n observabilityStore: ObservabilityStorage,\n plan: { predicateScope: string; path: string },\n) {\n if (plan.predicateScope !== 'trace') return;\n if (supportsObservabilityTraceQueryRootSpanField(observabilityStore, plan.path)) return;\n throw new coreStorage.TraceQueryValidationError([rootSpanFieldIssue(['path'], plan.path)]);\n}\n\nexport function supportsObservabilityTraceQueryTimeToFirstChunkSort(observabilityStore: ObservabilityStorage) {\n return (\n getFeatures(observabilityStore)?.includes(OBSERVABILITY_TRACE_QUERY_TIME_TO_FIRST_CHUNK_SORT_STORAGE_FEATURE) ===\n true\n );\n}\n\n/** Covers the sort of trace and span queries. */\nexport function assertObservabilityTraceQueryTimeToFirstChunkSortSupported(\n observabilityStore: ObservabilityStorage,\n orderBy: { field: string },\n) {\n if (\n !TRACE_QUERY_TIME_TO_FIRST_CHUNK_FIELDS.has(orderBy.field) ||\n supportsObservabilityTraceQueryTimeToFirstChunkSort(observabilityStore)\n ) {\n return;\n }\n\n throw new HTTPException(501, {\n message: 'Sorting by time to first chunk is not supported by the configured observability store',\n });\n}\n\nexport function supportsObservabilityTraceQueryTimeToFirstTokenSort(observabilityStore: ObservabilityStorage) {\n return (\n getFeatures(observabilityStore)?.includes(OBSERVABILITY_TRACE_QUERY_TIME_TO_FIRST_TOKEN_SORT_STORAGE_FEATURE) ===\n true\n );\n}\n\n/** Covers the sort of trace and span queries. */\nexport function assertObservabilityTraceQueryTimeToFirstTokenSortSupported(\n observabilityStore: ObservabilityStorage,\n orderBy: { field: string },\n) {\n if (\n !TRACE_QUERY_TIME_TO_FIRST_TOKEN_FIELDS.has(orderBy.field) ||\n supportsObservabilityTraceQueryTimeToFirstTokenSort(observabilityStore)\n ) {\n return;\n }\n\n throw new HTTPException(501, {\n message: 'Sorting by time to first token is not supported by the configured observability store',\n });\n}\n\nexport function assertObservabilityTraceQueryDiscoverySupported(observabilityStore: ObservabilityStorage) {\n if (getFeatures(observabilityStore)?.includes(OBSERVABILITY_TRACE_QUERY_DISCOVERY_STORAGE_FEATURE)) return;\n\n throw new HTTPException(501, {\n message: 'Trace query discovery is not supported by the configured observability store',\n });\n}\n\n/**\n * A scoped request must never run unscoped: a store that predates tenant scope would\n * silently ignore `plan.scope` and return every tenant's rows, so it is rejected instead.\n * Unscoped requests are unaffected.\n */\nexport function assertObservabilityTraceQueryTenantScopeSupported(\n observabilityStore: ObservabilityStorage,\n scope: coreStorage.TraceQueryTenantScope | undefined,\n) {\n if (scope === undefined) return;\n if (getFeatures(observabilityStore)?.includes(OBSERVABILITY_TRACE_QUERY_TENANT_SCOPE_STORAGE_FEATURE)) return;\n\n throw new HTTPException(501, {\n message: 'The configured observability store cannot enforce the trusted tenant scope',\n });\n}\n\nexport function assertObservabilityThreadQuerySupported(observabilityStore: ObservabilityStorage) {\n if (getFeatures(observabilityStore)?.includes(OBSERVABILITY_THREAD_QUERY_STORAGE_FEATURE)) return;\n\n throw new HTTPException(501, {\n message: 'Advanced thread queries are not supported by the configured observability store',\n });\n}\n\n/**\n * Returns true when the store's class chain overrides `method` below the class\n * that first declares it (the `ObservabilityStorage` base, whose default\n * throws `*_NOT_IMPLEMENTED`). Walks the store's own prototype chain instead of\n * comparing against this package's `ObservabilityStorage.prototype`, so it\n * works for stores built against older or duplicated `@mastra/core` installs\n * and for stores that predate {@link ObservabilityStorage.getFeatures}.\n */\nfunction implementsObservabilityStorageMethod(observabilityStore: object, method: string): boolean {\n if (Object.prototype.hasOwnProperty.call(observabilityStore, method)) return true;\n\n let resolvedOwner: object | undefined;\n let declaringBase: object | undefined;\n for (\n let proto: object | null = Object.getPrototypeOf(observabilityStore);\n proto && proto !== Object.prototype;\n proto = Object.getPrototypeOf(proto)\n ) {\n if (Object.prototype.hasOwnProperty.call(proto, method)) {\n resolvedOwner ??= proto;\n declaringBase = proto;\n }\n }\n return resolvedOwner !== undefined && resolvedOwner !== declaringBase;\n}\n\nexport type ObservabilityDiscoveryCapabilities = {\n entityTypes: boolean;\n entityNames: boolean;\n serviceNames: boolean;\n environments: boolean;\n tags: boolean;\n metrics: boolean;\n};\n\nexport type ObservabilityStorageCapabilities = {\n metrics: boolean;\n logs: boolean;\n discovery: ObservabilityDiscoveryCapabilities;\n deltaPolling: boolean;\n traceQuery: boolean;\n traceQueryRootDuration: boolean;\n traceQueryContextIds: boolean;\n traceQueryTimeToFirstChunk: boolean;\n traceQueryRootSpanFields: boolean;\n traceQueryRootEntityId: boolean;\n traceQueryTimeToFirstChunkSort: boolean;\n traceQueryTimeToFirstToken: boolean;\n traceQueryTimeToFirstTokenSort: boolean;\n traceQueryDiscovery: boolean;\n traceQueryTenantScope: boolean;\n traceAggregate: boolean;\n threadQuery: boolean;\n threadQueryRows: boolean;\n spanQuery: boolean;\n spanQueryContextFields: boolean;\n spanAggregate: boolean;\n /** Days of traces the store keeps. Omitted when the store does not report a limit. */\n traceRetentionDays?: number;\n feedback: boolean;\n};\n\nexport const NO_OBSERVABILITY_STORAGE_CAPABILITIES: ObservabilityStorageCapabilities = {\n metrics: false,\n logs: false,\n discovery: {\n entityTypes: false,\n entityNames: false,\n serviceNames: false,\n environments: false,\n tags: false,\n metrics: false,\n },\n deltaPolling: false,\n traceQuery: false,\n traceQueryRootDuration: false,\n traceQueryContextIds: false,\n traceQueryTimeToFirstChunk: false,\n traceQueryRootSpanFields: false,\n traceQueryRootEntityId: false,\n traceQueryTimeToFirstChunkSort: false,\n traceQueryTimeToFirstToken: false,\n traceQueryTimeToFirstTokenSort: false,\n traceQueryDiscovery: false,\n traceQueryTenantScope: false,\n traceAggregate: false,\n threadQuery: false,\n threadQueryRows: false,\n spanQuery: false,\n spanAggregate: false,\n spanQueryContextFields: false,\n feedback: false,\n};\n\n/**\n * Resolves which optional observability APIs the configured store can serve.\n *\n * Feature declarations (`getFeatures()`) are optional. When a store declares\n * a feature list, that list is final. Stores without `getFeatures()` predate\n * declarations: metrics, logs and filter discovery are detected by whether the\n * store implements the underlying method, so those packages report accurately\n * without being upgraded. Delta polling and the trace/thread query APIs depend\n * on runtime behavior a method check can't see, so they are only reported for\n * stores that declare them. Feedback is also declaration-only: Studio hides\n * the feedback UI behind this flag, and store versions that implement feedback\n * without declaring it simply don't advertise it until upgraded.\n */\nexport function getObservabilityStorageCapabilities(\n observabilityStore: ObservabilityStorage,\n): ObservabilityStorageCapabilities {\n const declaredFeatures = getFeatures(observabilityStore);\n const features = declaredFeatures ?? [];\n const newApiCore = coreFeatures.has('observability:v1.13.2');\n const declares = (feature: string) => features.includes(feature);\n // Undeclared stores must implement every method behind the feature.\n const supports = (feature: string, methods: readonly string[]) => {\n if (!newApiCore) return false;\n if (!declaredFeatures) {\n return methods.every(method => implementsObservabilityStorageMethod(observabilityStore, method));\n }\n return declares(feature);\n };\n // Stores released before the per-endpoint discovery features existed declare\n // `trace-query` and implement every discovery method, so treat it as implying discovery.\n const supportsDiscovery = (feature: string, methods: readonly string[]) =>\n supports(feature, methods) || (newApiCore && declares(OBSERVABILITY_TRACE_QUERY_STORAGE_FEATURE));\n const traceQuery =\n newApiCore &&\n typeof coreStorage.planTraceQuery === 'function' &&\n declares(OBSERVABILITY_TRACE_QUERY_STORAGE_FEATURE);\n const threadQuery =\n newApiCore &&\n typeof coreStorage.planThreadQuery === 'function' &&\n declares(OBSERVABILITY_THREAD_QUERY_STORAGE_FEATURE);\n const spanQuery = newApiCore && supportsSpanQueryCore() && declares(OBSERVABILITY_SPAN_QUERY_STORAGE_FEATURE);\n\n return {\n // `listMetrics` is left out: it backs a newer route that metric dashboards don't use,\n // and older stores that implement the OLAP methods predate it.\n metrics: supports('metrics', [\n 'getMetricAggregate',\n 'getMetricBreakdown',\n 'getMetricTimeSeries',\n 'getMetricPercentiles',\n ]),\n logs: supports('logs', ['listLogs']),\n discovery: {\n entityTypes: supportsDiscovery('entity-type-discovery', ['getEntityTypes']),\n entityNames: supportsDiscovery('entity-name-discovery', ['getEntityNames']),\n serviceNames: supportsDiscovery('service-name-discovery', ['getServiceNames']),\n environments: supportsDiscovery('environment-discovery', ['getEnvironments']),\n tags: supportsDiscovery('tag-discovery', ['getTags']),\n metrics: supportsDiscovery('metric-discovery', ['getMetricNames', 'getMetricLabelKeys', 'getMetricLabelValues']),\n },\n deltaPolling:\n coreFeatures.has(OBSERVABILITY_DELTA_POLLING_FEATURE) && declares(OBSERVABILITY_DELTA_POLLING_STORAGE_FEATURE),\n traceQuery,\n traceQueryRootDuration:\n (traceQuery || threadQuery) && declares(OBSERVABILITY_TRACE_QUERY_ROOT_DURATION_STORAGE_FEATURE),\n traceQueryContextIds:\n (traceQuery || threadQuery) && declares(OBSERVABILITY_TRACE_QUERY_CONTEXT_IDS_STORAGE_FEATURE),\n traceQueryTimeToFirstChunk:\n (traceQuery || threadQuery || spanQuery) &&\n declares(OBSERVABILITY_TRACE_QUERY_TIME_TO_FIRST_CHUNK_STORAGE_FEATURE),\n traceQueryRootSpanFields:\n (traceQuery || threadQuery) && declares(OBSERVABILITY_TRACE_QUERY_ROOT_SPAN_FIELDS_STORAGE_FEATURE),\n traceQueryRootEntityId:\n (traceQuery || threadQuery) && declares(OBSERVABILITY_TRACE_QUERY_ROOT_ENTITY_ID_STORAGE_FEATURE),\n traceQueryTimeToFirstChunkSort:\n (traceQuery || spanQuery) && declares(OBSERVABILITY_TRACE_QUERY_TIME_TO_FIRST_CHUNK_SORT_STORAGE_FEATURE),\n traceQueryTimeToFirstToken:\n (traceQuery || threadQuery || spanQuery) &&\n declares(OBSERVABILITY_TRACE_QUERY_TIME_TO_FIRST_TOKEN_STORAGE_FEATURE),\n traceQueryTimeToFirstTokenSort:\n (traceQuery || spanQuery) && declares(OBSERVABILITY_TRACE_QUERY_TIME_TO_FIRST_TOKEN_SORT_STORAGE_FEATURE),\n traceQueryDiscovery:\n newApiCore && supportsTraceQueryDiscoveryCore() && declares(OBSERVABILITY_TRACE_QUERY_DISCOVERY_STORAGE_FEATURE),\n traceQueryTenantScope:\n (traceQuery || threadQuery) &&\n coreFeatures.has(OBSERVABILITY_TRACE_QUERY_TENANT_SCOPE_CORE_FEATURE) &&\n declares(OBSERVABILITY_TRACE_QUERY_TENANT_SCOPE_STORAGE_FEATURE),\n traceAggregate:\n newApiCore && supportsTraceAggregateCore() && declares(OBSERVABILITY_TRACE_AGGREGATE_STORAGE_FEATURE),\n threadQuery,\n threadQueryRows:\n threadQuery && typeof coreStorage.planThreadRowsQuery === 'function' && declares('thread-query-rows'),\n spanQuery,\n spanQueryContextFields: spanQuery && declares('span-query-context-fields'),\n spanAggregate: newApiCore && supportsSpanAggregateCore() && declares(OBSERVABILITY_SPAN_AGGREGATE_STORAGE_FEATURE),\n feedback: newApiCore && declares(OBSERVABILITY_FEEDBACK_STORAGE_FEATURE),\n };\n}\n\n/**\n * Matches the `OBSERVABILITY_STORAGE_*_NOT_IMPLEMENTED` MastraError the base\n * observability store throws for every optional method a store doesn't\n * implement. Checked by id (not `instanceof`) so it holds across duplicated\n * `@mastra/core` installs.\n */\nfunction isObservabilityStorageNotImplementedError(error: unknown): boolean {\n const id = error && typeof error === 'object' && 'id' in error ? error.id : undefined;\n return typeof id === 'string' && id.startsWith('OBSERVABILITY_STORAGE_') && id.endsWith('_NOT_IMPLEMENTED');\n}\n\n/**\n * Discovery is optional for observability stores. When the configured store\n * doesn't implement a discovery method, answer with an empty result instead of\n * a 500 so filter lookups degrade quietly on stores without discovery support.\n * Clients should check `observabilityStorageCapabilities.discovery` from\n * `GET /system/packages` before calling these routes.\n */\nexport async function withDiscoveryFallback<T>(run: () => Promise<T>, empty: T): Promise<T> {\n try {\n return await run();\n } catch (error) {\n if (isObservabilityStorageNotImplementedError(error)) return empty;\n throw error;\n }\n}\n\nexport function assertObservabilityDeltaSupported(\n observabilityStore: ObservabilityStorage,\n endpoint: ObservabilityListEndpoint,\n) {\n if (!coreFeatures.has(OBSERVABILITY_DELTA_POLLING_FEATURE)) {\n throw new HTTPException(501, {\n message: `${OBSERVABILITY_DELTA_POLLING_UPGRADE_MESSAGE} (endpoint: ${endpoint})`,\n });\n }\n\n if (getFeatures(observabilityStore)?.includes(OBSERVABILITY_DELTA_POLLING_STORAGE_FEATURE)) {\n return;\n }\n\n throw new HTTPException(501, {\n message: `Delta polling is not supported by the configured observability store for ${endpoint}`,\n });\n}\n\nexport interface RouteDetails {\n method: ServerRoute['method'];\n path: `/${string}`;\n summary: string;\n description: string;\n requiresPermission?: ServerRoute['requiresPermission'];\n}\n\nexport const NEW_ROUTE_DEFS = {\n QUERY_TRACES: {\n method: 'POST',\n path: '/observability/traces/query',\n summary: 'Query traces',\n description:\n 'Returns completed logical traces or distinct thread groups matching an advanced trace query. Thread grouping remains supported but is deprecated; use queryTraceThreads instead.',\n requiresPermission: 'observability:read',\n },\n\n AGGREGATE_TRACES: {\n method: 'POST',\n path: '/observability/traces/aggregate',\n summary: 'Aggregate traces',\n description:\n 'Returns grouped and optionally time-bucketed measures (counts, durations, error rates) over completed logical traces matching an advanced trace predicate',\n requiresPermission: 'observability:read',\n },\n\n QUERY_THREADS: {\n method: 'POST',\n path: '/observability/threads/query',\n summary: 'Query threads',\n description:\n 'Returns full-history thread rows with activity timestamps, first/last traces, previews and context fields',\n requiresPermission: 'observability:read',\n },\n\n QUERY_SPANS: {\n method: 'POST',\n path: '/observability/spans/query',\n summary: 'Query spans',\n description: 'Returns completed spans matching a span predicate, one row per span, with cursor pagination',\n requiresPermission: 'observability:read',\n },\n\n AGGREGATE_SPANS: {\n method: 'POST',\n path: '/observability/spans/aggregate',\n summary: 'Aggregate spans',\n description:\n 'Returns grouped and optionally time-bucketed measures (counts, durations, error rates, tokens, cost) over completed spans matching a span predicate',\n requiresPermission: 'observability:read',\n },\n\n GET_TRACE_QUERY_FIELDS: {\n method: 'POST',\n path: '/observability/traces/query/fields',\n summary: 'Discover trace query fields',\n description: 'Returns canonical query fields and observed top-level string metadata fields',\n requiresPermission: 'observability:read',\n },\n\n GET_TRACE_QUERY_VALUES: {\n method: 'POST',\n path: '/observability/traces/query/values',\n summary: 'Discover trace query values',\n description: 'Returns bounded string value suggestions and occurrence counts for one eligible query field',\n requiresPermission: 'observability:read',\n },\n\n LIST_METRICS: {\n method: 'GET',\n path: '/observability/metrics',\n summary: 'List metrics',\n description: 'Returns a paginated list of metrics with optional filtering and sorting',\n },\n\n LIST_LOGS: {\n method: 'GET',\n path: '/observability/logs',\n summary: 'List logs',\n description: 'Returns a paginated list of logs with optional filtering and sorting',\n },\n\n LIST_SCORES: {\n method: 'GET',\n path: '/observability/scores',\n summary: 'List scores',\n description: 'Returns a paginated list of scores with optional filtering and sorting',\n },\n\n CREATE_SCORE: {\n method: 'POST',\n path: '/observability/scores',\n summary: 'Create a score',\n description: 'Creates a single score record in the observability store',\n },\n\n DELETE_SCORES: {\n method: 'DELETE',\n path: '/observability/scores',\n summary: 'Delete scores',\n description: 'Deletes score records by scoreId, optionally scoped to a tenant',\n requiresPermission: 'observability:delete',\n },\n\n GET_SCORE: {\n method: 'GET',\n path: '/observability/scores/:scoreId',\n summary: 'Get score',\n description: 'Returns a single score by scoreId',\n },\n\n GET_SCORE_AGGREGATE: {\n method: 'POST',\n path: '/observability/scores/aggregate',\n summary: 'Get score aggregate',\n description: 'Returns an aggregated score value with optional period-over-period comparison',\n requiresPermission: 'observability:read',\n },\n\n GET_SCORE_BREAKDOWN: {\n method: 'POST',\n path: '/observability/scores/breakdown',\n summary: 'Get score breakdown',\n description: 'Returns score values grouped by specified dimensions',\n requiresPermission: 'observability:read',\n },\n\n GET_SCORE_TIME_SERIES: {\n method: 'POST',\n path: '/observability/scores/timeseries',\n summary: 'Get score time series',\n description: 'Returns score values bucketed by time interval with optional grouping',\n requiresPermission: 'observability:read',\n },\n\n GET_SCORE_PERCENTILES: {\n method: 'POST',\n path: '/observability/scores/percentiles',\n summary: 'Get score percentiles',\n description: 'Returns percentile values for a score bucketed by time interval',\n requiresPermission: 'observability:read',\n },\n\n LIST_FEEDBACK: {\n method: 'GET',\n path: '/observability/feedback',\n summary: 'List feedback',\n description: 'Returns a paginated list of feedback with optional filtering and sorting',\n },\n\n CREATE_FEEDBACK: {\n method: 'POST',\n path: '/observability/feedback',\n summary: 'Create feedback',\n description: 'Creates a single feedback record in the observability store',\n },\n\n DELETE_FEEDBACK: {\n method: 'DELETE',\n path: '/observability/feedback',\n summary: 'Delete feedback',\n description: 'Deletes feedback records by feedbackId, optionally scoped to a tenant',\n requiresPermission: 'observability:delete',\n },\n\n UPDATE_FEEDBACK_REVIEW_STATUS: {\n method: 'PATCH',\n path: '/observability/feedback/:feedbackId/review-status',\n summary: 'Update feedback review status',\n description: \"Updates a feedback record's review workflow status\",\n requiresPermission: 'observability:write',\n },\n\n GET_FEEDBACK_AGGREGATE: {\n method: 'POST',\n path: '/observability/feedback/aggregate',\n summary: 'Get feedback aggregate',\n description: 'Returns an aggregated numeric feedback value with optional period-over-period comparison',\n requiresPermission: 'observability:read',\n },\n\n GET_FEEDBACK_BREAKDOWN: {\n method: 'POST',\n path: '/observability/feedback/breakdown',\n summary: 'Get feedback breakdown',\n description: 'Returns numeric feedback values grouped by specified dimensions',\n requiresPermission: 'observability:read',\n },\n\n GET_FEEDBACK_TIME_SERIES: {\n method: 'POST',\n path: '/observability/feedback/timeseries',\n summary: 'Get feedback time series',\n description: 'Returns numeric feedback values bucketed by time interval with optional grouping',\n requiresPermission: 'observability:read',\n },\n\n GET_FEEDBACK_PERCENTILES: {\n method: 'POST',\n path: '/observability/feedback/percentiles',\n summary: 'Get feedback percentiles',\n description: 'Returns percentile values for numeric feedback bucketed by time interval',\n requiresPermission: 'observability:read',\n },\n\n GET_METRIC_AGGREGATE: {\n method: 'POST',\n path: '/observability/metrics/aggregate',\n summary: 'Get metric aggregate',\n description: 'Returns an aggregated metric value with optional period-over-period comparison',\n requiresPermission: 'observability:read',\n },\n\n GET_METRIC_BREAKDOWN: {\n method: 'POST',\n path: '/observability/metrics/breakdown',\n summary: 'Get metric breakdown',\n description: 'Returns metric values grouped by specified dimensions',\n requiresPermission: 'observability:read',\n },\n\n GET_METRIC_TIME_SERIES: {\n method: 'POST',\n path: '/observability/metrics/timeseries',\n summary: 'Get metric time series',\n description: 'Returns metric values bucketed by time interval with optional grouping',\n requiresPermission: 'observability:read',\n },\n\n GET_METRIC_PERCENTILES: {\n method: 'POST',\n path: '/observability/metrics/percentiles',\n summary: 'Get metric percentiles',\n description: 'Returns percentile values for a metric bucketed by time interval',\n requiresPermission: 'observability:read',\n },\n\n GET_METRIC_NAMES: {\n method: 'GET',\n path: '/observability/discovery/metric-names',\n summary: 'Get metric names',\n description: 'Returns distinct metric names with optional prefix filtering',\n },\n\n GET_METRIC_LABEL_KEYS: {\n method: 'GET',\n path: '/observability/discovery/metric-label-keys',\n summary: 'Get metric label keys',\n description: 'Returns distinct label keys for a given metric',\n },\n\n GET_METRIC_LABEL_VALUES: {\n method: 'GET',\n path: '/observability/discovery/metric-label-values',\n summary: 'Get label values',\n description: 'Returns distinct values for a given metric label key',\n },\n\n GET_ENTITY_TYPES: {\n method: 'GET',\n path: '/observability/discovery/entity-types',\n summary: 'Get entity types',\n description: 'Returns distinct entity types from observability data',\n },\n\n GET_ENTITY_NAMES: {\n method: 'GET',\n path: '/observability/discovery/entity-names',\n summary: 'Get entity names',\n description: 'Returns distinct entity names with optional type filtering',\n },\n\n GET_SERVICE_NAMES: {\n method: 'GET',\n path: '/observability/discovery/service-names',\n summary: 'Get service names',\n description: 'Returns distinct service names from observability data',\n },\n\n GET_ENVIRONMENTS: {\n method: 'GET',\n path: '/observability/discovery/environments',\n summary: 'Get environments',\n description: 'Returns distinct environments from observability data',\n },\n\n GET_TAGS: {\n method: 'GET',\n path: '/observability/discovery/tags',\n summary: 'Get tags',\n description: 'Returns distinct tags with optional entity type filtering',\n },\n\n GET_CAPABILITIES: {\n method: 'GET',\n path: '/observability/capabilities',\n summary: 'Get observability capabilities',\n description:\n 'Returns which optional observability APIs the configured observability storage supports. Every flag is false when no observability storage is configured.',\n },\n} as const satisfies Record<string, RouteDetails>;\n\nexport type NewRoutesKey = keyof typeof NEW_ROUTE_DEFS;\nexport type NewRoutesDefinitions = (typeof NEW_ROUTE_DEFS)[NewRoutesKey];\n\nexport function createObservabilityListQuerySchema<\n TFilter extends z.ZodObject<z.ZodRawShape>,\n TOrderBy extends z.ZodObject<z.ZodRawShape>,\n>(filterSchema: TFilter, orderBySchema: TOrderBy) {\n const unwrapDefault = (schema: unknown) => {\n const zodSchema = schema as z.ZodTypeAny;\n return zodSchema instanceof z.ZodDefault ? zodSchema.unwrap() : zodSchema;\n };\n const paginationShape = paginationArgsSchema.shape as unknown as Record<string, z.ZodTypeAny>;\n const orderByShape = orderBySchema.shape as unknown as Record<string, z.ZodTypeAny>;\n\n const pageSchema = unwrapDefault(paginationShape.page);\n const perPageSchema = unwrapDefault(paginationShape.perPage);\n const fieldSchema = orderByShape.field ? unwrapDefault(orderByShape.field) : z.never().optional();\n const directionSchema = orderByShape.direction ? unwrapDefault(orderByShape.direction) : z.never().optional();\n\n return wrapSchemaForQueryParams(\n z\n .object({\n ...filterSchema.shape,\n page: pageSchema,\n perPage: perPageSchema,\n field: fieldSchema,\n direction: directionSchema,\n mode: listModeSchema.optional(),\n after: deltaCursorSchema.optional(),\n limit: deltaLimitSchema,\n })\n .partial(),\n ).superRefine((value, ctx) => {\n const isDelta = value.mode === 'delta';\n const hasPagination = value.page !== undefined || value.perPage !== undefined;\n const hasOrderBy = value.field !== undefined || value.direction !== undefined;\n const hasAfter = value.after !== undefined;\n const hasLimit = value.limit !== undefined;\n\n if (isDelta) {\n if (hasPagination) {\n if (value.page !== undefined) {\n ctx.addIssue({\n code: z.ZodIssueCode.custom,\n path: ['page'],\n message: '`page` is not allowed when `mode=delta`',\n });\n }\n if (value.perPage !== undefined) {\n ctx.addIssue({\n code: z.ZodIssueCode.custom,\n path: ['perPage'],\n message: '`perPage` is not allowed when `mode=delta`',\n });\n }\n }\n if (hasOrderBy) {\n if (value.field !== undefined) {\n ctx.addIssue({\n code: z.ZodIssueCode.custom,\n path: ['field'],\n message: '`field` is not allowed when `mode=delta`',\n });\n }\n if (value.direction !== undefined) {\n ctx.addIssue({\n code: z.ZodIssueCode.custom,\n path: ['direction'],\n message: '`direction` is not allowed when `mode=delta`',\n });\n }\n }\n return;\n }\n\n if (hasAfter) {\n ctx.addIssue({\n code: z.ZodIssueCode.custom,\n path: ['after'],\n message: '`after` is only allowed when `mode=delta`',\n });\n }\n if (hasLimit) {\n ctx.addIssue({\n code: z.ZodIssueCode.custom,\n path: ['limit'],\n message: '`limit` is only allowed when `mode=delta`',\n });\n }\n });\n}\n"],"mappings":";;;;;;;AAuBA,MAAa,sCAAsC;AACnD,MAAa,8CACX;AACF,MAAM,4CAA4C;AAClD,MAAM,gDAAgD;AACtD,MAAM,2CAA2C;AACjD,MAAM,+CAA+C;AACrD,MAAM,4CAA4B,IAAI,IAAI;CACxC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF,CAAC;AACD,MAAM,0DAA0D;AAChE,MAAM,wDAAwD;AAC9D,MAAM,gDAAgC,IAAI,IAAI;CAAC;CAAS;CAAa;CAAU;AAAgB,CAAC;AAChG,MAAM,gEAAgE;AACtE,MAAM,yDAAyC,IAAI,IAAI,CAAC,oBAAoB,CAAC;AAC7E,MAAM,gEAAgE;AACtE,MAAM,yDAAyC,IAAI,IAAI,CAAC,oBAAoB,CAAC;AAC7E,MAAM,6DAA6D;AACnE,MAAM,2DAA2D;AAEjE,MAAM,uDAAuC,IAAI,IAAI;CACnD,CAAC,QAAQ,0DAA0D;CACnE,CAAC,YAAY,0DAA0D;CACvE,CAAC,YAAY,wDAAwD;AACvE,CAAC;AACD,MAAM,qEAAqE;AAC3E,MAAM,qEAAqE;AAC3E,MAAM,sDAAsD;AAC5D,MAAM,6CAA6C;AACnD,MAAM,yDAAyD;AAC/D,MAAM,yCAAyC;AAC/C,MAAa,sDAAsD;AACnE,MAAa,yDACX;AAEF,SAAgB,kCAAkC;CAChD,OACE,YAAY,kCAAkC,KAAA,KAC9C,YAAY,sCAAsC,KAAA,KAClD,YAAY,kCAAkC,KAAA,KAC9C,YAAY,s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AAY;IACd,IAAI,MAAM,UAAU,KAAA,GAClB,IAAI,SAAS;KACX,MAAM,EAAE,aAAa;KACrB,MAAM,CAAC,OAAO;KACd,SAAS;IACX,CAAC;IAEH,IAAI,MAAM,cAAc,KAAA,GACtB,IAAI,SAAS;KACX,MAAM,EAAE,aAAa;KACrB,MAAM,CAAC,WAAW;KAClB,SAAS;IACX,CAAC;GAEL;GACA;EACF;EAEA,IAAI,UACF,IAAI,SAAS;GACX,MAAM,EAAE,aAAa;GACrB,MAAM,CAAC,OAAO;GACd,SAAS;EACX,CAAC;EAEH,IAAI,UACF,IAAI,SAAS;GACX,MAAM,EAAE,aAAa;GACrB,MAAM,CAAC,OAAO;GACd,SAAS;EACX,CAAC;CAEL,CAAC;AACH"}
@@ -1,7 +1,7 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  require("../../rolldown-runtime-10nMEhjP.cjs");
3
- const require_observability_new_endpoints = require("../../observability-new-endpoints-CDeHfFNP.cjs");
4
- const require_observability = require("../../observability-CFKSxaff.cjs");
3
+ const require_observability_new_endpoints = require("../../observability-new-endpoints-CaTskbSh.cjs");
4
+ const require_observability = require("../../observability-DHuljMXO.cjs");
5
5
  exports.AGGREGATE_SPANS = require_observability_new_endpoints.AGGREGATE_SPANS;
6
6
  exports.AGGREGATE_TRACES = require_observability_new_endpoints.AGGREGATE_TRACES;
7
7
  exports.CREATE_FEEDBACK = require_observability_new_endpoints.CREATE_FEEDBACK;
@@ -1,3 +1,3 @@
1
- import { A as GET_TRACE_QUERY_VALUES, C as GET_SCORE_AGGREGATE, D as GET_SERVICE_NAMES, E as GET_SCORE_TIME_SERIES, F as NEW_ROUTES, I as QUERY_SPANS, L as QUERY_THREADS, M as LIST_LOGS, N as LIST_METRICS, O as GET_TAGS, P as LIST_SCORES, R as QUERY_TRACES, S as GET_SCORE, T as GET_SCORE_PERCENTILES, _ as GET_METRIC_LABEL_KEYS, a as DELETE_FEEDBACK, b as GET_METRIC_PERCENTILES, c as GET_ENTITY_NAMES, d as GET_FEEDBACK_AGGREGATE, f as GET_FEEDBACK_BREAKDOWN, g as GET_METRIC_BREAKDOWN, h as GET_METRIC_AGGREGATE, i as CREATE_SCORE, j as LIST_FEEDBACK, k as GET_TRACE_QUERY_FIELDS, l as GET_ENTITY_TYPES, m as GET_FEEDBACK_TIME_SERIES, n as AGGREGATE_TRACES, o as DELETE_SCORES, p as GET_FEEDBACK_PERCENTILES, r as CREATE_FEEDBACK, s as GET_CAPABILITIES, t as AGGREGATE_SPANS, u as GET_ENVIRONMENTS, v as GET_METRIC_LABEL_VALUES, w as GET_SCORE_BREAKDOWN, x as GET_METRIC_TIME_SERIES, y as GET_METRIC_NAMES, z as UPDATE_FEEDBACK_REVIEW_STATUS } from "../../observability-new-endpoints-B6MRJ5Rb.js";
2
- import { a as GET_TRACE_ROUTE, c as LIST_SCORES_BY_SPAN_ROUTE, d as SCORE_TRACES_ROUTE, i as GET_TRACE_LIGHT_ROUTE, l as LIST_TRACES_LIGHT_ROUTE, n as GET_BRANCH_ROUTE, o as GET_TRACE_TRAJECTORY_ROUTE, r as GET_SPAN_ROUTE, s as LIST_BRANCHES_ROUTE, t as DELETE_TRACES_ROUTE, u as LIST_TRACES_ROUTE } from "../../observability-65rZOqJk.js";
1
+ import { A as GET_TRACE_QUERY_VALUES, C as GET_SCORE_AGGREGATE, D as GET_SERVICE_NAMES, E as GET_SCORE_TIME_SERIES, F as NEW_ROUTES, I as QUERY_SPANS, L as QUERY_THREADS, M as LIST_LOGS, N as LIST_METRICS, O as GET_TAGS, P as LIST_SCORES, R as QUERY_TRACES, S as GET_SCORE, T as GET_SCORE_PERCENTILES, _ as GET_METRIC_LABEL_KEYS, a as DELETE_FEEDBACK, b as GET_METRIC_PERCENTILES, c as GET_ENTITY_NAMES, d as GET_FEEDBACK_AGGREGATE, f as GET_FEEDBACK_BREAKDOWN, g as GET_METRIC_BREAKDOWN, h as GET_METRIC_AGGREGATE, i as CREATE_SCORE, j as LIST_FEEDBACK, k as GET_TRACE_QUERY_FIELDS, l as GET_ENTITY_TYPES, m as GET_FEEDBACK_TIME_SERIES, n as AGGREGATE_TRACES, o as DELETE_SCORES, p as GET_FEEDBACK_PERCENTILES, r as CREATE_FEEDBACK, s as GET_CAPABILITIES, t as AGGREGATE_SPANS, u as GET_ENVIRONMENTS, v as GET_METRIC_LABEL_VALUES, w as GET_SCORE_BREAKDOWN, x as GET_METRIC_TIME_SERIES, y as GET_METRIC_NAMES, z as UPDATE_FEEDBACK_REVIEW_STATUS } from "../../observability-new-endpoints-CsUP8y2j.js";
2
+ import { a as GET_TRACE_ROUTE, c as LIST_SCORES_BY_SPAN_ROUTE, d as SCORE_TRACES_ROUTE, i as GET_TRACE_LIGHT_ROUTE, l as LIST_TRACES_LIGHT_ROUTE, n as GET_BRANCH_ROUTE, o as GET_TRACE_TRAJECTORY_ROUTE, r as GET_SPAN_ROUTE, s as LIST_BRANCHES_ROUTE, t as DELETE_TRACES_ROUTE, u as LIST_TRACES_ROUTE } from "../../observability-BgIU0otL.js";
3
3
  export { AGGREGATE_SPANS, AGGREGATE_TRACES, CREATE_FEEDBACK, CREATE_SCORE, DELETE_FEEDBACK, DELETE_SCORES, DELETE_TRACES_ROUTE, GET_BRANCH_ROUTE, GET_CAPABILITIES, GET_ENTITY_NAMES, GET_ENTITY_TYPES, GET_ENVIRONMENTS, GET_FEEDBACK_AGGREGATE, GET_FEEDBACK_BREAKDOWN, GET_FEEDBACK_PERCENTILES, GET_FEEDBACK_TIME_SERIES, GET_METRIC_AGGREGATE, GET_METRIC_BREAKDOWN, GET_METRIC_LABEL_KEYS, GET_METRIC_LABEL_VALUES, GET_METRIC_NAMES, GET_METRIC_PERCENTILES, GET_METRIC_TIME_SERIES, GET_SCORE, GET_SCORE_AGGREGATE, GET_SCORE_BREAKDOWN, GET_SCORE_PERCENTILES, GET_SCORE_TIME_SERIES, GET_SERVICE_NAMES, GET_SPAN_ROUTE, GET_TAGS, GET_TRACE_LIGHT_ROUTE, GET_TRACE_QUERY_FIELDS, GET_TRACE_QUERY_VALUES, GET_TRACE_ROUTE, GET_TRACE_TRAJECTORY_ROUTE, LIST_BRANCHES_ROUTE, LIST_FEEDBACK, LIST_LOGS, LIST_METRICS, LIST_SCORES, LIST_SCORES_BY_SPAN_ROUTE, LIST_TRACES_LIGHT_ROUTE, LIST_TRACES_ROUTE, NEW_ROUTES, QUERY_SPANS, QUERY_THREADS, QUERY_TRACES, SCORE_TRACES_ROUTE, UPDATE_FEEDBACK_REVIEW_STATUS };
@@ -3,7 +3,7 @@ require("../../rolldown-runtime-10nMEhjP.cjs");
3
3
  const require_route_builder = require("../../route-builder-CvARmqnA.cjs");
4
4
  const require_server_handlers_error = require("./error.cjs");
5
5
  const require_server_handlers_observability_shared = require("./observability-shared.cjs");
6
- const require_system = require("../../system-DGfJlOxK.cjs");
6
+ const require_system = require("../../system-BxHpBJiq.cjs");
7
7
  let fs = require("fs");
8
8
  // src/server/handlers/system.ts
9
9
  const SOURCE_PROVIDER_CAPABILITIES_TIMEOUT_MS = 3e3;
@@ -90,7 +90,7 @@ const GET_API_SCHEMA_ROUTE = require_route_builder.createRoute({
90
90
  tags: ["System"],
91
91
  requiresAuth: true,
92
92
  handler: async () => {
93
- const { buildApiSchemaManifest } = await Promise.resolve().then(() => require("../../api-schema-manifest-CwFjht0V.cjs"));
93
+ const { buildApiSchemaManifest } = await Promise.resolve().then(() => require("../../api-schema-manifest-BWId44SV.cjs"));
94
94
  return buildApiSchemaManifest();
95
95
  }
96
96
  });
@@ -106,6 +106,8 @@ export declare const GET_SYSTEM_PACKAGES_ROUTE: Omit<import("@mastra/core/server
106
106
  traceQueryRootSpanFields: boolean;
107
107
  traceQueryRootEntityId: boolean;
108
108
  traceQueryTimeToFirstChunkSort: boolean;
109
+ traceQueryTimeToFirstToken: boolean;
110
+ traceQueryTimeToFirstTokenSort: boolean;
109
111
  traceQueryDiscovery: boolean;
110
112
  traceQueryTenantScope: boolean;
111
113
  traceAggregate: boolean;
@@ -183,6 +185,8 @@ export declare const GET_SYSTEM_PACKAGES_ROUTE: Omit<import("@mastra/core/server
183
185
  traceQueryRootSpanFields: import("zod").ZodBoolean;
184
186
  traceQueryRootEntityId: import("zod").ZodBoolean;
185
187
  traceQueryTimeToFirstChunkSort: import("zod").ZodBoolean;
188
+ traceQueryTimeToFirstToken: import("zod").ZodBoolean;
189
+ traceQueryTimeToFirstTokenSort: import("zod").ZodBoolean;
186
190
  traceQueryDiscovery: import("zod").ZodBoolean;
187
191
  traceQueryTenantScope: import("zod").ZodBoolean;
188
192
  traceAggregate: import("zod").ZodBoolean;
@@ -1 +1 @@
1
- {"version":3,"file":"system.d.ts","sourceRoot":"","sources":["../../../src/server/handlers/system.ts"],"names":[],"mappings":"AA+HA,eAAO,MAAM,oBAAoB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAc/B,CAAC;AAEH,eAAO,MAAM,yBAAyB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAgEpC,CAAC"}
1
+ {"version":3,"file":"system.d.ts","sourceRoot":"","sources":["../../../src/server/handlers/system.ts"],"names":[],"mappings":"AA+HA,eAAO,MAAM,oBAAoB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAc/B,CAAC;AAEH,eAAO,MAAM,yBAAyB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAgEpC,CAAC"}
@@ -1,7 +1,7 @@
1
1
  import { n as createRoute } from "../../route-builder-BxPrwNog.js";
2
2
  import { handleError } from "./error.js";
3
3
  import { getObservabilityStorageCapabilities } from "./observability-shared.js";
4
- import { t as apiSchemaManifestResponseSchema, u as systemPackagesResponseSchema } from "../../system-B8L_G4oo.js";
4
+ import { t as apiSchemaManifestResponseSchema, u as systemPackagesResponseSchema } from "../../system-CxwzIMsy.js";
5
5
  import { readFileSync } from "fs";
6
6
  // src/server/handlers/system.ts
7
7
  const SOURCE_PROVIDER_CAPABILITIES_TIMEOUT_MS = 3e3;
@@ -88,7 +88,7 @@ const GET_API_SCHEMA_ROUTE = createRoute({
88
88
  tags: ["System"],
89
89
  requiresAuth: true,
90
90
  handler: async () => {
91
- const { buildApiSchemaManifest } = await import("../../api-schema-manifest-JUFooPZG.js");
91
+ const { buildApiSchemaManifest } = await import("../../api-schema-manifest-BVPhF1ZS.js");
92
92
  return buildApiSchemaManifest();
93
93
  }
94
94
  });
@@ -2,15 +2,15 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  require("../rolldown-runtime-10nMEhjP.cjs");
3
3
  const require_server_handlers_error = require("./handlers/error.cjs");
4
4
  const require_workflows = require("../workflows-BAOfWBkr.cjs");
5
- const require_agent_builder = require("../agent-builder-DXhQCXod.cjs");
5
+ const require_agent_builder = require("../agent-builder-DIEX-as5.cjs");
6
6
  const require_agents = require("../agents-D36tukip.cjs");
7
7
  const require_plans = require("../plans-Dydti0sT.cjs");
8
8
  const require_a2a = require("../a2a-CmMIWPuz.cjs");
9
9
  const require_conversations = require("../conversations-CJn0ioOZ.cjs");
10
10
  const require_logs = require("../logs-DI-h9uHR.cjs");
11
11
  const require_mcp = require("../mcp-mpYrlkUA.cjs");
12
- const require_memory = require("../memory-DpKQ1Quf.cjs");
13
- const require_observability = require("../observability-CFKSxaff.cjs");
12
+ const require_memory = require("../memory-Buhi6kZ-.cjs");
13
+ const require_observability = require("../observability-DHuljMXO.cjs");
14
14
  const require_responses = require("../responses-CxvSoOLt.cjs");
15
15
  const require_scores = require("../scores-CnozEyM4.cjs");
16
16
  const require_tools = require("../tools-CeJrnYDf.cjs");
@@ -1,14 +1,14 @@
1
1
  import { formatZodError, isZodError } from "./handlers/error.js";
2
2
  import { k as workflows_exports } from "../workflows-DPIRVRN9.js";
3
- import { _ as agent_builder_exports } from "../agent-builder-CrmZ77IU.js";
3
+ import { _ as agent_builder_exports } from "../agent-builder-XhBB0Svr.js";
4
4
  import { H as agents_exports } from "../agents-BVjnYswL.js";
5
5
  import { n as plans_exports } from "../plans-B5GgYqx-.js";
6
6
  import { r as a2a_exports } from "../a2a-CSz0rw8E.js";
7
7
  import { a as conversations_exports } from "../conversations-CABVTBQY.js";
8
8
  import { i as logs_exports } from "../logs-BbaBP2LD.js";
9
9
  import { h as mcp_exports } from "../mcp-D3F3iYew.js";
10
- import { O as memory_exports } from "../memory-DQXCDswv.js";
11
- import { f as observability_exports } from "../observability-65rZOqJk.js";
10
+ import { O as memory_exports } from "../memory-BTR95ujT.js";
11
+ import { f as observability_exports } from "../observability-BgIU0otL.js";
12
12
  import { i as responses_exports } from "../responses-DbiqhxP3.js";
13
13
  import { s as scores_exports } from "../scores-BjclMqFa.js";
14
14
  import { o as tools_exports } from "../tools-Ck35EVD7.js";
@@ -18,7 +18,7 @@ const require_responses = require("../../responses-CTiwnWeF.cjs");
18
18
  const require_conversations = require("../../conversations-BVj0Dk2Q.cjs");
19
19
  const require_logs = require("../../logs-YisOj8HR.cjs");
20
20
  const require_mcp = require("../../mcp-Bt3h1lO7.cjs");
21
- const require_system = require("../../system-DGfJlOxK.cjs");
21
+ const require_system = require("../../system-BxHpBJiq.cjs");
22
22
  const require_scores = require("../../scores-CWCaN4jf.cjs");
23
23
  const require_vectors = require("../../vectors-CPSofSCf.cjs");
24
24
  const require_version_common = require("../../version-common-Cc0STXl9.cjs");
@@ -16,7 +16,7 @@ import { _ as responseToolSchema, a as deleteResponseSchema, c as responseInputT
16
16
  import { a as createConversationBodySchema, i as conversationObjectSchema, n as conversationIdPathParams, r as conversationItemsListSchema, t as conversationDeletedSchema } from "../../conversations-DHrKTI6x.js";
17
17
  import { n as listLogsQuerySchema, r as listLogsResponseSchema, t as listLogTransportsResponseSchema } from "../../logs-Ca_q8krO.js";
18
18
  import { C as serverDetailSchema, E as versionDetailSchema, _ as mcpServerToolPathParams, a as getMcpServerDetailQuerySchema, c as listMcpServerToolsResponseSchema, f as mcpServerDetailPathParams, h as mcpServerIdPathParams, i as executeToolResponseSchema$1, l as listMcpServersQuerySchema, o as jsonRpcErrorSchema, r as executeToolBodySchema$1, u as listMcpServersResponseSchema, v as mcpToolInfoSchema, w as serverInfoSchema } from "../../mcp-D4Cprr8R.js";
19
- import { a as editorSourceSchema, c as observabilityRuntimeStrategySchema, i as editorSourceCapabilitiesSchema, l as observabilityStorageCapabilitiesSchema, n as apiSchemaManifestRouteSchema, o as mastraPackageSchema, r as apiSchemaResponseShapeSchema, s as observabilityDiscoveryCapabilitiesSchema, t as apiSchemaManifestResponseSchema, u as systemPackagesResponseSchema } from "../../system-B8L_G4oo.js";
19
+ import { a as editorSourceSchema, c as observabilityRuntimeStrategySchema, i as editorSourceCapabilitiesSchema, l as observabilityStorageCapabilitiesSchema, n as apiSchemaManifestRouteSchema, o as mastraPackageSchema, r as apiSchemaResponseShapeSchema, s as observabilityDiscoveryCapabilitiesSchema, t as apiSchemaManifestResponseSchema, u as systemPackagesResponseSchema } from "../../system-CxwzIMsy.js";
20
20
  import { a as listScoresByScorerIdQuerySchema, c as scorerEntrySchema, i as listScoresByRunIdQuerySchema, l as scorerIdPathParams, n as listScorersResponseSchema, o as saveScoreBodySchema, r as listScoresByEntityIdQuerySchema, s as saveScoreResponseSchema, t as entityPathParams, u as scoresWithPaginationResponseSchema } from "../../scores-BULd4ZBI.js";
21
21
  import { a as listEmbeddersResponseSchema, c as queryVectorsBodySchema, d as upsertVectorsResponseSchema, f as vectorIndexPathParams, i as describeIndexResponseSchema, l as queryVectorsResponseSchema, n as createIndexResponseSchema, o as listIndexesResponseSchema, p as vectorNamePathParams, r as deleteIndexResponseSchema, s as listVectorsResponseSchema, t as createIndexBodySchema, u as upsertVectorsBodySchema } from "../../vectors-CadLydEJ.js";
22
22
  import { a as createVersionBodySchema, c as versionDiffEntrySchema, i as createListVersionsResponseSchema, l as versionOrderBySchema, n as compareVersionsQuerySchema, o as deleteVersionResponseSchema, r as createCompareVersionsResponseSchema, s as listVersionsQuerySchema, t as activateVersionResponseSchema } from "../../version-common-BLTDO88f.js";
@@ -40,6 +40,8 @@ export declare const observabilityStorageCapabilitiesSchema: z.ZodObject<{
40
40
  traceQueryRootSpanFields: z.ZodBoolean;
41
41
  traceQueryRootEntityId: z.ZodBoolean;
42
42
  traceQueryTimeToFirstChunkSort: z.ZodBoolean;
43
+ traceQueryTimeToFirstToken: z.ZodBoolean;
44
+ traceQueryTimeToFirstTokenSort: z.ZodBoolean;
43
45
  traceQueryDiscovery: z.ZodBoolean;
44
46
  traceQueryTenantScope: z.ZodBoolean;
45
47
  traceAggregate: z.ZodBoolean;
@@ -128,6 +130,8 @@ export declare const systemPackagesResponseSchema: z.ZodObject<{
128
130
  traceQueryRootSpanFields: z.ZodBoolean;
129
131
  traceQueryRootEntityId: z.ZodBoolean;
130
132
  traceQueryTimeToFirstChunkSort: z.ZodBoolean;
133
+ traceQueryTimeToFirstToken: z.ZodBoolean;
134
+ traceQueryTimeToFirstTokenSort: z.ZodBoolean;
131
135
  traceQueryDiscovery: z.ZodBoolean;
132
136
  traceQueryTenantScope: z.ZodBoolean;
133
137
  traceAggregate: z.ZodBoolean;
@@ -1 +1 @@
1
- {"version":3,"file":"system.d.ts","sourceRoot":"","sources":["../../../src/server/schemas/system.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,QAAQ,CAAC;AAE3B,eAAO,MAAM,mBAAmB;;;iBAG9B,CAAC;AAEH,eAAO,MAAM,kCAAkC;;;;;EAK7C,CAAC;AAEH,eAAO,MAAM,wCAAwC;;;;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;;;;;;;;;;;;;;;;;;iBAoBvC,CAAC;AAIH,eAAO,MAAM,4BAA4B;;;;;;;;;;iBAIvC,CAAC;AAEH,eAAO,MAAM,4BAA4B;;;;;;;;;;;;;;;;;;;iBASvC,CAAC;AAEH,eAAO,MAAM,+BAA+B;;;;;;;;;;;;;;;;;;;;;;iBAG1C,CAAC;AAEH,MAAM,MAAM,aAAa,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,mBAAmB,CAAC,CAAC;AAChE,MAAM,MAAM,sBAAsB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,4BAA4B,CAAC,CAAC"}
@@ -6,7 +6,7 @@ const require_utils = require("../../utils-BnH77wPf.cjs");
6
6
  const require_constants = require("../../constants-Co1XjPjd.cjs");
7
7
  const require_server_handlers_error = require("../handlers/error.cjs");
8
8
  const require_helpers = require("../../helpers-CE1fJdLM.cjs");
9
- const require_routes = require("../../routes-CbwRkg8_.cjs");
9
+ const require_routes = require("../../routes-By3cLbPV.cjs");
10
10
  let zod_v4 = require("zod/v4");
11
11
  let stream = require("stream");
12
12
  let _mastra_core_request_context = require("@mastra/core/request-context");
@@ -4,7 +4,7 @@ import { o as normalizeRoutePath, t as WorkflowRegistry } from "../../utils-YEuw
4
4
  import { f as RESERVED_REQUEST_CONTEXT_KEYS, h as isStudioClientTypeHeader, i as MASTRA_IS_STUDIO_KEY, l as MASTRA_USER_KEY, m as isReservedRequestContextKey, n as MASTRA_AUTH_TOKEN_KEY, o as MASTRA_RESOURCE_ID_KEY$1, r as MASTRA_CLIENT_TYPE_HEADER, s as MASTRA_STUDIO_CLIENT_TYPE, t as MASTRA_AUTH_MODE_KEY } from "../../constants-ohUUT3Vg.js";
5
5
  import { formatZodError, isZodError } from "../handlers/error.js";
6
6
  import { d as pathMatchesPattern, i as findMatchingCustomRoute, o as isCustomRoutePublic, r as coreAuthMiddleware } from "../../helpers-CMCXsowL.js";
7
- import { t as SERVER_ROUTES } from "../../routes-M2U8U4Jl.js";
7
+ import { t as SERVER_ROUTES } from "../../routes-CBrxFxzL.js";
8
8
  import { z } from "zod/v4";
9
9
  import { Readable } from "stream";
10
10
  import { RequestContext } from "@mastra/core/request-context";
@@ -283,7 +283,7 @@ export declare const OBSERVABILITY_ROUTES: readonly [import(".").ServerRoute, Om
283
283
  by: ["threadId"];
284
284
  } | undefined;
285
285
  orderBy?: {
286
- field: "endedAt" | "startedAt" | "timeToFirstChunkMs";
286
+ field: "endedAt" | "startedAt" | "timeToFirstChunkMs" | "timeToFirstTokenMs";
287
287
  direction: "asc" | "desc";
288
288
  }[] | undefined;
289
289
  page?: {
@@ -318,6 +318,7 @@ export declare const OBSERVABILITY_ROUTES: readonly [import(".").ServerRoute, Om
318
318
  environment: string | null;
319
319
  status: "error" | "success";
320
320
  timeToFirstChunkMs?: number | null | undefined;
321
+ timeToFirstTokenMs?: number | null | undefined;
321
322
  }[];
322
323
  page: {
323
324
  next: string | null;
@@ -343,6 +344,7 @@ export declare const OBSERVABILITY_ROUTES: readonly [import(".").ServerRoute, Om
343
344
  environment: string | null;
344
345
  status: "error" | "success";
345
346
  timeToFirstChunkMs?: number | null | undefined;
347
+ timeToFirstTokenMs?: number | null | undefined;
346
348
  }[];
347
349
  pagination: {
348
350
  total: number;
@@ -372,6 +374,7 @@ export declare const OBSERVABILITY_ROUTES: readonly [import(".").ServerRoute, Om
372
374
  environment: string | null;
373
375
  status: "error" | "success";
374
376
  timeToFirstChunkMs?: number | null | undefined;
377
+ timeToFirstTokenMs?: number | null | undefined;
375
378
  }[];
376
379
  delta: {
377
380
  limit: number;
@@ -410,6 +413,7 @@ export declare const OBSERVABILITY_ROUTES: readonly [import(".").ServerRoute, Om
410
413
  endedAt: "endedAt";
411
414
  startedAt: "startedAt";
412
415
  timeToFirstChunkMs: "timeToFirstChunkMs";
416
+ timeToFirstTokenMs: "timeToFirstTokenMs";
413
417
  }>;
414
418
  direction: import("zod").ZodEnum<{
415
419
  asc: "asc";
@@ -451,6 +455,7 @@ export declare const OBSERVABILITY_ROUTES: readonly [import(".").ServerRoute, Om
451
455
  success: "success";
452
456
  }>;
453
457
  timeToFirstChunkMs: import("zod").ZodOptional<import("zod").ZodNullable<import("zod").ZodNumber>>;
458
+ timeToFirstTokenMs: import("zod").ZodOptional<import("zod").ZodNullable<import("zod").ZodNumber>>;
454
459
  }, import("zod/v4/core").$strict>>;
455
460
  page: import("zod").ZodObject<{
456
461
  next: import("zod").ZodNullable<import("zod").ZodString>;
@@ -479,6 +484,7 @@ export declare const OBSERVABILITY_ROUTES: readonly [import(".").ServerRoute, Om
479
484
  success: "success";
480
485
  }>;
481
486
  timeToFirstChunkMs: import("zod").ZodOptional<import("zod").ZodNullable<import("zod").ZodNumber>>;
487
+ timeToFirstTokenMs: import("zod").ZodOptional<import("zod").ZodNullable<import("zod").ZodNumber>>;
482
488
  }, import("zod/v4/core").$strict>>;
483
489
  pagination: import("zod").ZodObject<{
484
490
  total: import("zod").ZodNumber;
@@ -511,6 +517,7 @@ export declare const OBSERVABILITY_ROUTES: readonly [import(".").ServerRoute, Om
511
517
  success: "success";
512
518
  }>;
513
519
  timeToFirstChunkMs: import("zod").ZodOptional<import("zod").ZodNullable<import("zod").ZodNumber>>;
520
+ timeToFirstTokenMs: import("zod").ZodOptional<import("zod").ZodNullable<import("zod").ZodNumber>>;
514
521
  }, import("zod/v4/core").$strict>>;
515
522
  delta: import("zod").ZodObject<{
516
523
  limit: import("zod").ZodNumber;
@@ -861,6 +868,7 @@ export declare const OBSERVABILITY_ROUTES: readonly [import(".").ServerRoute, Om
861
868
  startedAt: string;
862
869
  endedAt: string;
863
870
  timeToFirstChunkMs: number | null;
871
+ timeToFirstTokenMs?: number | null | undefined;
864
872
  inputPreview: string | null;
865
873
  outputPreview: string | null;
866
874
  errorPreview: string | null;
@@ -957,6 +965,7 @@ export declare const OBSERVABILITY_ROUTES: readonly [import(".").ServerRoute, Om
957
965
  startedAt: import("zod").ZodString;
958
966
  endedAt: import("zod").ZodString;
959
967
  timeToFirstChunkMs: import("zod").ZodNullable<import("zod").ZodNumber>;
968
+ timeToFirstTokenMs: import("zod").ZodOptional<import("zod").ZodNullable<import("zod").ZodNumber>>;
960
969
  inputPreview: import("zod").ZodNullable<import("zod").ZodString>;
961
970
  outputPreview: import("zod").ZodNullable<import("zod").ZodString>;
962
971
  errorPreview: import("zod").ZodNullable<import("zod").ZodString>;
@@ -988,7 +997,7 @@ export declare const OBSERVABILITY_ROUTES: readonly [import(".").ServerRoute, Om
988
997
  };
989
998
  where?: import("@mastra/core/storage").TraceQueryScalarPredicate | undefined;
990
999
  orderBy: {
991
- field: "endedAt" | "startedAt" | "timeToFirstChunkMs";
1000
+ field: "endedAt" | "startedAt" | "timeToFirstChunkMs" | "timeToFirstTokenMs";
992
1001
  direction: "asc" | "desc";
993
1002
  }[];
994
1003
  page: {
@@ -1035,6 +1044,7 @@ export declare const OBSERVABILITY_ROUTES: readonly [import(".").ServerRoute, Om
1035
1044
  outputPreview: string | null;
1036
1045
  errorPreview: string | null;
1037
1046
  timeToFirstChunkMs?: number | null | undefined;
1047
+ timeToFirstTokenMs?: number | null | undefined;
1038
1048
  }[];
1039
1049
  page: {
1040
1050
  next: string | null;
@@ -1061,6 +1071,7 @@ export declare const OBSERVABILITY_ROUTES: readonly [import(".").ServerRoute, Om
1061
1071
  endedAt: "endedAt";
1062
1072
  startedAt: "startedAt";
1063
1073
  timeToFirstChunkMs: "timeToFirstChunkMs";
1074
+ timeToFirstTokenMs: "timeToFirstTokenMs";
1064
1075
  }>;
1065
1076
  direction: import("zod").ZodEnum<{
1066
1077
  asc: "asc";
@@ -1114,6 +1125,7 @@ export declare const OBSERVABILITY_ROUTES: readonly [import(".").ServerRoute, Om
1114
1125
  outputPreview: import("zod").ZodNullable<import("zod").ZodString>;
1115
1126
  errorPreview: import("zod").ZodNullable<import("zod").ZodString>;
1116
1127
  timeToFirstChunkMs: import("zod").ZodOptional<import("zod").ZodNullable<import("zod").ZodNumber>>;
1128
+ timeToFirstTokenMs: import("zod").ZodOptional<import("zod").ZodNullable<import("zod").ZodNumber>>;
1117
1129
  }, import("zod/v4/core").$strict>>;
1118
1130
  page: import("zod").ZodObject<{
1119
1131
  next: import("zod").ZodNullable<import("zod").ZodString>;
@@ -4176,6 +4188,8 @@ export declare const OBSERVABILITY_ROUTES: readonly [import(".").ServerRoute, Om
4176
4188
  traceQueryRootSpanFields: boolean;
4177
4189
  traceQueryRootEntityId: boolean;
4178
4190
  traceQueryTimeToFirstChunkSort: boolean;
4191
+ traceQueryTimeToFirstToken: boolean;
4192
+ traceQueryTimeToFirstTokenSort: boolean;
4179
4193
  traceQueryDiscovery: boolean;
4180
4194
  traceQueryTenantScope: boolean;
4181
4195
  traceAggregate: boolean;
@@ -4219,6 +4233,8 @@ export declare const OBSERVABILITY_ROUTES: readonly [import(".").ServerRoute, Om
4219
4233
  traceQueryRootSpanFields: import("zod").ZodBoolean;
4220
4234
  traceQueryRootEntityId: import("zod").ZodBoolean;
4221
4235
  traceQueryTimeToFirstChunkSort: import("zod").ZodBoolean;
4236
+ traceQueryTimeToFirstToken: import("zod").ZodBoolean;
4237
+ traceQueryTimeToFirstTokenSort: import("zod").ZodBoolean;
4222
4238
  traceQueryDiscovery: import("zod").ZodBoolean;
4223
4239
  traceQueryTenantScope: import("zod").ZodBoolean;
4224
4240
  traceAggregate: import("zod").ZodBoolean;