@mastra/pg 1.33.0-alpha.3 → 1.33.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { ErrorCategory, ErrorDomain, MastraError } from "@mastra/core/error";
2
2
  import * as coreStorage from "@mastra/core/storage";
3
- import { AgentsStorage, BRANCH_SPAN_TYPES, BackgroundTasksStorage, BlobStore, ChannelsStorage, DATASETS_SCHEMA, DATASET_ITEMS_SCHEMA, DATASET_VERSIONS_SCHEMA, DatasetsStorage, EXPERIMENTS_SCHEMA, EXPERIMENT_RESULTS_SCHEMA, EntityType, ExperimentsStorage, FactoryStorage, FavoritesStorage, KNOWLEDGE_SEMANTIC_OUTBOX_SCHEMA, KnowledgeConflictError, KnowledgeNotFoundError, KnowledgeStorage, MCPClientsStorage, MCPServersStorage, METRIC_DISTINCT_COLUMNS, MastraCompositeStore, MemoryStorage, NotificationsStorage, OBSERVATIONAL_MEMORY_TABLE_SCHEMA, ObservabilityStorage, PromptBlocksStorage, RUN_FENCING_TABLE_SCHEMAS, RunFenceConflictError, SchedulesStorage, ScorerDefinitionsStorage, ScoresStorage, SkillsStorage, TABLE_AGENTS, TABLE_AGENT_VERSIONS, TABLE_BACKGROUND_TASKS, TABLE_CHANNEL_CONFIG, TABLE_CHANNEL_INSTALLATIONS, TABLE_CONFIGS, TABLE_DATASETS, TABLE_DATASET_ITEMS, TABLE_DATASET_VERSIONS, TABLE_EXPERIMENTS, TABLE_EXPERIMENT_RESULTS, TABLE_FAVORITES, TABLE_KNOWLEDGE_ACTIVITY, TABLE_KNOWLEDGE_MENTIONS, TABLE_KNOWLEDGE_NODES, TABLE_KNOWLEDGE_RECORDS, TABLE_KNOWLEDGE_SEMANTIC_OUTBOX, TABLE_MCP_CLIENTS, TABLE_MCP_CLIENT_VERSIONS, TABLE_MCP_SERVERS, TABLE_MCP_SERVER_VERSIONS, TABLE_MEMORY_RUN_FENCES, TABLE_MESSAGES, TABLE_NOTIFICATIONS, TABLE_PROMPT_BLOCKS, TABLE_PROMPT_BLOCK_VERSIONS, TABLE_RESOURCES, TABLE_SCHEDULES, TABLE_SCHEDULE_TRIGGERS, TABLE_SCHEMAS, TABLE_SCORERS, TABLE_SCORER_DEFINITIONS, TABLE_SCORER_DEFINITION_VERSIONS, TABLE_SKILLS, TABLE_SKILL_BLOBS, TABLE_SKILL_VERSIONS, TABLE_SPANS, TABLE_THREADS, TABLE_THREAD_STATE, TABLE_TOOL_PROVIDER_CONNECTIONS, TABLE_WORKFLOW_DEFINITIONS, TABLE_WORKFLOW_RUN_OWNERS, TABLE_WORKFLOW_SNAPSHOT, TABLE_WORKSPACES, TABLE_WORKSPACE_VERSIONS, ThreadStateStorage, ToolProviderConnectionsStorage, TraceStatus, UniqueViolationError, WorkflowDefinitionsStorage, WorkflowsStorage, WorkspacesStorage, assertWorkflowStepGuard, calculatePagination, canonicalizeKnowledgeScope, computeTraceStatus, createKnowledgeUlid, createStorageErrorId, createVectorErrorId, ensureDate, executeRetentionPrune, getDefaultValue, getSqlType, hasErrorCode, isKnowledgeScopeVisible, isRunFenceConflictError, isWorkflowStepConflictError, knowledgeScopeKey, knowledgeSemanticDocumentId, knowledgeSemanticIdempotencyKey, listBranchesArgsSchema, listFeedbackArgsSchema, listLogsArgsSchema, listMetricsArgsSchema, listScoresArgsSchema, listTracesArgsSchema, matchesExpectedWorkflowStatus, matchesRunFence, mergeWorkflowStepResult, normalizePerPage, normalizeScheduleTarget, parseDuration, parseKnowledgeNodeCursor, parseKnowledgeWikilinks, resolveListOrderBy, resolveRetentionTargets, resolveRunFence, retentionCutoffMs, runRetentionBatches, safelyParseJSON, storageMessageMatchesMetadataFilter, toTraceSpans, transformScoreRow, validateStorageMetadataFilter } from "@mastra/core/storage";
3
+ import { AgentsStorage, BRANCH_SPAN_TYPES, BackgroundTasksStorage, BlobStore, ChannelsStorage, DATASETS_SCHEMA, DATASET_ITEMS_SCHEMA, DATASET_VERSIONS_SCHEMA, DatasetsStorage, EXPERIMENTS_SCHEMA, EXPERIMENT_RESULTS_SCHEMA, EntityType, ExperimentsStorage, FactoryStorage, FavoritesStorage, KNOWLEDGE_SEMANTIC_OUTBOX_SCHEMA, KnowledgeConflictError, KnowledgeNotFoundError, KnowledgeStorage, MCPClientsStorage, MCPServersStorage, METRIC_DISTINCT_COLUMNS, MastraCompositeStore, MemoryStorage, NotificationsStorage, OBSERVATIONAL_MEMORY_TABLE_SCHEMA, ObservabilityStorage, PromptBlocksStorage, RUN_FENCING_TABLE_SCHEMAS, RunFenceConflictError, SchedulesStorage, ScorerDefinitionsStorage, ScoresStorage, SkillsStorage, TABLE_AGENTS, TABLE_AGENT_VERSIONS, TABLE_BACKGROUND_TASKS, TABLE_CHANNEL_CONFIG, TABLE_CHANNEL_INSTALLATIONS, TABLE_CONFIGS, TABLE_DATASETS, TABLE_DATASET_ITEMS, TABLE_DATASET_VERSIONS, TABLE_EXPERIMENTS, TABLE_EXPERIMENT_RESULTS, TABLE_FAVORITES, TABLE_KNOWLEDGE_ACTIVITY, TABLE_KNOWLEDGE_MENTIONS, TABLE_KNOWLEDGE_NODES, TABLE_KNOWLEDGE_RECORDS, TABLE_KNOWLEDGE_SEMANTIC_OUTBOX, TABLE_MCP_CLIENTS, TABLE_MCP_CLIENT_VERSIONS, TABLE_MCP_SERVERS, TABLE_MCP_SERVER_VERSIONS, TABLE_MEMORY_RUN_FENCES, TABLE_MESSAGES, TABLE_NOTIFICATIONS, TABLE_PROMPT_BLOCKS, TABLE_PROMPT_BLOCK_VERSIONS, TABLE_RESOURCES, TABLE_SCHEDULES, TABLE_SCHEDULE_TRIGGERS, TABLE_SCHEMAS, TABLE_SCORERS, TABLE_SCORER_DEFINITIONS, TABLE_SCORER_DEFINITION_VERSIONS, TABLE_SKILLS, TABLE_SKILL_BLOBS, TABLE_SKILL_VERSIONS, TABLE_SPANS, TABLE_THREADS, TABLE_THREAD_STATE, TABLE_TOOL_PROVIDER_CONNECTIONS, TABLE_WORKFLOW_DEFINITIONS, TABLE_WORKFLOW_RUN_OWNERS, TABLE_WORKFLOW_SNAPSHOT, TABLE_WORKSPACES, TABLE_WORKSPACE_VERSIONS, ThreadStateStorage, ToolProviderConnectionsStorage, TraceStatus, UniqueViolationError, WorkflowDefinitionsStorage, WorkflowsStorage, WorkspacesStorage, assertWorkflowStepGuard, calculatePagination, canonicalizeKnowledgeScope, computeTraceStatus, createKnowledgeUlid, createStorageErrorId, createVectorErrorId, ensureDate, executeRetentionPrune, getDefaultValue, getSqlType, getStringAttribute, hasErrorCode, isKnowledgeScopeVisible, isRunFenceConflictError, isWorkflowStepConflictError, knowledgeScopeKey, knowledgeSemanticDocumentId, knowledgeSemanticIdempotencyKey, listBranchesArgsSchema, listFeedbackArgsSchema, listLogsArgsSchema, listMetricsArgsSchema, listScoresArgsSchema, listTracesArgsSchema, matchesExpectedWorkflowStatus, matchesRunFence, mergeWorkflowStepResult, normalizePerPage, normalizeScheduleTarget, parseDuration, parseKnowledgeNodeCursor, parseKnowledgeWikilinks, resolveListOrderBy, resolveRetentionTargets, resolveRunFence, retentionCutoffMs, runRetentionBatches, safelyParseJSON, storageMessageMatchesMetadataFilter, toTraceSpans, transformScoreRow, validateStorageMetadataFilter } from "@mastra/core/storage";
4
4
  import { parseFieldKey, parseSqlIdentifier } from "@mastra/core/utils";
