@mastra/libsql 1.12.0-alpha.0 → 1.12.1-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.
- package/CHANGELOG.md +72 -0
- package/dist/docs/SKILL.md +1 -1
- package/dist/docs/assets/SOURCE_MAP.json +1 -1
- package/dist/docs/references/docs-agents-agent-approval.md +1 -1
- package/dist/docs/references/docs-agents-networks.md +1 -1
- package/dist/docs/references/docs-memory-memory-processors.md +6 -6
- package/dist/docs/references/docs-memory-multi-user-threads.md +2 -2
- package/dist/docs/references/docs-memory-semantic-recall.md +1 -1
- package/dist/docs/references/docs-memory-storage.md +2 -1
- package/dist/docs/references/docs-memory-working-memory.md +28 -1
- package/dist/docs/references/docs-rag-retrieval.md +12 -12
- package/dist/docs/references/reference-memory-memory-class.md +3 -3
- package/dist/docs/references/reference-storage-libsql.md +6 -0
- package/dist/docs/references/reference-vectors-libsql.md +1 -1
- package/dist/index.cjs +297 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +298 -7
- package/dist/index.js.map +1 -1
- package/dist/storage/domains/memory/index.d.ts.map +1 -1
- package/dist/storage/domains/notifications/index.d.ts +19 -0
- package/dist/storage/domains/notifications/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 +5 -5
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createClient } from '@libsql/client';
|
|
2
2
|
import { MastraError, ErrorCategory, ErrorDomain } from '@mastra/core/error';
|
|
3
|
-
import { createVectorErrorId, AgentsStorage, AGENTS_SCHEMA, TABLE_AGENTS, AGENT_VERSIONS_SCHEMA, TABLE_AGENT_VERSIONS, createStorageErrorId, normalizePerPage, calculatePagination, BackgroundTasksStorage, TABLE_SCHEMAS, TABLE_BACKGROUND_TASKS, BlobStore, TABLE_SKILL_BLOBS, SKILL_BLOBS_SCHEMA, ChannelsStorage, TABLE_CHANNEL_INSTALLATIONS, TABLE_CHANNEL_CONFIG, DatasetsStorage, DATASETS_SCHEMA, TABLE_DATASETS, DATASET_ITEMS_SCHEMA, TABLE_DATASET_ITEMS, DATASET_VERSIONS_SCHEMA, TABLE_DATASET_VERSIONS, ensureDate, safelyParseJSON, TABLE_EXPERIMENT_RESULTS, TABLE_EXPERIMENTS, ExperimentsStorage, EXPERIMENTS_SCHEMA, EXPERIMENT_RESULTS_SCHEMA, FavoritesStorage, FAVORITES_SCHEMA, TABLE_FAVORITES, TABLE_SKILLS, MCPClientsStorage, MCP_CLIENTS_SCHEMA, TABLE_MCP_CLIENTS, MCP_CLIENT_VERSIONS_SCHEMA, TABLE_MCP_CLIENT_VERSIONS, MCPServersStorage, MCP_SERVERS_SCHEMA, TABLE_MCP_SERVERS, MCP_SERVER_VERSIONS_SCHEMA, TABLE_MCP_SERVER_VERSIONS, MemoryStorage, TABLE_THREADS, TABLE_MESSAGES, TABLE_RESOURCES, ObservabilityStorage, SPAN_SCHEMA, TABLE_SPANS, listTracesArgsSchema, toTraceSpans, PromptBlocksStorage, PROMPT_BLOCKS_SCHEMA, TABLE_PROMPT_BLOCKS, PROMPT_BLOCK_VERSIONS_SCHEMA, TABLE_PROMPT_BLOCK_VERSIONS, SchedulesStorage, TABLE_SCHEDULES, TABLE_SCHEDULE_TRIGGERS, ScorerDefinitionsStorage, SCORER_DEFINITIONS_SCHEMA, TABLE_SCORER_DEFINITIONS, SCORER_DEFINITION_VERSIONS_SCHEMA, TABLE_SCORER_DEFINITION_VERSIONS, ScoresStorage, SCORERS_SCHEMA, TABLE_SCORERS, transformScoreRow, SkillsStorage, SKILLS_SCHEMA, SKILL_VERSIONS_SCHEMA, TABLE_SKILL_VERSIONS, ToolProviderConnectionsStorage, TOOL_PROVIDER_CONNECTIONS_SCHEMA, TABLE_TOOL_PROVIDER_CONNECTIONS, WorkflowsStorage, TABLE_WORKFLOW_SNAPSHOT, WorkspacesStorage, WORKSPACES_SCHEMA, TABLE_WORKSPACES, WORKSPACE_VERSIONS_SCHEMA, TABLE_WORKSPACE_VERSIONS, MastraCompositeStore, getSqlType, TraceStatus } from '@mastra/core/storage';
|
|
3
|
+
import { createVectorErrorId, AgentsStorage, AGENTS_SCHEMA, TABLE_AGENTS, AGENT_VERSIONS_SCHEMA, TABLE_AGENT_VERSIONS, createStorageErrorId, normalizePerPage, calculatePagination, BackgroundTasksStorage, TABLE_SCHEMAS, TABLE_BACKGROUND_TASKS, BlobStore, TABLE_SKILL_BLOBS, SKILL_BLOBS_SCHEMA, ChannelsStorage, TABLE_CHANNEL_INSTALLATIONS, TABLE_CHANNEL_CONFIG, DatasetsStorage, DATASETS_SCHEMA, TABLE_DATASETS, DATASET_ITEMS_SCHEMA, TABLE_DATASET_ITEMS, DATASET_VERSIONS_SCHEMA, TABLE_DATASET_VERSIONS, ensureDate, safelyParseJSON, TABLE_EXPERIMENT_RESULTS, TABLE_EXPERIMENTS, ExperimentsStorage, EXPERIMENTS_SCHEMA, EXPERIMENT_RESULTS_SCHEMA, FavoritesStorage, FAVORITES_SCHEMA, TABLE_FAVORITES, TABLE_SKILLS, MCPClientsStorage, MCP_CLIENTS_SCHEMA, TABLE_MCP_CLIENTS, MCP_CLIENT_VERSIONS_SCHEMA, TABLE_MCP_CLIENT_VERSIONS, MCPServersStorage, MCP_SERVERS_SCHEMA, TABLE_MCP_SERVERS, MCP_SERVER_VERSIONS_SCHEMA, TABLE_MCP_SERVER_VERSIONS, MemoryStorage, TABLE_THREADS, TABLE_MESSAGES, TABLE_RESOURCES, NotificationsStorage, TABLE_NOTIFICATIONS, ObservabilityStorage, SPAN_SCHEMA, TABLE_SPANS, listTracesArgsSchema, toTraceSpans, PromptBlocksStorage, PROMPT_BLOCKS_SCHEMA, TABLE_PROMPT_BLOCKS, PROMPT_BLOCK_VERSIONS_SCHEMA, TABLE_PROMPT_BLOCK_VERSIONS, SchedulesStorage, TABLE_SCHEDULES, TABLE_SCHEDULE_TRIGGERS, ScorerDefinitionsStorage, SCORER_DEFINITIONS_SCHEMA, TABLE_SCORER_DEFINITIONS, SCORER_DEFINITION_VERSIONS_SCHEMA, TABLE_SCORER_DEFINITION_VERSIONS, ScoresStorage, SCORERS_SCHEMA, TABLE_SCORERS, transformScoreRow, SkillsStorage, SKILLS_SCHEMA, SKILL_VERSIONS_SCHEMA, TABLE_SKILL_VERSIONS, ToolProviderConnectionsStorage, TOOL_PROVIDER_CONNECTIONS_SCHEMA, TABLE_TOOL_PROVIDER_CONNECTIONS, WorkflowsStorage, TABLE_WORKFLOW_SNAPSHOT, WorkspacesStorage, WORKSPACES_SCHEMA, TABLE_WORKSPACES, WORKSPACE_VERSIONS_SCHEMA, TABLE_WORKSPACE_VERSIONS, MastraCompositeStore, getSqlType, TraceStatus } from '@mastra/core/storage';
|
|
4
4
|
import { parseSqlIdentifier, parseFieldKey } from '@mastra/core/utils';
|
|
5
5
|
import { MastraVector, validateTopK, validateUpsertInput } from '@mastra/core/vector';
|
|
6
6
|
import { BaseFilterTranslator } from '@mastra/core/vector/filter';
|
|
@@ -6348,6 +6348,7 @@ var MemoryLibSQL = class extends MemoryStorage {
|
|
|
6348
6348
|
}
|
|
6349
6349
|
}
|
|
6350
6350
|
async dangerouslyClearAll() {
|
|
6351
|
+
await this.init();
|
|
6351
6352
|
await this.#db.deleteData({ tableName: TABLE_MESSAGES });
|
|
6352
6353
|
await this.#db.deleteData({ tableName: TABLE_THREADS });
|
|
6353
6354
|
await this.#db.deleteData({ tableName: TABLE_RESOURCES });
|
|
@@ -8353,6 +8354,294 @@ ${unreflectedContent}` : bufferedReflection;
|
|
|
8353
8354
|
}
|
|
8354
8355
|
}
|
|
8355
8356
|
};
|
|
8357
|
+
var statusTimestamp = (status, now) => {
|
|
8358
|
+
if (status === "delivered") return { deliveredAt: now };
|
|
8359
|
+
if (status === "seen") return { seenAt: now };
|
|
8360
|
+
if (status === "dismissed") return { dismissedAt: now };
|
|
8361
|
+
if (status === "archived") return { archivedAt: now };
|
|
8362
|
+
if (status === "discarded") return { discardedAt: now };
|
|
8363
|
+
return {};
|
|
8364
|
+
};
|
|
8365
|
+
function parseJson2(value) {
|
|
8366
|
+
if (value == null) return void 0;
|
|
8367
|
+
if (typeof value === "string") {
|
|
8368
|
+
try {
|
|
8369
|
+
return JSON.parse(value);
|
|
8370
|
+
} catch {
|
|
8371
|
+
return value;
|
|
8372
|
+
}
|
|
8373
|
+
}
|
|
8374
|
+
return value;
|
|
8375
|
+
}
|
|
8376
|
+
function parseDate(value) {
|
|
8377
|
+
return value == null ? void 0 : new Date(String(value));
|
|
8378
|
+
}
|
|
8379
|
+
var cloneValue = (value) => value === void 0 ? void 0 : structuredClone(value);
|
|
8380
|
+
function rowToNotification(row) {
|
|
8381
|
+
return {
|
|
8382
|
+
id: String(row.id),
|
|
8383
|
+
threadId: String(row.threadId),
|
|
8384
|
+
source: String(row.source),
|
|
8385
|
+
kind: String(row.kind),
|
|
8386
|
+
priority: String(row.priority),
|
|
8387
|
+
status: String(row.status),
|
|
8388
|
+
summary: String(row.summary),
|
|
8389
|
+
payload: parseJson2(row.payload),
|
|
8390
|
+
resourceId: row.resourceId == null ? void 0 : String(row.resourceId),
|
|
8391
|
+
agentId: row.agentId == null ? void 0 : String(row.agentId),
|
|
8392
|
+
sourceId: row.sourceId == null ? void 0 : String(row.sourceId),
|
|
8393
|
+
dedupeKey: row.dedupeKey == null ? void 0 : String(row.dedupeKey),
|
|
8394
|
+
coalesceKey: row.coalesceKey == null ? void 0 : String(row.coalesceKey),
|
|
8395
|
+
coalescedCount: Number(row.coalescedCount ?? 1),
|
|
8396
|
+
attributes: parseJson2(row.attributes),
|
|
8397
|
+
createdAt: new Date(String(row.createdAt)),
|
|
8398
|
+
updatedAt: new Date(String(row.updatedAt)),
|
|
8399
|
+
deliveredAt: parseDate(row.deliveredAt),
|
|
8400
|
+
seenAt: parseDate(row.seenAt),
|
|
8401
|
+
dismissedAt: parseDate(row.dismissedAt),
|
|
8402
|
+
archivedAt: parseDate(row.archivedAt),
|
|
8403
|
+
discardedAt: parseDate(row.discardedAt),
|
|
8404
|
+
deliverAt: parseDate(row.deliverAt),
|
|
8405
|
+
summaryAt: parseDate(row.summaryAt),
|
|
8406
|
+
deliveryReason: row.deliveryReason == null ? void 0 : String(row.deliveryReason),
|
|
8407
|
+
deliveryAttempts: Number(row.deliveryAttempts ?? 0),
|
|
8408
|
+
lastDeliveryAttemptAt: parseDate(row.lastDeliveryAttemptAt),
|
|
8409
|
+
lastDeliveryError: row.lastDeliveryError == null ? void 0 : String(row.lastDeliveryError),
|
|
8410
|
+
deliveredSignalId: row.deliveredSignalId == null ? void 0 : String(row.deliveredSignalId),
|
|
8411
|
+
summarySignalId: row.summarySignalId == null ? void 0 : String(row.summarySignalId),
|
|
8412
|
+
metadata: parseJson2(row.metadata)
|
|
8413
|
+
};
|
|
8414
|
+
}
|
|
8415
|
+
function addArrayFilter(conditions, args, column, value) {
|
|
8416
|
+
if (!value) return;
|
|
8417
|
+
const values = Array.isArray(value) ? value : [value];
|
|
8418
|
+
conditions.push(`"${column}" IN (${values.map(() => "?").join(", ")})`);
|
|
8419
|
+
args.push(...values);
|
|
8420
|
+
}
|
|
8421
|
+
var NotificationsLibSQL = class extends NotificationsStorage {
|
|
8422
|
+
#db;
|
|
8423
|
+
#client;
|
|
8424
|
+
constructor(config) {
|
|
8425
|
+
super();
|
|
8426
|
+
const client = resolveClient(config);
|
|
8427
|
+
this.#client = client;
|
|
8428
|
+
this.#db = new LibSQLDB({ client, maxRetries: config.maxRetries, initialBackoffMs: config.initialBackoffMs });
|
|
8429
|
+
}
|
|
8430
|
+
async init() {
|
|
8431
|
+
await this.#db.createTable({
|
|
8432
|
+
tableName: TABLE_NOTIFICATIONS,
|
|
8433
|
+
schema: TABLE_SCHEMAS[TABLE_NOTIFICATIONS]
|
|
8434
|
+
});
|
|
8435
|
+
await this.#client.batch(
|
|
8436
|
+
[
|
|
8437
|
+
{
|
|
8438
|
+
sql: `CREATE INDEX IF NOT EXISTS idx_notifications_thread_status_updated ON "${TABLE_NOTIFICATIONS}" ("threadId", "status", "updatedAt")`,
|
|
8439
|
+
args: []
|
|
8440
|
+
},
|
|
8441
|
+
{
|
|
8442
|
+
sql: `CREATE INDEX IF NOT EXISTS idx_notifications_coalescing ON "${TABLE_NOTIFICATIONS}" ("threadId", "source", "kind", "status", "agentId", "resourceId", "dedupeKey", "coalesceKey")`,
|
|
8443
|
+
args: []
|
|
8444
|
+
},
|
|
8445
|
+
{
|
|
8446
|
+
sql: `CREATE INDEX IF NOT EXISTS idx_notifications_due ON "${TABLE_NOTIFICATIONS}" ("status", "deliverAt", "summaryAt")`,
|
|
8447
|
+
args: []
|
|
8448
|
+
}
|
|
8449
|
+
],
|
|
8450
|
+
"write"
|
|
8451
|
+
);
|
|
8452
|
+
}
|
|
8453
|
+
async dangerouslyClearAll() {
|
|
8454
|
+
await this.#db.deleteData({ tableName: TABLE_NOTIFICATIONS });
|
|
8455
|
+
}
|
|
8456
|
+
async createNotification(input) {
|
|
8457
|
+
const existing = await this.findCoalescable(input);
|
|
8458
|
+
if (existing) {
|
|
8459
|
+
const now2 = /* @__PURE__ */ new Date();
|
|
8460
|
+
const attributes = input.attributes ? { ...cloneValue(existing.attributes), ...cloneValue(input.attributes) } : cloneValue(existing.attributes);
|
|
8461
|
+
const metadata = input.metadata ? { ...cloneValue(existing.metadata), ...cloneValue(input.metadata) } : cloneValue(existing.metadata);
|
|
8462
|
+
await this.#db.update({
|
|
8463
|
+
tableName: TABLE_NOTIFICATIONS,
|
|
8464
|
+
keys: { threadId: existing.threadId, id: existing.id },
|
|
8465
|
+
data: {
|
|
8466
|
+
summary: input.summary,
|
|
8467
|
+
payload: cloneValue(input.payload ?? existing.payload) ?? null,
|
|
8468
|
+
priority: input.priority ?? existing.priority,
|
|
8469
|
+
attributes: attributes ?? null,
|
|
8470
|
+
updatedAt: now2,
|
|
8471
|
+
deliverAt: input.deliverAt ?? existing.deliverAt ?? null,
|
|
8472
|
+
summaryAt: input.summaryAt ?? existing.summaryAt ?? null,
|
|
8473
|
+
deliveryReason: input.deliveryReason ?? existing.deliveryReason ?? null,
|
|
8474
|
+
coalescedCount: (existing.coalescedCount ?? 1) + 1,
|
|
8475
|
+
metadata: metadata ?? null
|
|
8476
|
+
}
|
|
8477
|
+
});
|
|
8478
|
+
const updated = await this.getNotification({ threadId: existing.threadId, id: existing.id });
|
|
8479
|
+
if (!updated) throw new Error(`Notification ${existing.id} was not found for thread ${existing.threadId}`);
|
|
8480
|
+
return updated;
|
|
8481
|
+
}
|
|
8482
|
+
const now = input.createdAt ?? /* @__PURE__ */ new Date();
|
|
8483
|
+
const record = {
|
|
8484
|
+
id: input.id ?? randomUUID(),
|
|
8485
|
+
threadId: input.threadId,
|
|
8486
|
+
source: input.source,
|
|
8487
|
+
kind: input.kind,
|
|
8488
|
+
priority: input.priority ?? "medium",
|
|
8489
|
+
status: "pending",
|
|
8490
|
+
summary: input.summary,
|
|
8491
|
+
payload: cloneValue(input.payload),
|
|
8492
|
+
resourceId: input.resourceId,
|
|
8493
|
+
agentId: input.agentId,
|
|
8494
|
+
sourceId: input.sourceId,
|
|
8495
|
+
dedupeKey: input.dedupeKey,
|
|
8496
|
+
coalesceKey: input.coalesceKey,
|
|
8497
|
+
coalescedCount: 1,
|
|
8498
|
+
attributes: cloneValue(input.attributes),
|
|
8499
|
+
createdAt: now,
|
|
8500
|
+
updatedAt: now,
|
|
8501
|
+
deliverAt: input.deliverAt,
|
|
8502
|
+
summaryAt: input.summaryAt,
|
|
8503
|
+
deliveryReason: input.deliveryReason,
|
|
8504
|
+
deliveryAttempts: 0,
|
|
8505
|
+
metadata: cloneValue(input.metadata)
|
|
8506
|
+
};
|
|
8507
|
+
await this.#db.insert({
|
|
8508
|
+
tableName: TABLE_NOTIFICATIONS,
|
|
8509
|
+
record: {
|
|
8510
|
+
...record,
|
|
8511
|
+
payload: record.payload ?? null,
|
|
8512
|
+
attributes: record.attributes ?? null,
|
|
8513
|
+
metadata: record.metadata ?? null,
|
|
8514
|
+
resourceId: record.resourceId ?? null,
|
|
8515
|
+
agentId: record.agentId ?? null,
|
|
8516
|
+
sourceId: record.sourceId ?? null,
|
|
8517
|
+
dedupeKey: record.dedupeKey ?? null,
|
|
8518
|
+
coalesceKey: record.coalesceKey ?? null,
|
|
8519
|
+
deliverAt: record.deliverAt ?? null,
|
|
8520
|
+
summaryAt: record.summaryAt ?? null,
|
|
8521
|
+
deliveryReason: record.deliveryReason ?? null,
|
|
8522
|
+
deliveryAttempts: record.deliveryAttempts ?? 0
|
|
8523
|
+
}
|
|
8524
|
+
});
|
|
8525
|
+
return record;
|
|
8526
|
+
}
|
|
8527
|
+
async listNotifications(input) {
|
|
8528
|
+
const conditions = ['"threadId" = ?'];
|
|
8529
|
+
const args = [input.threadId];
|
|
8530
|
+
addArrayFilter(conditions, args, "status", input.status);
|
|
8531
|
+
addArrayFilter(conditions, args, "priority", input.priority);
|
|
8532
|
+
if (input.source) {
|
|
8533
|
+
conditions.push('"source" = ?');
|
|
8534
|
+
args.push(input.source);
|
|
8535
|
+
}
|
|
8536
|
+
if (input.resourceId) {
|
|
8537
|
+
conditions.push('"resourceId" = ?');
|
|
8538
|
+
args.push(input.resourceId);
|
|
8539
|
+
}
|
|
8540
|
+
if (input.agentId) {
|
|
8541
|
+
conditions.push('"agentId" = ?');
|
|
8542
|
+
args.push(input.agentId);
|
|
8543
|
+
}
|
|
8544
|
+
if (input.search) {
|
|
8545
|
+
conditions.push('(LOWER("summary") LIKE ? OR LOWER("kind") LIKE ?)');
|
|
8546
|
+
const search = `%${input.search.toLowerCase()}%`;
|
|
8547
|
+
args.push(search, search);
|
|
8548
|
+
}
|
|
8549
|
+
const limit = input.limit ? " LIMIT ?" : "";
|
|
8550
|
+
if (input.limit) args.push(input.limit);
|
|
8551
|
+
const result = await this.#client.execute({
|
|
8552
|
+
sql: `SELECT ${buildSelectColumns(TABLE_NOTIFICATIONS)} FROM "${TABLE_NOTIFICATIONS}" WHERE ${conditions.join(" AND ")} ORDER BY "updatedAt" DESC${limit}`,
|
|
8553
|
+
args
|
|
8554
|
+
});
|
|
8555
|
+
return (result.rows ?? []).map((row) => rowToNotification(row));
|
|
8556
|
+
}
|
|
8557
|
+
async listDueNotifications(input) {
|
|
8558
|
+
const now = input.now.toISOString();
|
|
8559
|
+
const conditions = [
|
|
8560
|
+
'"status" = ?',
|
|
8561
|
+
'(("deliverAt" IS NOT NULL AND "deliverAt" <= ?) OR ("summaryAt" IS NOT NULL AND "summaryAt" <= ?))'
|
|
8562
|
+
];
|
|
8563
|
+
const args = ["pending", now, now];
|
|
8564
|
+
if (input.agentId) {
|
|
8565
|
+
conditions.push('"agentId" = ?');
|
|
8566
|
+
args.push(input.agentId);
|
|
8567
|
+
}
|
|
8568
|
+
if (input.resourceId) {
|
|
8569
|
+
conditions.push('"resourceId" = ?');
|
|
8570
|
+
args.push(input.resourceId);
|
|
8571
|
+
}
|
|
8572
|
+
const limit = input.limit ? " LIMIT ?" : "";
|
|
8573
|
+
if (input.limit) args.push(input.limit);
|
|
8574
|
+
const result = await this.#client.execute({
|
|
8575
|
+
sql: `SELECT ${buildSelectColumns(TABLE_NOTIFICATIONS)} FROM "${TABLE_NOTIFICATIONS}" WHERE ${conditions.join(" AND ")} ORDER BY CASE WHEN "deliverAt" IS NULL THEN "summaryAt" WHEN "summaryAt" IS NULL THEN "deliverAt" WHEN "deliverAt" <= "summaryAt" THEN "deliverAt" ELSE "summaryAt" END ASC, "updatedAt" ASC${limit}`,
|
|
8576
|
+
args
|
|
8577
|
+
});
|
|
8578
|
+
return (result.rows ?? []).map((row) => rowToNotification(row));
|
|
8579
|
+
}
|
|
8580
|
+
async getNotification(input) {
|
|
8581
|
+
const result = await this.#client.execute({
|
|
8582
|
+
sql: `SELECT ${buildSelectColumns(TABLE_NOTIFICATIONS)} FROM "${TABLE_NOTIFICATIONS}" WHERE "threadId" = ? AND "id" = ? LIMIT 1`,
|
|
8583
|
+
args: [input.threadId, input.id]
|
|
8584
|
+
});
|
|
8585
|
+
const row = result.rows?.[0];
|
|
8586
|
+
return row ? rowToNotification(row) : null;
|
|
8587
|
+
}
|
|
8588
|
+
async updateNotification(input) {
|
|
8589
|
+
const existing = await this.getNotification({ threadId: input.threadId, id: input.id });
|
|
8590
|
+
if (!existing) {
|
|
8591
|
+
throw new Error(`Notification ${input.id} was not found for thread ${input.threadId}`);
|
|
8592
|
+
}
|
|
8593
|
+
const now = /* @__PURE__ */ new Date();
|
|
8594
|
+
await this.#db.update({
|
|
8595
|
+
tableName: TABLE_NOTIFICATIONS,
|
|
8596
|
+
keys: { threadId: input.threadId, id: input.id },
|
|
8597
|
+
data: {
|
|
8598
|
+
...input.status ? { status: input.status, ...statusTimestamp(input.status, now) } : {},
|
|
8599
|
+
...input.summary !== void 0 ? { summary: input.summary } : {},
|
|
8600
|
+
...input.payload !== void 0 ? { payload: cloneValue(input.payload) } : {},
|
|
8601
|
+
...input.attributes !== void 0 ? { attributes: cloneValue(input.attributes) } : {},
|
|
8602
|
+
...input.metadata !== void 0 ? { metadata: cloneValue(input.metadata) } : {},
|
|
8603
|
+
...input.deliverAt !== void 0 ? { deliverAt: input.deliverAt } : {},
|
|
8604
|
+
...input.summaryAt !== void 0 ? { summaryAt: input.summaryAt } : {},
|
|
8605
|
+
...input.deliveryReason !== void 0 ? { deliveryReason: input.deliveryReason } : {},
|
|
8606
|
+
...input.deliveryAttempts !== void 0 ? { deliveryAttempts: input.deliveryAttempts } : {},
|
|
8607
|
+
...input.lastDeliveryAttemptAt !== void 0 ? { lastDeliveryAttemptAt: input.lastDeliveryAttemptAt } : {},
|
|
8608
|
+
...input.lastDeliveryError !== void 0 ? { lastDeliveryError: input.lastDeliveryError } : {},
|
|
8609
|
+
...input.deliveredSignalId !== void 0 ? { deliveredSignalId: input.deliveredSignalId } : {},
|
|
8610
|
+
...input.summarySignalId !== void 0 ? { summarySignalId: input.summarySignalId } : {},
|
|
8611
|
+
updatedAt: now
|
|
8612
|
+
}
|
|
8613
|
+
});
|
|
8614
|
+
const updated = await this.getNotification({ threadId: input.threadId, id: input.id });
|
|
8615
|
+
if (!updated) throw new Error(`Notification ${input.id} was not found for thread ${input.threadId}`);
|
|
8616
|
+
return updated;
|
|
8617
|
+
}
|
|
8618
|
+
async findCoalescable(input) {
|
|
8619
|
+
if (!input.dedupeKey && !input.coalesceKey) return void 0;
|
|
8620
|
+
const agentId = input.agentId ?? null;
|
|
8621
|
+
const resourceId = input.resourceId ?? null;
|
|
8622
|
+
const dedupeKey = input.dedupeKey ?? null;
|
|
8623
|
+
const coalesceKey = input.coalesceKey ?? null;
|
|
8624
|
+
const result = await this.#client.execute({
|
|
8625
|
+
sql: `SELECT ${buildSelectColumns(TABLE_NOTIFICATIONS)} FROM "${TABLE_NOTIFICATIONS}" WHERE "threadId" = ? AND "source" = ? AND "kind" = ? AND "status" = ? AND (("agentId" = ?) OR ("agentId" IS NULL AND ? IS NULL)) AND (("resourceId" = ?) OR ("resourceId" IS NULL AND ? IS NULL)) AND ((? IS NOT NULL AND "dedupeKey" = ?) OR (? IS NOT NULL AND "coalesceKey" = ?)) ORDER BY "updatedAt" DESC LIMIT 1`,
|
|
8626
|
+
args: [
|
|
8627
|
+
input.threadId,
|
|
8628
|
+
input.source,
|
|
8629
|
+
input.kind,
|
|
8630
|
+
"pending",
|
|
8631
|
+
agentId,
|
|
8632
|
+
agentId,
|
|
8633
|
+
resourceId,
|
|
8634
|
+
resourceId,
|
|
8635
|
+
dedupeKey,
|
|
8636
|
+
dedupeKey,
|
|
8637
|
+
coalesceKey,
|
|
8638
|
+
coalesceKey
|
|
8639
|
+
]
|
|
8640
|
+
});
|
|
8641
|
+
const row = result.rows?.[0];
|
|
8642
|
+
return row ? rowToNotification(row) : void 0;
|
|
8643
|
+
}
|
|
8644
|
+
};
|
|
8356
8645
|
var ObservabilityLibSQL = class extends ObservabilityStorage {
|
|
8357
8646
|
#db;
|
|
8358
8647
|
constructor(config) {
|
|
@@ -9325,7 +9614,7 @@ var PromptBlocksLibSQL = class extends PromptBlocksStorage {
|
|
|
9325
9614
|
};
|
|
9326
9615
|
}
|
|
9327
9616
|
};
|
|
9328
|
-
function
|
|
9617
|
+
function parseJson3(val) {
|
|
9329
9618
|
if (val == null) return void 0;
|
|
9330
9619
|
if (typeof val === "string") {
|
|
9331
9620
|
try {
|
|
@@ -9341,7 +9630,7 @@ function toNumber(val) {
|
|
|
9341
9630
|
return Number(val);
|
|
9342
9631
|
}
|
|
9343
9632
|
function rowToSchedule(row) {
|
|
9344
|
-
const target =
|
|
9633
|
+
const target = parseJson3(row.target);
|
|
9345
9634
|
if (!target) {
|
|
9346
9635
|
throw new Error(`Schedule row ${row.id} has invalid target`);
|
|
9347
9636
|
}
|
|
@@ -9357,7 +9646,7 @@ function rowToSchedule(row) {
|
|
|
9357
9646
|
if (row.timezone != null) schedule.timezone = String(row.timezone);
|
|
9358
9647
|
if (row.last_fire_at != null) schedule.lastFireAt = toNumber(row.last_fire_at);
|
|
9359
9648
|
if (row.last_run_id != null) schedule.lastRunId = String(row.last_run_id);
|
|
9360
|
-
const metadata =
|
|
9649
|
+
const metadata = parseJson3(row.metadata);
|
|
9361
9650
|
if (metadata !== void 0) schedule.metadata = metadata;
|
|
9362
9651
|
if (row.owner_type != null) schedule.ownerType = String(row.owner_type);
|
|
9363
9652
|
if (row.owner_id != null) schedule.ownerId = String(row.owner_id);
|
|
@@ -9375,7 +9664,7 @@ function rowToTrigger(row) {
|
|
|
9375
9664
|
};
|
|
9376
9665
|
if (row.error != null) trigger.error = String(row.error);
|
|
9377
9666
|
if (row.parent_trigger_id != null) trigger.parentTriggerId = String(row.parent_trigger_id);
|
|
9378
|
-
const metadata =
|
|
9667
|
+
const metadata = parseJson3(row.metadata);
|
|
9379
9668
|
if (metadata !== void 0) trigger.metadata = metadata;
|
|
9380
9669
|
return trigger;
|
|
9381
9670
|
}
|
|
@@ -12117,6 +12406,7 @@ var LibSQLStore = class extends MastraCompositeStore {
|
|
|
12117
12406
|
const backgroundTasks = new BackgroundTasksLibSQL(domainConfig);
|
|
12118
12407
|
const schedules = new SchedulesLibSQL(domainConfig);
|
|
12119
12408
|
const toolProviderConnections = new ToolProviderConnectionsLibSQL(domainConfig);
|
|
12409
|
+
const notifications = new NotificationsLibSQL(domainConfig);
|
|
12120
12410
|
this.stores = {
|
|
12121
12411
|
scores,
|
|
12122
12412
|
workflows,
|
|
@@ -12136,7 +12426,8 @@ var LibSQLStore = class extends MastraCompositeStore {
|
|
|
12136
12426
|
blobs,
|
|
12137
12427
|
backgroundTasks,
|
|
12138
12428
|
schedules,
|
|
12139
|
-
toolProviderConnections
|
|
12429
|
+
toolProviderConnections,
|
|
12430
|
+
notifications
|
|
12140
12431
|
};
|
|
12141
12432
|
}
|
|
12142
12433
|
async applyLocalPragmas() {
|
|
@@ -12325,6 +12616,6 @@ Example Complex Query:
|
|
|
12325
12616
|
]
|
|
12326
12617
|
}`;
|
|
12327
12618
|
|
|
12328
|
-
export { AgentsLibSQL, BackgroundTasksLibSQL, BlobsLibSQL, ChannelsLibSQL, DatasetsLibSQL, LibSQLStore as DefaultStorage, ExperimentsLibSQL, FavoritesLibSQL, LIBSQL_PROMPT, LibSQLStore, LibSQLVector, MCPClientsLibSQL, MCPServersLibSQL, MemoryLibSQL, ObservabilityLibSQL, PromptBlocksLibSQL, SchedulesLibSQL, ScorerDefinitionsLibSQL, ScoresLibSQL, SkillsLibSQL, ToolProviderConnectionsLibSQL, WorkflowsLibSQL, WorkspacesLibSQL };
|
|
12619
|
+
export { AgentsLibSQL, BackgroundTasksLibSQL, BlobsLibSQL, ChannelsLibSQL, DatasetsLibSQL, LibSQLStore as DefaultStorage, ExperimentsLibSQL, FavoritesLibSQL, LIBSQL_PROMPT, LibSQLStore, LibSQLVector, MCPClientsLibSQL, MCPServersLibSQL, MemoryLibSQL, NotificationsLibSQL, ObservabilityLibSQL, PromptBlocksLibSQL, SchedulesLibSQL, ScorerDefinitionsLibSQL, ScoresLibSQL, SkillsLibSQL, ToolProviderConnectionsLibSQL, WorkflowsLibSQL, WorkspacesLibSQL };
|
|
12329
12620
|
//# sourceMappingURL=index.js.map
|
|
12330
12621
|
//# sourceMappingURL=index.js.map
|