@mastra/spanner 1.5.0-alpha.0 → 1.5.0-alpha.1

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 { Spanner } from "@google-cloud/spanner";
2
2
  import { ErrorCategory, ErrorDomain, MastraError } from "@mastra/core/error";
3
- import { AGENTS_SCHEMA, AGENT_VERSIONS_SCHEMA, AgentsStorage, BackgroundTasksStorage, BlobStore, ChannelsStorage, DatasetsStorage, ExperimentsStorage, FavoritesStorage, MCPClientsStorage, MCPServersStorage, MCP_CLIENTS_SCHEMA, MCP_CLIENT_VERSIONS_SCHEMA, MCP_SERVERS_SCHEMA, MCP_SERVER_VERSIONS_SCHEMA, METRIC_DISTINCT_COLUMNS, MastraCompositeStore, MemoryStorage, ObservabilityStorage, PROMPT_BLOCKS_SCHEMA, PROMPT_BLOCK_VERSIONS_SCHEMA, PromptBlocksStorage, SCORER_DEFINITIONS_SCHEMA, SCORER_DEFINITION_VERSIONS_SCHEMA, SKILLS_SCHEMA, SKILL_BLOBS_SCHEMA, SKILL_VERSIONS_SCHEMA, 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_MCP_CLIENTS, TABLE_MCP_CLIENT_VERSIONS, TABLE_MCP_SERVERS, TABLE_MCP_SERVER_VERSIONS, TABLE_MESSAGES, 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_WORKFLOW_SNAPSHOT, TABLE_WORKSPACES, TABLE_WORKSPACE_VERSIONS, TraceStatus, WORKSPACES_SCHEMA, WORKSPACE_VERSIONS_SCHEMA, WorkflowsStorage, WorkspacesStorage, calculatePagination, createStorageErrorId, getDefaultValue, hasErrorCode, listMetricsArgsSchema, listTracesArgsSchema, normalizePerPage, normalizeScheduleTarget, toTraceSpans, transformScoreRow, validateStorageMetadataFilter } from "@mastra/core/storage";
3
+ import { AGENTS_SCHEMA, AGENT_VERSIONS_SCHEMA, AgentsStorage, BackgroundTasksStorage, BlobStore, ChannelsStorage, DatasetsStorage, ExperimentsStorage, FavoritesStorage, MCPClientsStorage, MCPServersStorage, MCP_CLIENTS_SCHEMA, MCP_CLIENT_VERSIONS_SCHEMA, MCP_SERVERS_SCHEMA, MCP_SERVER_VERSIONS_SCHEMA, METRIC_DISTINCT_COLUMNS, MastraCompositeStore, MemoryStorage, ObservabilityStorage, PROMPT_BLOCKS_SCHEMA, PROMPT_BLOCK_VERSIONS_SCHEMA, PromptBlocksStorage, SCORER_DEFINITIONS_SCHEMA, SCORER_DEFINITION_VERSIONS_SCHEMA, SKILLS_SCHEMA, SKILL_BLOBS_SCHEMA, SKILL_VERSIONS_SCHEMA, 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_MCP_CLIENTS, TABLE_MCP_CLIENT_VERSIONS, TABLE_MCP_SERVERS, TABLE_MCP_SERVER_VERSIONS, TABLE_MESSAGES, 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_WORKFLOW_DEFINITIONS, TABLE_WORKFLOW_SNAPSHOT, TABLE_WORKSPACES, TABLE_WORKSPACE_VERSIONS, TraceStatus, WORKFLOW_DEFINITIONS_SCHEMA, WORKSPACES_SCHEMA, WORKSPACE_VERSIONS_SCHEMA, WorkflowDefinitionsStorage, WorkflowsStorage, WorkspacesStorage, calculatePagination, createStorageErrorId, getDefaultValue, hasErrorCode, listMetricsArgsSchema, listTracesArgsSchema, normalizePerPage, normalizeScheduleTarget, toTraceSpans, transformScoreRow, validateStorageMetadataFilter } from "@mastra/core/storage";
4
4
  import { MastraBase } from "@mastra/core/base";