5
5
  import { MastraVector, validateTopK, validateUpsertInput } from "@mastra/core/vector";
6
6
  import { Mutex } from "async-mutex";
@@ -239,7 +239,7 @@ const createNumericOperator = (symbol) => {
239
239
  sql: `(CASE WHEN jsonb_typeof(${jsonExtract}) = 'number' THEN (${textExtract})::numeric ${symbol} $${paramIndex}::numeric ELSE NULL END)`,
240
240
  needsValue: true
241
241
  };
242
- else return {
242
+ return {
243
243
  sql: `${textExtract} ${symbol} $${paramIndex}::text`,
244
244
  needsValue: true
245
245
  };
@@ -16103,6 +16103,51 @@ const SPAN_EVENT_COLUMNS = [
16103
16103
  type: "double precision",
16104
16104
  nullable: true
16105
16105
  },
16106
+ {
16107
+ name: "externalParentSpanId",
16108
+ type: "text",
16109
+ nullable: true
16110
+ },
16111
+ {
16112
+ name: "resumedFromSpanId",
16113
+ type: "text",
16114
+ nullable: true
16115
+ },
16116
+ {
16117
+ name: "model",
16118
+ type: "text",
16119
+ nullable: true
16120
+ },
16121
+ {
16122
+ name: "provider",
16123
+ type: "text",
16124
+ nullable: true
16125
+ },
16126
+ {
16127
+ name: "outcome",
16128
+ type: "text",
16129
+ nullable: true
16130
+ },
16131
+ {
16132
+ name: "stopReason",
16133
+ type: "text",
16134
+ nullable: true
16135
+ },
16136
+ {
16137
+ name: "timeToFirstTokenMs",
16138
+ type: "double precision",
16139
+ nullable: true
16140
+ },
16141
+ {
16142
+ name: "errorCount",
16143
+ type: "integer",
16144
+ nullable: true
16145
+ },
16146
+ {
16147
+ name: "stopReasonContext",
16148
+ type: "jsonb",
16149
+ nullable: true
16150
+ },
16106
16151
  {
16107
16152
  name: "tags",
16108
16153
  type: "text[]",
@@ -16811,6 +16856,26 @@ function allTableDDL(schema, mode) {
16811
16856
  ];
16812
16857
  }
16813
16858
  /**
16859
+ * Span event columns added after the table first shipped, with their types. All
16860
+ * nullable with no default, so each ALTER is a catalog-only change; rows written
16861
+ * before it read NULL and readers fall back to the payload or attributes.
16862
+ */
16863
+ const ADDED_SPAN_COLUMNS = [
16864
+ ["inputPreview", "text"],
16865
+ ["outputPreview", "text"],
16866
+ ["errorPreview", "text"],
16867
+ ["timeToFirstChunkMs", "double precision"],
16868
+ ["externalParentSpanId", "text"],
16869
+ ["resumedFromSpanId", "text"],
16870
+ ["model", "text"],
16871
+ ["provider", "text"],
16872
+ ["outcome", "text"],
16873
+ ["stopReason", "text"],
16874
+ ["timeToFirstTokenMs", "double precision"],
16875
+ ["errorCount", "integer"],
16876
+ ["stopReasonContext", "jsonb"]
16877
+ ];
16878
+ /**
16814
16879
  * Additive column migrations for tables created by an older version of this
16815
16880
  * schema. `CREATE TABLE IF NOT EXISTS` is a no-op on an existing table, so new
16816
16881
  * columns have to be added out of band.
@@ -16827,20 +16892,11 @@ function additiveColumns(schema) {
16827
16892
  column: "isPending",
16828
16893
  ddl: `ALTER TABLE ${qualifiedTable(schema, TABLE_SPAN_EVENTS)} ADD COLUMN IF NOT EXISTS "isPending" boolean NOT NULL DEFAULT false`
16829
16894
  },
16830
- ...[
16831
- "inputPreview",
16832
- "outputPreview",
16833
- "errorPreview"
16834
- ].map((column) => ({
16895
+ ...ADDED_SPAN_COLUMNS.map(([column, type]) => ({
16835
16896
  table: TABLE_SPAN_EVENTS,
16836
16897
  column,
16837
- ddl: `ALTER TABLE ${qualifiedTable(schema, TABLE_SPAN_EVENTS)} ADD COLUMN IF NOT EXISTS "${column}" text`
16898
+ ddl: `ALTER TABLE ${qualifiedTable(schema, TABLE_SPAN_EVENTS)} ADD COLUMN IF NOT EXISTS "${column}" ${type}`
16838
16899
  })),
16839
- {
16840
- table: TABLE_SPAN_EVENTS,
16841
- column: "timeToFirstChunkMs",
16842
- ddl: `ALTER TABLE ${qualifiedTable(schema, TABLE_SPAN_EVENTS)} ADD COLUMN IF NOT EXISTS "timeToFirstChunkMs" double precision`
16843
- },
16844
16900
  {
16845
16901
  table: TABLE_FEEDBACK_EVENTS,
16846
16902
  column: "reviewStatus",
@@ -17393,6 +17449,11 @@ const PROMOTED_KEYS = /* @__PURE__ */ new Set([
17393
17449
  "executionSource",
17394
17450
  "serviceName"
17395
17451
  ]);
17452
+ function nullableNumber$1(value) {
17453
+ if (value == null || value === "") return null;
17454
+ const n = Number(value);
17455
+ return Number.isNaN(n) ? null : n;
17456
+ }
17396
17457
  function nullableString(value) {
17397
17458
  if (typeof value === "string") return value === "" ? null : value;
17398
17459
  if (value == null) return null;
@@ -17554,6 +17615,15 @@ function spanRecordToRow(span) {
17554
17615
  startedAt: toIsoOrDate(span.startedAt),
17555
17616
  endedAt: toIsoOrDate(endedAt),
17556
17617
  timeToFirstChunkMs: span.timeToFirstChunkMs ?? null,
17618
+ externalParentSpanId: span.externalParentSpanId ?? null,
17619
+ resumedFromSpanId: span.resumedFromSpanId ?? null,
17620
+ model: span.model ?? null,
17621
+ provider: span.provider ?? null,
17622
+ outcome: span.outcome ?? null,
17623
+ stopReason: span.stopReason ?? null,
17624
+ stopReasonContext: jsonField(span.stopReasonContext),
17625
+ timeToFirstTokenMs: span.timeToFirstTokenMs ?? null,
17626
+ errorCount: span.errorCount ?? null,
17557
17627
  tags: normalizeTags(span.tags),
17558
17628
  metadataSearch: buildMetadataSearch(metadata),
17559
17629
  metadataRaw: jsonField(metadata),
@@ -17583,6 +17653,7 @@ function rowToSpanRecord(row) {
17583
17653
  const startedAt = toDate(row.startedAt);
17584
17654
  const endedAt = spanRowEndedAt(row, startedAt);
17585
17655
  const error = parsedJson(row.error);
17656
+ const attributes = parsedJson(row.attributes);
17586
17657
  const { executionSource, ...ctx } = rowToCommonContext(row);
17587
17658
  return {
17588
17659
  ...ctx,
@@ -17595,10 +17666,19 @@ function rowToSpanRecord(row) {
17595
17666
  isEvent: Boolean(row.isEvent),
17596
17667
  startedAt,
17597
17668
  endedAt,
17669
+ externalParentSpanId: nullableString(row.externalParentSpanId),
17670
+ resumedFromSpanId: nullableString(row.resumedFromSpanId),
17671
+ model: nullableString(row.model) ?? getStringAttribute(attributes, "model"),
17672
+ provider: nullableString(row.provider) ?? getStringAttribute(attributes, "provider"),
17673
+ outcome: nullableString(row.outcome),
17674
+ stopReason: nullableString(row.stopReason),
17675
+ stopReasonContext: parsedJson(row.stopReasonContext) ?? null,
17676
+ timeToFirstTokenMs: nullableNumber$1(row.timeToFirstTokenMs),
17677
+ errorCount: nullableNumber$1(row.errorCount),
17598
17678
  tags: normalizeTags(row.tags),
17599
17679
  metadata: parsedJson(row.metadataRaw) ?? void 0,
17600
17680
  scope: parsedJson(row.scope) ?? void 0,
17601
- attributes: parsedJson(row.attributes) ?? void 0,
17681
+ attributes: attributes ?? void 0,
17602
17682
  links: parsedJson(row.links) ?? void 0,
17603
17683
  input: parsedJson(row.input) ?? void 0,
17604
17684
  output: parsedJson(row.output) ?? void 0,