@mastra/pg 1.19.0-alpha.1 → 1.19.0-alpha.2
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/CHANGELOG.md +44 -0
- package/dist/docs/SKILL.md +1 -1
- package/dist/docs/assets/SOURCE_MAP.json +1 -1
- package/dist/docs/references/docs-deployment-workers.md +14 -14
- package/dist/index.cjs +184 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +185 -2
- package/dist/index.js.map +1 -1
- package/dist/storage/domains/workflow-definitions/index.d.ts +20 -0
- package/dist/storage/domains/workflow-definitions/index.d.ts.map +1 -0
- package/dist/storage/index.d.ts +2 -1
- package/dist/storage/index.d.ts.map +1 -1
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ErrorCategory, ErrorDomain, MastraError } from "@mastra/core/error";
|
|
2
|
-
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, MCPClientsStorage, MCPServersStorage, METRIC_DISTINCT_COLUMNS, MastraCompositeStore, MemoryStorage, NotificationsStorage, OBSERVATIONAL_MEMORY_TABLE_SCHEMA, ObservabilityStorage, PromptBlocksStorage, 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_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_TOOL_PROVIDER_CONNECTIONS, TABLE_WORKFLOW_SNAPSHOT, TABLE_WORKSPACES, TABLE_WORKSPACE_VERSIONS, ToolProviderConnectionsStorage, TraceStatus, UniqueViolationError, WorkflowsStorage, WorkspacesStorage, calculatePagination, createStorageErrorId, createVectorErrorId, ensureDate, getDefaultValue, getSqlType, hasErrorCode, listBranchesArgsSchema, listFeedbackArgsSchema, listLogsArgsSchema, listMetricsArgsSchema, listScoresArgsSchema, listTracesArgsSchema, mergeWorkflowStepResult, normalizePerPage, normalizeScheduleTarget, parseDuration, safelyParseJSON, storageMessageMatchesMetadataFilter, toTraceSpans, transformScoreRow, validateStorageMetadataFilter } from "@mastra/core/storage";
|
|
2
|
+
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, MCPClientsStorage, MCPServersStorage, METRIC_DISTINCT_COLUMNS, MastraCompositeStore, MemoryStorage, NotificationsStorage, OBSERVATIONAL_MEMORY_TABLE_SCHEMA, ObservabilityStorage, PromptBlocksStorage, 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_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_TOOL_PROVIDER_CONNECTIONS, TABLE_WORKFLOW_DEFINITIONS, TABLE_WORKFLOW_SNAPSHOT, TABLE_WORKSPACES, TABLE_WORKSPACE_VERSIONS, ToolProviderConnectionsStorage, TraceStatus, UniqueViolationError, WorkflowDefinitionsStorage, WorkflowsStorage, WorkspacesStorage, calculatePagination, createStorageErrorId, createVectorErrorId, ensureDate, getDefaultValue, getSqlType, hasErrorCode, listBranchesArgsSchema, listFeedbackArgsSchema, listLogsArgsSchema, listMetricsArgsSchema, listScoresArgsSchema, listTracesArgsSchema, mergeWorkflowStepResult, normalizePerPage, normalizeScheduleTarget, parseDuration, safelyParseJSON, storageMessageMatchesMetadataFilter, toTraceSpans, transformScoreRow, validateStorageMetadataFilter } from "@mastra/core/storage";
|
|
3
3
|
import { parseFieldKey, parseSqlIdentifier } from "@mastra/core/utils";
|
|
4
4
|
import { MastraVector, validateTopK, validateUpsertInput } from "@mastra/core/vector";
|
|
5
5
|
import { Mutex } from "async-mutex";
|
|
@@ -18748,6 +18748,187 @@ var ToolProviderConnectionsPG = class ToolProviderConnectionsPG extends ToolProv
|
|
|
18748
18748
|
}
|
|
18749
18749
|
};
|
|
18750
18750
|
//#endregion
|
|
18751
|
+
//#region src/storage/domains/workflow-definitions/index.ts
|
|
18752
|
+
function rowToDefinition(row) {
|
|
18753
|
+
const inputSchema = parseJsonResilient(row.inputSchema);
|
|
18754
|
+
const outputSchema = parseJsonResilient(row.outputSchema);
|
|
18755
|
+
const graph = parseJsonResilient(row.graph);
|
|
18756
|
+
if (inputSchema === void 0 || outputSchema === void 0 || graph === void 0) throw new Error(`Workflow definition row "${String(row.id)}" is missing required JSON columns.`);
|
|
18757
|
+
const def = {
|
|
18758
|
+
id: String(row.id),
|
|
18759
|
+
inputSchema,
|
|
18760
|
+
outputSchema,
|
|
18761
|
+
graph,
|
|
18762
|
+
status: String(row.status),
|
|
18763
|
+
source: String(row.source),
|
|
18764
|
+
createdAt: new Date(row.createdAtZ ?? row.createdAt),
|
|
18765
|
+
updatedAt: new Date(row.updatedAtZ ?? row.updatedAt)
|
|
18766
|
+
};
|
|
18767
|
+
if (row.description != null) def.description = String(row.description);
|
|
18768
|
+
const metadata = parseJsonResilient(row.metadata);
|
|
18769
|
+
if (metadata !== void 0 && metadata !== null) def.metadata = metadata;
|
|
18770
|
+
const stateSchema = parseJsonResilient(row.stateSchema);
|
|
18771
|
+
if (stateSchema !== void 0 && stateSchema !== null) def.stateSchema = stateSchema;
|
|
18772
|
+
const requestContextSchema = parseJsonResilient(row.requestContextSchema);
|
|
18773
|
+
if (requestContextSchema !== void 0 && requestContextSchema !== null) def.requestContextSchema = requestContextSchema;
|
|
18774
|
+
if (row.authorId != null) def.authorId = String(row.authorId);
|
|
18775
|
+
return def;
|
|
18776
|
+
}
|
|
18777
|
+
var WorkflowDefinitionsPG = class WorkflowDefinitionsPG extends WorkflowDefinitionsStorage {
|
|
18778
|
+
#db;
|
|
18779
|
+
#schema;
|
|
18780
|
+
#skipDefaultIndexes;
|
|
18781
|
+
#indexes;
|
|
18782
|
+
static MANAGED_TABLES = [TABLE_WORKFLOW_DEFINITIONS];
|
|
18783
|
+
constructor(config) {
|
|
18784
|
+
super();
|
|
18785
|
+
const { client, schemaName, skipDefaultIndexes, indexes } = resolvePgConfig(config);
|
|
18786
|
+
this.#db = new PgDB({
|
|
18787
|
+
client,
|
|
18788
|
+
schemaName,
|
|
18789
|
+
skipDefaultIndexes
|
|
18790
|
+
});
|
|
18791
|
+
this.#schema = schemaName || "public";
|
|
18792
|
+
this.#skipDefaultIndexes = skipDefaultIndexes;
|
|
18793
|
+
this.#indexes = indexes?.filter((idx) => WorkflowDefinitionsPG.MANAGED_TABLES.includes(idx.table));
|
|
18794
|
+
}
|
|
18795
|
+
static getExportDDL(schemaName) {
|
|
18796
|
+
return [generateTableSQL({
|
|
18797
|
+
tableName: TABLE_WORKFLOW_DEFINITIONS,
|
|
18798
|
+
schema: TABLE_SCHEMAS[TABLE_WORKFLOW_DEFINITIONS],
|
|
18799
|
+
schemaName,
|
|
18800
|
+
includeAllConstraints: true
|
|
18801
|
+
})];
|
|
18802
|
+
}
|
|
18803
|
+
getDefaultIndexDefinitions() {
|
|
18804
|
+
return [{
|
|
18805
|
+
name: `${this.#schema !== "public" ? `${this.#schema}_` : ""}idx_workflow_definitions_status`,
|
|
18806
|
+
table: TABLE_WORKFLOW_DEFINITIONS,
|
|
18807
|
+
columns: ["status"]
|
|
18808
|
+
}];
|
|
18809
|
+
}
|
|
18810
|
+
async createDefaultIndexes() {
|
|
18811
|
+
if (this.#skipDefaultIndexes) return;
|
|
18812
|
+
for (const indexDef of this.getDefaultIndexDefinitions()) try {
|
|
18813
|
+
await this.#db.createIndex(indexDef);
|
|
18814
|
+
} catch (error) {
|
|
18815
|
+
this.logger?.warn?.(`Failed to create index ${indexDef.name}:`, error);
|
|
18816
|
+
}
|
|
18817
|
+
}
|
|
18818
|
+
async createCustomIndexes() {
|
|
18819
|
+
if (!this.#indexes || this.#indexes.length === 0) return;
|
|
18820
|
+
for (const indexDef of this.#indexes) try {
|
|
18821
|
+
await this.#db.createIndex(indexDef);
|
|
18822
|
+
} catch (error) {
|
|
18823
|
+
this.logger?.warn?.(`Failed to create custom index ${indexDef.name}:`, error);
|
|
18824
|
+
}
|
|
18825
|
+
}
|
|
18826
|
+
async init() {
|
|
18827
|
+
await this.#db.createTable({
|
|
18828
|
+
tableName: TABLE_WORKFLOW_DEFINITIONS,
|
|
18829
|
+
schema: TABLE_SCHEMAS[TABLE_WORKFLOW_DEFINITIONS]
|
|
18830
|
+
});
|
|
18831
|
+
await this.createDefaultIndexes();
|
|
18832
|
+
await this.createCustomIndexes();
|
|
18833
|
+
}
|
|
18834
|
+
async dangerouslyClearAll() {
|
|
18835
|
+
await this.#db.clearTable({ tableName: TABLE_WORKFLOW_DEFINITIONS });
|
|
18836
|
+
}
|
|
18837
|
+
async upsert(input) {
|
|
18838
|
+
const now = /* @__PURE__ */ new Date();
|
|
18839
|
+
if (!await this.get(input.id)) {
|
|
18840
|
+
if (!("inputSchema" in input) || !input.inputSchema) throw new Error(`Cannot create workflow definition "${input.id}": inputSchema is required.`);
|
|
18841
|
+
if (!("outputSchema" in input) || !input.outputSchema) throw new Error(`Cannot create workflow definition "${input.id}": outputSchema is required.`);
|
|
18842
|
+
if (!("graph" in input) || !input.graph) throw new Error(`Cannot create workflow definition "${input.id}": graph is required.`);
|
|
18843
|
+
const record = {
|
|
18844
|
+
id: input.id,
|
|
18845
|
+
description: input.description ?? null,
|
|
18846
|
+
metadata: input.metadata ?? null,
|
|
18847
|
+
inputSchema: input.inputSchema,
|
|
18848
|
+
outputSchema: input.outputSchema,
|
|
18849
|
+
stateSchema: input.stateSchema ?? null,
|
|
18850
|
+
requestContextSchema: input.requestContextSchema ?? null,
|
|
18851
|
+
graph: input.graph,
|
|
18852
|
+
status: "active",
|
|
18853
|
+
source: "storage",
|
|
18854
|
+
authorId: "authorId" in input ? input.authorId ?? null : null,
|
|
18855
|
+
createdAt: now,
|
|
18856
|
+
updatedAt: now
|
|
18857
|
+
};
|
|
18858
|
+
try {
|
|
18859
|
+
await this.#db.insert({
|
|
18860
|
+
tableName: TABLE_WORKFLOW_DEFINITIONS,
|
|
18861
|
+
record
|
|
18862
|
+
});
|
|
18863
|
+
} catch (error) {
|
|
18864
|
+
if (!await this.get(input.id)) throw error;
|
|
18865
|
+
return this.applyUpdate(input, now);
|
|
18866
|
+
}
|
|
18867
|
+
const created = await this.get(input.id);
|
|
18868
|
+
if (!created) throw new Error(`Failed to persist workflow definition "${input.id}".`);
|
|
18869
|
+
return created;
|
|
18870
|
+
}
|
|
18871
|
+
return this.applyUpdate(input, now);
|
|
18872
|
+
}
|
|
18873
|
+
async applyUpdate(input, now) {
|
|
18874
|
+
const data = { updatedAt: now };
|
|
18875
|
+
if ("description" in input && input.description !== void 0) data.description = input.description;
|
|
18876
|
+
if ("metadata" in input && input.metadata !== void 0) data.metadata = input.metadata;
|
|
18877
|
+
if ("inputSchema" in input && input.inputSchema !== void 0) data.inputSchema = input.inputSchema;
|
|
18878
|
+
if ("outputSchema" in input && input.outputSchema !== void 0) data.outputSchema = input.outputSchema;
|
|
18879
|
+
if ("stateSchema" in input && input.stateSchema !== void 0) data.stateSchema = input.stateSchema;
|
|
18880
|
+
if ("requestContextSchema" in input && input.requestContextSchema !== void 0) data.requestContextSchema = input.requestContextSchema;
|
|
18881
|
+
if ("graph" in input && input.graph !== void 0) data.graph = input.graph;
|
|
18882
|
+
if ("status" in input && input.status !== void 0) data.status = input.status;
|
|
18883
|
+
if ("authorId" in input && input.authorId !== void 0) data.authorId = input.authorId;
|
|
18884
|
+
await this.#db.update({
|
|
18885
|
+
tableName: TABLE_WORKFLOW_DEFINITIONS,
|
|
18886
|
+
keys: { id: input.id },
|
|
18887
|
+
data
|
|
18888
|
+
});
|
|
18889
|
+
const updated = await this.get(input.id);
|
|
18890
|
+
if (!updated) throw new Error(`Failed to update workflow definition "${input.id}".`);
|
|
18891
|
+
return updated;
|
|
18892
|
+
}
|
|
18893
|
+
async get(id) {
|
|
18894
|
+
const tableName = getTableName$5({
|
|
18895
|
+
indexName: TABLE_WORKFLOW_DEFINITIONS,
|
|
18896
|
+
schemaName: getSchemaName$5(this.#schema)
|
|
18897
|
+
});
|
|
18898
|
+
const row = await this.#db.client.oneOrNone(`SELECT * FROM ${tableName} WHERE "id" = $1`, [id]);
|
|
18899
|
+
return row ? rowToDefinition(row) : null;
|
|
18900
|
+
}
|
|
18901
|
+
async list(args) {
|
|
18902
|
+
const tableName = getTableName$5({
|
|
18903
|
+
indexName: TABLE_WORKFLOW_DEFINITIONS,
|
|
18904
|
+
schemaName: getSchemaName$5(this.#schema)
|
|
18905
|
+
});
|
|
18906
|
+
const conditions = [];
|
|
18907
|
+
const params = [];
|
|
18908
|
+
if (args?.status) {
|
|
18909
|
+
params.push(args.status);
|
|
18910
|
+
conditions.push(`"status" = $${params.length}`);
|
|
18911
|
+
}
|
|
18912
|
+
if (args?.authorId !== void 0) {
|
|
18913
|
+
params.push(args.authorId);
|
|
18914
|
+
conditions.push(`"authorId" = $${params.length}`);
|
|
18915
|
+
}
|
|
18916
|
+
const where = conditions.length > 0 ? `WHERE ${conditions.join(" AND ")}` : "";
|
|
18917
|
+
const definitions = (await this.#db.client.manyOrNone(`SELECT * FROM ${tableName} ${where} ORDER BY "updatedAt" DESC`, params)).map((row) => rowToDefinition(row));
|
|
18918
|
+
return {
|
|
18919
|
+
definitions,
|
|
18920
|
+
total: definitions.length
|
|
18921
|
+
};
|
|
18922
|
+
}
|
|
18923
|
+
async delete(id) {
|
|
18924
|
+
const tableName = getTableName$5({
|
|
18925
|
+
indexName: TABLE_WORKFLOW_DEFINITIONS,
|
|
18926
|
+
schemaName: getSchemaName$5(this.#schema)
|
|
18927
|
+
});
|
|
18928
|
+
await this.#db.client.none(`DELETE FROM ${tableName} WHERE "id" = $1`, [id]);
|
|
18929
|
+
}
|
|
18930
|
+
};
|
|
18931
|
+
//#endregion
|
|
18751
18932
|
//#region src/storage/domains/workflows/index.ts
|
|
18752
18933
|
function getSchemaName(schema) {
|
|
18753
18934
|
return schema ? `"${schema}"` : "\"public\"";
|
|
@@ -20240,6 +20421,7 @@ const ALL_DOMAINS = [
|
|
|
20240
20421
|
BlobsPG,
|
|
20241
20422
|
ToolProviderConnectionsPG,
|
|
20242
20423
|
WorkflowsPG,
|
|
20424
|
+
WorkflowDefinitionsPG,
|
|
20243
20425
|
DatasetsPG,
|
|
20244
20426
|
ExperimentsPG,
|
|
20245
20427
|
BackgroundTasksPG,
|
|
@@ -20321,6 +20503,7 @@ var PostgresStore = class extends MastraCompositeStore {
|
|
|
20321
20503
|
this.stores = {
|
|
20322
20504
|
scores: new ScoresPG(domainConfig),
|
|
20323
20505
|
workflows: new WorkflowsPG(domainConfig),
|
|
20506
|
+
workflowDefinitions: new WorkflowDefinitionsPG(domainConfig),
|
|
20324
20507
|
memory: new MemoryPG(domainConfig),
|
|
20325
20508
|
notifications: new NotificationsPG(domainConfig),
|
|
20326
20509
|
observability: new ObservabilityPG(domainConfig),
|
|
@@ -20645,6 +20828,6 @@ Example Complex Query:
|
|
|
20645
20828
|
]
|
|
20646
20829
|
}`;
|
|
20647
20830
|
//#endregion
|
|
20648
|
-
export { AgentsPG, BackgroundTasksPG, BlobsPG, ChannelsPG, DatasetsPG, ExperimentsPG, FavoritesPG, MCPClientsPG, MCPServersPG, MemoryPG, NotificationsPG, ObservabilityPG, ObservabilityStoragePostgresVNext, PGVECTOR_PROMPT, PgFactoryStorage, PgVector, PoolAdapter, PostgresStore, PostgresStoreVNext, PromptBlocksPG, SchedulesPG, ScorerDefinitionsPG, ScoresPG, SkillsPG, ToolProviderConnectionsPG, WorkflowsPG, WorkspacesPG, exportSchemas };
|
|
20831
|
+
export { AgentsPG, BackgroundTasksPG, BlobsPG, ChannelsPG, DatasetsPG, ExperimentsPG, FavoritesPG, MCPClientsPG, MCPServersPG, MemoryPG, NotificationsPG, ObservabilityPG, ObservabilityStoragePostgresVNext, PGVECTOR_PROMPT, PgFactoryStorage, PgVector, PoolAdapter, PostgresStore, PostgresStoreVNext, PromptBlocksPG, SchedulesPG, ScorerDefinitionsPG, ScoresPG, SkillsPG, ToolProviderConnectionsPG, WorkflowDefinitionsPG, WorkflowsPG, WorkspacesPG, exportSchemas };
|
|
20649
20832
|
|
|
20650
20833
|
//# sourceMappingURL=index.js.map
|