5
5
  import { parseSqlIdentifier } from "@mastra/core/utils";
6
6
  import { randomUUID } from "crypto";
@@ -11500,6 +11500,169 @@ var SkillsSpanner = class SkillsSpanner extends SkillsStorage {
11500
11500
  }
11501
11501
  };
11502
11502
  //#endregion
11503
+ //#region src/storage/domains/workflow-definitions/index.ts
11504
+ function rowToDefinition(row) {
11505
+ const parsed = transformFromSpannerRow({
11506
+ tableName: TABLE_WORKFLOW_DEFINITIONS,
11507
+ row
11508
+ });
11509
+ if (parsed.inputSchema == null || parsed.outputSchema == null || parsed.graph == null) throw new Error(`Workflow definition row "${String(parsed.id)}" is missing required JSON columns.`);
11510
+ const def = {
11511
+ id: String(parsed.id),
11512
+ inputSchema: parsed.inputSchema,
11513
+ outputSchema: parsed.outputSchema,
11514
+ graph: parsed.graph,
11515
+ status: parsed.status,
11516
+ source: parsed.source,
11517
+ createdAt: parsed.createdAt instanceof Date ? parsed.createdAt : new Date(parsed.createdAt),
11518
+ updatedAt: parsed.updatedAt instanceof Date ? parsed.updatedAt : new Date(parsed.updatedAt)
11519
+ };
11520
+ if (parsed.description != null) def.description = parsed.description;
11521
+ if (parsed.metadata != null) def.metadata = parsed.metadata;
11522
+ if (parsed.stateSchema != null) def.stateSchema = parsed.stateSchema;
11523
+ if (parsed.requestContextSchema != null) def.requestContextSchema = parsed.requestContextSchema;
11524
+ if (parsed.authorId != null) def.authorId = parsed.authorId;
11525
+ return def;
11526
+ }
11527
+ var WorkflowDefinitionsSpanner = class WorkflowDefinitionsSpanner extends WorkflowDefinitionsStorage {
11528
+ database;
11529
+ db;
11530
+ skipDefaultIndexes;
11531
+ indexes;
11532
+ static MANAGED_TABLES = [TABLE_WORKFLOW_DEFINITIONS];
11533
+ constructor(config) {
11534
+ super();
11535
+ const { database, indexes, skipDefaultIndexes, initMode } = resolveSpannerConfig(config);
11536
+ this.database = database;
11537
+ this.db = new SpannerDB({
11538
+ database,
11539
+ skipDefaultIndexes,
11540
+ initMode
11541
+ });
11542
+ this.skipDefaultIndexes = skipDefaultIndexes;
11543
+ this.indexes = indexes?.filter((idx) => WorkflowDefinitionsSpanner.MANAGED_TABLES.includes(idx.table));
11544
+ }
11545
+ async init() {
11546
+ await this.db.createTable({
11547
+ tableName: TABLE_WORKFLOW_DEFINITIONS,
11548
+ schema: WORKFLOW_DEFINITIONS_SCHEMA
11549
+ });
11550
+ await this.createDefaultIndexes();
11551
+ await this.createCustomIndexes();
11552
+ }
11553
+ getDefaultIndexDefinitions() {
11554
+ return [{
11555
+ name: "mastra_workflow_definitions_status_idx",
11556
+ table: TABLE_WORKFLOW_DEFINITIONS,
11557
+ columns: ["status"]
11558
+ }];
11559
+ }
11560
+ async createDefaultIndexes() {
11561
+ if (this.skipDefaultIndexes) return;
11562
+ await this.db.createIndexes(this.getDefaultIndexDefinitions());
11563
+ }
11564
+ async createCustomIndexes() {
11565
+ if (!this.indexes || this.indexes.length === 0) return;
11566
+ await this.db.createIndexes(this.indexes);
11567
+ }
11568
+ async dangerouslyClearAll() {
11569
+ await this.db.clearTable({ tableName: TABLE_WORKFLOW_DEFINITIONS });
11570
+ }
11571
+ async upsert(input) {
11572
+ const now = /* @__PURE__ */ new Date();
11573
+ if (!await this.get(input.id)) {
11574
+ if (!("inputSchema" in input) || input.inputSchema === void 0) throw new Error(`Cannot create workflow definition "${input.id}": inputSchema is required.`);
11575
+ if (!("outputSchema" in input) || input.outputSchema === void 0) throw new Error(`Cannot create workflow definition "${input.id}": outputSchema is required.`);
11576
+ if (!("graph" in input) || input.graph === void 0) throw new Error(`Cannot create workflow definition "${input.id}": graph is required.`);
11577
+ const record = {
11578
+ id: input.id,
11579
+ description: input.description ?? null,
11580
+ metadata: input.metadata ?? null,
11581
+ inputSchema: input.inputSchema,
11582
+ outputSchema: input.outputSchema,
11583
+ stateSchema: input.stateSchema ?? null,
11584
+ requestContextSchema: input.requestContextSchema ?? null,
11585
+ graph: input.graph,
11586
+ status: "active",
11587
+ source: "storage",
11588
+ authorId: "authorId" in input ? input.authorId ?? null : null,
11589
+ createdAt: now,
11590
+ updatedAt: now
11591
+ };
11592
+ try {
11593
+ await this.db.insert({
11594
+ tableName: TABLE_WORKFLOW_DEFINITIONS,
11595
+ record
11596
+ });
11597
+ } catch (error) {
11598
+ if (!await this.get(input.id)) throw error;
11599
+ return this.applyUpdate(input, now);
11600
+ }
11601
+ const created = await this.get(input.id);
11602
+ if (!created) throw new Error(`Failed to persist workflow definition "${input.id}".`);
11603
+ return created;
11604
+ }
11605
+ return this.applyUpdate(input, now);
11606
+ }
11607
+ async applyUpdate(input, now) {
11608
+ const data = { updatedAt: now };
11609
+ if ("description" in input && input.description !== void 0) data.description = input.description;
11610
+ if ("metadata" in input && input.metadata !== void 0) data.metadata = input.metadata;
11611
+ if ("inputSchema" in input && input.inputSchema !== void 0) data.inputSchema = input.inputSchema;
11612
+ if ("outputSchema" in input && input.outputSchema !== void 0) data.outputSchema = input.outputSchema;
11613
+ if ("stateSchema" in input && input.stateSchema !== void 0) data.stateSchema = input.stateSchema;
11614
+ if ("requestContextSchema" in input && input.requestContextSchema !== void 0) data.requestContextSchema = input.requestContextSchema;
11615
+ if ("graph" in input && input.graph !== void 0) data.graph = input.graph;
11616
+ if ("status" in input && input.status !== void 0) data.status = input.status;
11617
+ if ("authorId" in input && input.authorId !== void 0) data.authorId = input.authorId;
11618
+ await this.db.update({
11619
+ tableName: TABLE_WORKFLOW_DEFINITIONS,
11620
+ keys: { id: input.id },
11621
+ data
11622
+ });
11623
+ const updated = await this.get(input.id);
11624
+ if (!updated) throw new Error(`Failed to update workflow definition "${input.id}".`);
11625
+ return updated;
11626
+ }
11627
+ async get(id) {
11628
+ const row = await this.db.load({
11629
+ tableName: TABLE_WORKFLOW_DEFINITIONS,
11630
+ keys: { id }
11631
+ });
11632
+ return row ? rowToDefinition(row) : null;
11633
+ }
11634
+ async list(args) {
11635
+ const params = {};
11636
+ const conditions = [];
11637
+ if (args?.status) {
11638
+ params.status = args.status;
11639
+ conditions.push(`${quoteIdent("status", "column name")} = @status`);
11640
+ }
11641
+ if (args?.authorId !== void 0) {
11642
+ params.authorId = args.authorId;
11643
+ conditions.push(`${quoteIdent("authorId", "column name")} = @authorId`);
11644
+ }
11645
+ const where = conditions.length ? `WHERE ${conditions.join(" AND ")}` : "";
11646
+ const sql = `SELECT * FROM ${quoteIdent(TABLE_WORKFLOW_DEFINITIONS, "table name")} ${where} ORDER BY ${quoteIdent("updatedAt", "column name")} DESC`;
11647
+ const [rows] = await this.database.run({
11648
+ sql,
11649
+ params,
11650
+ json: true
11651
+ });
11652
+ const definitions = rows.map(rowToDefinition);
11653
+ return {
11654
+ definitions,
11655
+ total: definitions.length
11656
+ };
11657
+ }
11658
+ async delete(id) {
11659
+ await this.db.runDml({
11660
+ sql: `DELETE FROM ${quoteIdent(TABLE_WORKFLOW_DEFINITIONS, "table name")} WHERE id = @id`,
11661
+ params: { id }
11662
+ });
11663
+ }
11664
+ };
11665
+ //#endregion
11503
11666
  //#region src/storage/domains/workflows/index.ts
11504
11667
  /**
11505
11668
  * Spanner-backed storage for workflow run snapshots, including persistence,
@@ -12668,7 +12831,8 @@ const SPANNER_DOMAIN_KEYS = [
12668
12831
  "datasets",
12669
12832
  "experiments",
12670
12833
  "favorites",
12671
- "workspaces"
12834
+ "workspaces",
12835
+ "workflowDefinitions"
12672
12836
  ];
12673
12837
  const isPreConfiguredDatabase = (config) => "database" in config && !!config.database;
12674
12838
  /**
@@ -12756,7 +12920,8 @@ var SpannerStore = class extends MastraCompositeStore {
12756
12920
  ...wants("datasets") && { datasets: new DatasetsSpanner(domainConfig) },
12757
12921
  ...wants("experiments") && { experiments: new ExperimentsSpanner(domainConfig) },
12758
12922
  ...wants("favorites") && { favorites: new FavoritesSpanner(domainConfig) },
12759
- ...wants("workspaces") && { workspaces: new WorkspacesSpanner(domainConfig) }
12923
+ ...wants("workspaces") && { workspaces: new WorkspacesSpanner(domainConfig) },
12924
+ ...wants("workflowDefinitions") && { workflowDefinitions: new WorkflowDefinitionsSpanner(domainConfig) }
12760
12925
  };
12761
12926
  } catch (e) {
12762
12927
  throw new MastraError({
@@ -12812,7 +12977,8 @@ var SpannerStore = class extends MastraCompositeStore {
12812
12977
  "datasets",
12813
12978
  "experiments",
12814
12979
  "workspaces",
12815
- "favorites"
12980
+ "favorites",
12981
+ "workflowDefinitions"
12816
12982
  ]) {
12817
12983
  const store = this.stores?.[key];
12818
12984
  if (store) await store.init();
@@ -12844,6 +13010,6 @@ var SpannerStore = class extends MastraCompositeStore {
12844
13010
  }
12845
13011
  };
12846
13012
  //#endregion
12847
- export { AgentsSpanner, BackgroundTasksSpanner, BlobsSpanner, ChannelsSpanner, DatasetsSpanner, ExperimentsSpanner, FavoritesSpanner, MCPClientsSpanner, MCPServersSpanner, MemorySpanner, ObservabilitySpanner, PromptBlocksSpanner, SPANNER_DOMAIN_KEYS, SchedulesSpanner, ScorerDefinitionsSpanner, ScoresSpanner, SkillsSpanner, SpannerStore, WorkflowsSpanner, WorkspacesSpanner };
13013
+ export { AgentsSpanner, BackgroundTasksSpanner, BlobsSpanner, ChannelsSpanner, DatasetsSpanner, ExperimentsSpanner, FavoritesSpanner, MCPClientsSpanner, MCPServersSpanner, MemorySpanner, ObservabilitySpanner, PromptBlocksSpanner, SPANNER_DOMAIN_KEYS, SchedulesSpanner, ScorerDefinitionsSpanner, ScoresSpanner, SkillsSpanner, SpannerStore, WorkflowDefinitionsSpanner, WorkflowsSpanner, WorkspacesSpanner };
12848
13014
 
12849
13015
  //# sourceMappingURL=index.js.map