@mastra/elasticsearch 1.3.1 → 1.4.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.d.cts CHANGED
@@ -1,6 +1,11 @@
1
1
  import { Client } from "@elastic/elasticsearch";
2
2
  import { CreateIndexParams, DeleteIndexParams, DeleteVectorParams, DeleteVectorsParams, DescribeIndexParams, IndexStats, MastraVector, QueryResult, QueryVectorParams, UpdateVectorParams, UpsertVectorParams } from "@mastra/core/vector";
3
3
  import { BlacklistedRootOperators, LogicalOperatorValueMap, OperatorValueMap, VectorFilter } from "@mastra/core/vector/filter";
4
+ import { MastraStorage, MemoryStorage, PaginationInfo, ScoreTenancyFilters, ScoresStorage, StorageCloneThreadInput, StorageCloneThreadOutput, StorageDomains, StorageListMessagesInput, StorageListMessagesOutput, StorageListThreadsInput, StorageListThreadsOutput, StorageListWorkflowRunsInput, StoragePagination, StorageResourceType, UpdateWorkflowStateOptions, WorkflowRun, WorkflowRuns, WorkflowsStorage } from "@mastra/core/storage";
5
+ import { MastraMessageContentV2 } from "@mastra/core/agent";
6
+ import { MastraDBMessage, StorageThreadType } from "@mastra/core/memory";
7
+ import { StepResult, WorkflowRunState } from "@mastra/core/workflows";
8
+ import { SaveScorePayload, ScoreRowData, ScoringSource } from "@mastra/core/evals";
4
9
  //#region src/vector/filter.d.ts
5
10
  type ElasticSearchOperatorValueMap = Omit<OperatorValueMap, '$options' | '$nor' | '$elemMatch'>;
6
11
  type ElasticSearchLogicalOperatorValueMap = Omit<LogicalOperatorValueMap, '$nor'>;
@@ -138,5 +143,272 @@ declare class ElasticSearchVector extends MastraVector<ElasticSearchVectorFilter
138
143
  deleteVectors({ indexName, filter, ids }: DeleteVectorsParams<ElasticSearchVectorFilter>): Promise<void>;
139
144
  }
140
145
  //#endregion
141
- export { type ElasticSearchAuth, ElasticSearchVector, type ElasticSearchVectorConfig, type ElasticSearchVectorFilter };
146
+ //#region src/storage/types.d.ts
147
+ /**
148
+ * ElasticSearch storage configuration type.
149
+ *
150
+ * Accepts either:
151
+ * - A pre-configured ElasticSearch client: `{ id, client }`
152
+ * - Connection parameters: `{ id, url, auth? }`
153
+ *
154
+ * This mirrors the config surface of `ElasticSearchVector` so both can share
155
+ * the same connection settings (or the same client instance).
156
+ */
157
+ type ElasticSearchConfig = {
158
+ id: string;
159
+ /**
160
+ * When true, automatic initialization (index creation) is disabled.
161
+ * You must call `storage.init()` explicitly before use.
162
+ */
163
+ disableInit?: boolean;
164
+ } & ({
165
+ /**
166
+ * Pre-configured ElasticSearch client (from `@elastic/elasticsearch`).
167
+ *
168
+ * @example
169
+ * ```typescript
170
+ * import { Client } from '@elastic/elasticsearch';
171
+ *
172
+ * const client = new Client({ node: 'http://localhost:9200' });
173
+ * const store = new ElasticSearchStore({ id: 'my-store', client });
174
+ * ```
175
+ */
176
+ client: Client;
177
+ url?: never;
178
+ auth?: never;
179
+ } | {
180
+ /**
181
+ * ElasticSearch node URL.
182
+ *
183
+ * @example
184
+ * ```typescript
185
+ * const store = new ElasticSearchStore({
186
+ * id: 'my-store',
187
+ * url: 'http://localhost:9200',
188
+ * auth: { apiKey: '...' },
189
+ * });
190
+ * ```
191
+ */
192
+ url: string;
193
+ auth?: ElasticSearchAuth;
194
+ client?: never;
195
+ });
196
+ //#endregion
197
+ //#region src/storage/store.d.ts
198
+ /**
199
+ * ElasticSearch storage adapter for Mastra.
200
+ *
201
+ * Implements the memory, workflows, and scores storage domains on top of
202
+ * ElasticSearch. Shares the same connection config surface as
203
+ * `ElasticSearchVector`, so both can reuse one client or connection config.
204
+ *
205
+ * @example
206
+ * ```typescript
207
+ * // Using connection parameters
208
+ * const storage = new ElasticSearchStore({
209
+ * id: 'my-store',
210
+ * url: 'http://localhost:9200',
211
+ * auth: { apiKey: '...' },
212
+ * });
213
+ *
214
+ * // Access memory domain
215
+ * const memory = await storage.getStore('memory');
216
+ * await memory?.saveThread({ thread });
217
+ * ```
218
+ *
219
+ * @example
220
+ * ```typescript
221
+ * // Using a pre-configured client shared with ElasticSearchVector
222
+ * import { Client } from '@elastic/elasticsearch';
223
+ *
224
+ * const client = new Client({ node: 'http://localhost:9200' });
225
+ * const storage = new ElasticSearchStore({ id: 'my-store', client });
226
+ * const vector = new ElasticSearchVector({ id: 'my-vector', client });
227
+ * ```
228
+ */
229
+ declare class ElasticSearchStore extends MastraStorage {
230
+ private client;
231
+ private shouldManageConnection;
232
+ stores: StorageDomains;
233
+ constructor(config: ElasticSearchConfig);
234
+ getClient(): Client;
235
+ close(): Promise<void>;
236
+ }
237
+ //#endregion
238
+ //#region src/storage/db.d.ts
239
+ interface ElasticSearchDomainConfig {
240
+ client: Client;
241
+ }
242
+ //#endregion
243
+ //#region src/storage/domains/memory/index.d.ts
244
+ declare class MemoryElasticSearch extends MemoryStorage {
245
+ readonly supportsPartialThreadUpdate = true;
246
+ private db;
247
+ constructor(config: ElasticSearchDomainConfig);
248
+ dangerouslyClearAll(): Promise<void>;
249
+ getThreadById({ threadId, resourceId }: {
250
+ threadId: string;
251
+ resourceId?: string;
252
+ }): Promise<StorageThreadType | null>;
253
+ listThreadsByResourceId(args: StorageListThreadsInput): Promise<StorageListThreadsOutput>;
254
+ listThreads(args: StorageListThreadsInput): Promise<StorageListThreadsOutput>;
255
+ saveThread({ thread }: {
256
+ thread: StorageThreadType;
257
+ }): Promise<StorageThreadType>;
258
+ updateThread({ id, title, metadata }: {
259
+ id: string;
260
+ title?: string;
261
+ metadata?: Record<string, unknown>;
262
+ }): Promise<StorageThreadType>;
263
+ deleteThread({ threadId }: {
264
+ threadId: string;
265
+ }): Promise<void>;
266
+ saveMessages(args: {
267
+ messages: MastraDBMessage[];
268
+ }): Promise<{
269
+ messages: MastraDBMessage[];
270
+ }>;
271
+ /**
272
+ * Returns all messages that belong to a thread, sorted in insertion order
273
+ * (createdAt with `_index` tiebreaker).
274
+ */
275
+ private listThreadMessages;
276
+ /** Returns all message documents across all threads (excludes index docs). */
277
+ private listAllMessages;
278
+ private getThreadIdForMessage;
279
+ /**
280
+ * Fetches the messages named by `include` together with their surrounding context.
281
+ *
282
+ * @param include - Message ids to pin, each with an optional before/after window.
283
+ * @param resourceId - When set, drops any pinned or context message owned by another
284
+ * resource so an id from another resource returns nothing.
285
+ */
286
+ private getIncludedMessages;
287
+ private parseStoredMessage;
288
+ listMessagesById({ messageIds }: {
289
+ messageIds: string[];
290
+ }): Promise<{
291
+ messages: MastraDBMessage[];
292
+ }>;
293
+ listMessages(args: StorageListMessagesInput): Promise<StorageListMessagesOutput>;
294
+ getResourceById({ resourceId }: {
295
+ resourceId: string;
296
+ }): Promise<StorageResourceType | null>;
297
+ saveResource({ resource }: {
298
+ resource: StorageResourceType;
299
+ }): Promise<StorageResourceType>;
300
+ updateResource({ resourceId, workingMemory, metadata }: {
301
+ resourceId: string;
302
+ workingMemory?: string;
303
+ metadata?: Record<string, unknown>;
304
+ }): Promise<StorageResourceType>;
305
+ updateMessages(args: {
306
+ messages: (Partial<Omit<MastraDBMessage, 'createdAt'>> & {
307
+ id: string;
308
+ content?: {
309
+ metadata?: MastraMessageContentV2['metadata'];
310
+ content?: MastraMessageContentV2['content'];
311
+ };
312
+ })[];
313
+ }): Promise<MastraDBMessage[]>;
314
+ deleteMessages(messageIds: string[]): Promise<void>;
315
+ private sortThreads;
316
+ cloneThread(args: StorageCloneThreadInput): Promise<StorageCloneThreadOutput>;
317
+ }
318
+ //#endregion
319
+ //#region src/storage/domains/workflows/index.d.ts
320
+ declare class WorkflowsElasticSearch extends WorkflowsStorage {
321
+ private db;
322
+ constructor(config: ElasticSearchDomainConfig);
323
+ supportsConcurrentUpdates(): boolean;
324
+ dangerouslyClearAll(): Promise<void>;
325
+ updateWorkflowResults({ workflowName, runId, stepId, result, requestContext }: {
326
+ workflowName: string;
327
+ runId: string;
328
+ stepId: string;
329
+ result: StepResult<unknown, unknown, unknown, unknown>;
330
+ requestContext: Record<string, unknown>;
331
+ }): Promise<Record<string, StepResult<unknown, unknown, unknown, unknown>>>;
332
+ updateWorkflowState({ workflowName, runId, opts }: {
333
+ workflowName: string;
334
+ runId: string;
335
+ opts: UpdateWorkflowStateOptions;
336
+ }): Promise<WorkflowRunState | undefined>;
337
+ persistWorkflowSnapshot(params: {
338
+ namespace?: string;
339
+ workflowName: string;
340
+ runId: string;
341
+ resourceId?: string;
342
+ snapshot: WorkflowRunState;
343
+ createdAt?: Date;
344
+ updatedAt?: Date;
345
+ }): Promise<void>;
346
+ loadWorkflowSnapshot(params: {
347
+ namespace: string;
348
+ workflowName: string;
349
+ runId: string;
350
+ }): Promise<WorkflowRunState | null>;
351
+ getWorkflowRunById({ runId, workflowName }: {
352
+ runId: string;
353
+ workflowName?: string;
354
+ }): Promise<WorkflowRun | null>;
355
+ deleteWorkflowRunById({ runId, workflowName }: {
356
+ runId: string;
357
+ workflowName: string;
358
+ }): Promise<void>;
359
+ listWorkflowRuns({ workflowName, fromDate, toDate, perPage, page, resourceId, status }?: StorageListWorkflowRunsInput): Promise<WorkflowRuns>;
360
+ }
361
+ //#endregion
362
+ //#region src/storage/domains/scores/index.d.ts
363
+ declare class ScoresElasticSearch extends ScoresStorage {
364
+ private db;
365
+ constructor(config: ElasticSearchDomainConfig);
366
+ dangerouslyClearAll(): Promise<void>;
367
+ getScoreById({ id }: {
368
+ id: string;
369
+ }): Promise<ScoreRowData | null>;
370
+ listScoresByScorerId({ scorerId, entityId, entityType, source, pagination, filters }: {
371
+ scorerId: string;
372
+ entityId?: string;
373
+ entityType?: string;
374
+ source?: ScoringSource;
375
+ pagination?: StoragePagination;
376
+ filters?: ScoreTenancyFilters;
377
+ }): Promise<{
378
+ scores: ScoreRowData[];
379
+ pagination: PaginationInfo;
380
+ }>;
381
+ saveScore(score: SaveScorePayload): Promise<{
382
+ score: ScoreRowData;
383
+ }>;
384
+ listScoresByRunId({ runId, pagination, filters }: {
385
+ runId: string;
386
+ pagination?: StoragePagination;
387
+ filters?: ScoreTenancyFilters;
388
+ }): Promise<{
389
+ scores: ScoreRowData[];
390
+ pagination: PaginationInfo;
391
+ }>;
392
+ listScoresByEntityId({ entityId, entityType, pagination, filters }: {
393
+ entityId: string;
394
+ entityType?: string;
395
+ pagination?: StoragePagination;
396
+ filters?: ScoreTenancyFilters;
397
+ }): Promise<{
398
+ scores: ScoreRowData[];
399
+ pagination: PaginationInfo;
400
+ }>;
401
+ listScoresBySpan({ traceId, spanId, pagination, filters }: {
402
+ traceId: string;
403
+ spanId: string;
404
+ pagination?: StoragePagination;
405
+ filters?: ScoreTenancyFilters;
406
+ }): Promise<{
407
+ scores: ScoreRowData[];
408
+ pagination: PaginationInfo;
409
+ }>;
410
+ private fetchAndFilterScores;
411
+ }
412
+ //#endregion
413
+ export { type ElasticSearchAuth, type ElasticSearchConfig, ElasticSearchStore, ElasticSearchVector, type ElasticSearchVectorConfig, type ElasticSearchVectorFilter, MemoryElasticSearch, ScoresElasticSearch, WorkflowsElasticSearch };
142
414
  //# sourceMappingURL=index.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.cts","names":[],"sources":["../src/vector/filter.ts","../src/vector/index.ts"],"mappings":";;;;KAUK,gCAAgC,KAAK;KAErC,uCAAuC,KAAK;KAE5C,2BAA2B;KAEpB,4BAA4B,mBAChC,+BACN,+BACA,sCACA;;;KCaG,4BAA4B,kBAAkB;KAEvC;EAAsB;;EAAqB;EAAkB;;EAAuB;;KAEpF;EACN;EAAY,QAAQ;EAAqB;EAAa;;EACtD;EAAY;EAAa,OAAO;EAAmB;;cAE5C,4BAA4B,aAAa;UAC5C;;;;;;;;EASI,YAAA,QAAQ;;;;;;;;;EA6Bd,cAAc,WAAW,WAAW,UAAqB,oBAAoB;;;;;;EAkD7E,eAAe;;;;;YAwBL,sBAAsB,mBAAmB,mBAAmB,iBAAiB;;;;;;;EAoDvF,gBAAgB,aAAa,sBAAsB,QAAQ;;;;;;;EAqB3D,cAAc,aAAa,oBAAoB;;;;;;;;;;EA4B/C,SAAS,WAAW,SAAS,UAAe,OAAO,qBAAqB;;;;;;;;;;;EA+HxE,QACJ,WACA,aACA,QACA,MACA,iBACC,4BAA4B,QAAQ;;;;;;;;UA+D/B;;;;;;;UAYA;;;;;;;;;;;EAeF,aAAa,QAAQ,mBAAmB,6BAA6B;;;;UAwD7D;;;;UAuFA;;;;;;;;EAyDR,eAAe,WAAW,MAAM,qBAAqB;EA2BrD,gBAAgB,WAAW,QAAQ,OAAO,oBAAoB,6BAA6B"}
1
+ {"version":3,"file":"index.d.cts","names":[],"sources":["../src/vector/filter.ts","../src/vector/index.ts","../src/storage/types.ts","../src/storage/store.ts","../src/storage/db.ts","../src/storage/domains/memory/index.ts","../src/storage/domains/workflows/index.ts","../src/storage/domains/scores/index.ts"],"mappings":";;;;;;;;;KAUK,gCAAgC,KAAK;KAErC,uCAAuC,KAAK;KAE5C,2BAA2B;KAEpB,4BAA4B,mBAChC,+BACN,+BACA,sCACA;;;KCaG,4BAA4B,kBAAkB;KAEvC;EAAsB;;EAAqB;EAAkB;;EAAuB;;KAEpF;EACN;EAAY,QAAQ;EAAqB;EAAa;;EACtD;EAAY;EAAa,OAAO;EAAmB;;cAE5C,4BAA4B,aAAa;UAC5C;;;;;;;;EASI,YAAA,QAAQ;;;;;;;;;EA6Bd,cAAc,WAAW,WAAW,UAAqB,oBAAoB;;;;;;EAkD7E,eAAe;;;;;YAwBL,sBAAsB,mBAAmB,mBAAmB,iBAAiB;;;;;;;EAoDvF,gBAAgB,aAAa,sBAAsB,QAAQ;;;;;;;EAqB3D,cAAc,aAAa,oBAAoB;;;;;;;;;;EA4B/C,SAAS,WAAW,SAAS,UAAe,OAAO,qBAAqB;;;;;;;;;;;EA+HxE,QACJ,WACA,aACA,QACA,MACA,iBACC,4BAA4B,QAAQ;;;;;;;;UA+D/B;;;;;;;UAYA;;;;;;;;;;;EAeF,aAAa,QAAQ,mBAAmB,6BAA6B;;;;UAwD7D;;;;UAuFA;;;;;;;;EAyDR,eAAe,WAAW,MAAM,qBAAqB;EA2BrD,gBAAgB,WAA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BACX,cACA,OACA;IAEA;IACA;IACA,MAAM;MACJ,QAAQ;EAmDC,wBAAwB;IACnC;IACA;IACA;IACA;IACA,UAAU;IACV,YAAY;IACZ,YAAY;MACV;EA6CS,qBAAqB;IAChC;IACA;IACA;MACE,QAAQ;EA6BC,qBACX,OACA;IAEA;IACA;MACE,QAAQ;EA2CC,wBAAwB,OAAO;IAAkB;IAAe;MAAyB;EAqBzF,mBACX,cACA,UACA,QACA,SACA,MACA,YACA,WACC,+BAAoC,QAAQ;;;;cChVpC,4BAA4B;UAC/B;EAEI,YAAA,QAAQ;EAKP,uBAAuB;EAIvB,eAAe;IAAQ;MAAe,QAAQ;EA2B9C,uBACX,UACA,UACA,YACA,QACA,YACA;IAEA;IACA;IACA;IACA,SAAS;IACT,aAAa;IACb,UAAU;MACR;IACF,QAAQ;IACR,YAAY;;EAsBD,UAAU,OAAO,mBAAmB;IAAU,OAAO;;EAiDrD,oBACX,OACA,YACA;IAEA;IACA,aAAa;IACb,UAAU;MACR;IACF,QAAQ;IACR,YAAY;;EAKD,uBACX,UACA,YACA,YACA;IAEA;IACA;IACA,aAAa;IACb,UAAU;MACR;IACF,QAAQ;IACR,YAAY;;EAgBD,mBACX,SACA,QACA,YACA;IAEA;IACA;IACA,aAAa;IACb,UAAU;MACR;IACF,QAAQ;IACR,YAAY;;UAQA"}
package/dist/index.d.ts CHANGED
@@ -1,6 +1,11 @@
1
1
  import { Client } from "@elastic/elasticsearch";
2
+ import { MastraStorage, MemoryStorage, PaginationInfo, ScoreTenancyFilters, ScoresStorage, StorageCloneThreadInput, StorageCloneThreadOutput, StorageDomains, StorageListMessagesInput, StorageListMessagesOutput, StorageListThreadsInput, StorageListThreadsOutput, StorageListWorkflowRunsInput, StoragePagination, StorageResourceType, UpdateWorkflowStateOptions, WorkflowRun, WorkflowRuns, WorkflowsStorage } from "@mastra/core/storage";
2
3
  import { CreateIndexParams, DeleteIndexParams, DeleteVectorParams, DeleteVectorsParams, DescribeIndexParams, IndexStats, MastraVector, QueryResult, QueryVectorParams, UpdateVectorParams, UpsertVectorParams } from "@mastra/core/vector";
3
4
  import { BaseFilterTranslator, BlacklistedRootOperators, LogicalOperatorValueMap, OperatorValueMap, VectorFilter } from "@mastra/core/vector/filter";
5
+ import { MastraMessageContentV2 } from "@mastra/core/agent";
6
+ import { SaveScorePayload, ScoreRowData, ScoringSource } from "@mastra/core/evals";
7
+ import { MastraDBMessage, StorageThreadType } from "@mastra/core/memory";
8
+ import { StepResult, WorkflowRunState } from "@mastra/core/workflows";
4
9
  //#region src/vector/filter.d.ts
5
10
  type ElasticSearchOperatorValueMap = Omit<OperatorValueMap, '$options' | '$nor' | '$elemMatch'>;
6
11
  type ElasticSearchLogicalOperatorValueMap = Omit<LogicalOperatorValueMap, '$nor'>;
@@ -138,5 +143,272 @@ declare class ElasticSearchVector extends MastraVector<ElasticSearchVectorFilter
138
143
  deleteVectors({ indexName, filter, ids }: DeleteVectorsParams<ElasticSearchVectorFilter>): Promise<void>;
139
144
  }
140
145
  //#endregion
141
- export { type ElasticSearchAuth, ElasticSearchVector, type ElasticSearchVectorConfig, type ElasticSearchVectorFilter };
146
+ //#region src/storage/types.d.ts
147
+ /**
148
+ * ElasticSearch storage configuration type.
149
+ *
150
+ * Accepts either:
151
+ * - A pre-configured ElasticSearch client: `{ id, client }`
152
+ * - Connection parameters: `{ id, url, auth? }`
153
+ *
154
+ * This mirrors the config surface of `ElasticSearchVector` so both can share
155
+ * the same connection settings (or the same client instance).
156
+ */
157
+ type ElasticSearchConfig = {
158
+ id: string;
159
+ /**
160
+ * When true, automatic initialization (index creation) is disabled.
161
+ * You must call `storage.init()` explicitly before use.
162
+ */
163
+ disableInit?: boolean;
164
+ } & ({
165
+ /**
166
+ * Pre-configured ElasticSearch client (from `@elastic/elasticsearch`).
167
+ *
168
+ * @example
169
+ * ```typescript
170
+ * import { Client } from '@elastic/elasticsearch';
171
+ *
172
+ * const client = new Client({ node: 'http://localhost:9200' });
173
+ * const store = new ElasticSearchStore({ id: 'my-store', client });
174
+ * ```
175
+ */
176
+ client: Client;
177
+ url?: never;
178
+ auth?: never;
179
+ } | {
180
+ /**
181
+ * ElasticSearch node URL.
182
+ *
183
+ * @example
184
+ * ```typescript
185
+ * const store = new ElasticSearchStore({
186
+ * id: 'my-store',
187
+ * url: 'http://localhost:9200',
188
+ * auth: { apiKey: '...' },
189
+ * });
190
+ * ```
191
+ */
192
+ url: string;
193
+ auth?: ElasticSearchAuth;
194
+ client?: never;
195
+ });
196
+ //#endregion
197
+ //#region src/storage/store.d.ts
198
+ /**
199
+ * ElasticSearch storage adapter for Mastra.
200
+ *
201
+ * Implements the memory, workflows, and scores storage domains on top of
202
+ * ElasticSearch. Shares the same connection config surface as
203
+ * `ElasticSearchVector`, so both can reuse one client or connection config.
204
+ *
205
+ * @example
206
+ * ```typescript
207
+ * // Using connection parameters
208
+ * const storage = new ElasticSearchStore({
209
+ * id: 'my-store',
210
+ * url: 'http://localhost:9200',
211
+ * auth: { apiKey: '...' },
212
+ * });
213
+ *
214
+ * // Access memory domain
215
+ * const memory = await storage.getStore('memory');
216
+ * await memory?.saveThread({ thread });
217
+ * ```
218
+ *
219
+ * @example
220
+ * ```typescript
221
+ * // Using a pre-configured client shared with ElasticSearchVector
222
+ * import { Client } from '@elastic/elasticsearch';
223
+ *
224
+ * const client = new Client({ node: 'http://localhost:9200' });
225
+ * const storage = new ElasticSearchStore({ id: 'my-store', client });
226
+ * const vector = new ElasticSearchVector({ id: 'my-vector', client });
227
+ * ```
228
+ */
229
+ declare class ElasticSearchStore extends MastraStorage {
230
+ private client;
231
+ private shouldManageConnection;
232
+ stores: StorageDomains;
233
+ constructor(config: ElasticSearchConfig);
234
+ getClient(): Client;
235
+ close(): Promise<void>;
236
+ }
237
+ //#endregion
238
+ //#region src/storage/db.d.ts
239
+ interface ElasticSearchDomainConfig {
240
+ client: Client;
241
+ }
242
+ //#endregion
243
+ //#region src/storage/domains/memory/index.d.ts
244
+ declare class MemoryElasticSearch extends MemoryStorage {
245
+ readonly supportsPartialThreadUpdate = true;
246
+ private db;
247
+ constructor(config: ElasticSearchDomainConfig);
248
+ dangerouslyClearAll(): Promise<void>;
249
+ getThreadById({ threadId, resourceId }: {
250
+ threadId: string;
251
+ resourceId?: string;
252
+ }): Promise<StorageThreadType | null>;
253
+ listThreadsByResourceId(args: StorageListThreadsInput): Promise<StorageListThreadsOutput>;
254
+ listThreads(args: StorageListThreadsInput): Promise<StorageListThreadsOutput>;
255
+ saveThread({ thread }: {
256
+ thread: StorageThreadType;
257
+ }): Promise<StorageThreadType>;
258
+ updateThread({ id, title, metadata }: {
259
+ id: string;
260
+ title?: string;
261
+ metadata?: Record<string, unknown>;
262
+ }): Promise<StorageThreadType>;
263
+ deleteThread({ threadId }: {
264
+ threadId: string;
265
+ }): Promise<void>;
266
+ saveMessages(args: {
267
+ messages: MastraDBMessage[];
268
+ }): Promise<{
269
+ messages: MastraDBMessage[];
270
+ }>;
271
+ /**
272
+ * Returns all messages that belong to a thread, sorted in insertion order
273
+ * (createdAt with `_index` tiebreaker).
274
+ */
275
+ private listThreadMessages;
276
+ /** Returns all message documents across all threads (excludes index docs). */
277
+ private listAllMessages;
278
+ private getThreadIdForMessage;
279
+ /**
280
+ * Fetches the messages named by `include` together with their surrounding context.
281
+ *
282
+ * @param include - Message ids to pin, each with an optional before/after window.
283
+ * @param resourceId - When set, drops any pinned or context message owned by another
284
+ * resource so an id from another resource returns nothing.
285
+ */
286
+ private getIncludedMessages;
287
+ private parseStoredMessage;
288
+ listMessagesById({ messageIds }: {
289
+ messageIds: string[];
290
+ }): Promise<{
291
+ messages: MastraDBMessage[];
292
+ }>;
293
+ listMessages(args: StorageListMessagesInput): Promise<StorageListMessagesOutput>;
294
+ getResourceById({ resourceId }: {
295
+ resourceId: string;
296
+ }): Promise<StorageResourceType | null>;
297
+ saveResource({ resource }: {
298
+ resource: StorageResourceType;
299
+ }): Promise<StorageResourceType>;
300
+ updateResource({ resourceId, workingMemory, metadata }: {
301
+ resourceId: string;
302
+ workingMemory?: string;
303
+ metadata?: Record<string, unknown>;
304
+ }): Promise<StorageResourceType>;
305
+ updateMessages(args: {
306
+ messages: (Partial<Omit<MastraDBMessage, 'createdAt'>> & {
307
+ id: string;
308
+ content?: {
309
+ metadata?: MastraMessageContentV2['metadata'];
310
+ content?: MastraMessageContentV2['content'];
311
+ };
312
+ })[];
313
+ }): Promise<MastraDBMessage[]>;
314
+ deleteMessages(messageIds: string[]): Promise<void>;
315
+ private sortThreads;
316
+ cloneThread(args: StorageCloneThreadInput): Promise<StorageCloneThreadOutput>;
317
+ }
318
+ //#endregion
319
+ //#region src/storage/domains/workflows/index.d.ts
320
+ declare class WorkflowsElasticSearch extends WorkflowsStorage {
321
+ private db;
322
+ constructor(config: ElasticSearchDomainConfig);
323
+ supportsConcurrentUpdates(): boolean;
324
+ dangerouslyClearAll(): Promise<void>;
325
+ updateWorkflowResults({ workflowName, runId, stepId, result, requestContext }: {
326
+ workflowName: string;
327
+ runId: string;
328
+ stepId: string;
329
+ result: StepResult<unknown, unknown, unknown, unknown>;
330
+ requestContext: Record<string, unknown>;
331
+ }): Promise<Record<string, StepResult<unknown, unknown, unknown, unknown>>>;
332
+ updateWorkflowState({ workflowName, runId, opts }: {
333
+ workflowName: string;
334
+ runId: string;
335
+ opts: UpdateWorkflowStateOptions;
336
+ }): Promise<WorkflowRunState | undefined>;
337
+ persistWorkflowSnapshot(params: {
338
+ namespace?: string;
339
+ workflowName: string;
340
+ runId: string;
341
+ resourceId?: string;
342
+ snapshot: WorkflowRunState;
343
+ createdAt?: Date;
344
+ updatedAt?: Date;
345
+ }): Promise<void>;
346
+ loadWorkflowSnapshot(params: {
347
+ namespace: string;
348
+ workflowName: string;
349
+ runId: string;
350
+ }): Promise<WorkflowRunState | null>;
351
+ getWorkflowRunById({ runId, workflowName }: {
352
+ runId: string;
353
+ workflowName?: string;
354
+ }): Promise<WorkflowRun | null>;
355
+ deleteWorkflowRunById({ runId, workflowName }: {
356
+ runId: string;
357
+ workflowName: string;
358
+ }): Promise<void>;
359
+ listWorkflowRuns({ workflowName, fromDate, toDate, perPage, page, resourceId, status }?: StorageListWorkflowRunsInput): Promise<WorkflowRuns>;
360
+ }
361
+ //#endregion
362
+ //#region src/storage/domains/scores/index.d.ts
363
+ declare class ScoresElasticSearch extends ScoresStorage {
364
+ private db;
365
+ constructor(config: ElasticSearchDomainConfig);
366
+ dangerouslyClearAll(): Promise<void>;
367
+ getScoreById({ id }: {
368
+ id: string;
369
+ }): Promise<ScoreRowData | null>;
370
+ listScoresByScorerId({ scorerId, entityId, entityType, source, pagination, filters }: {
371
+ scorerId: string;
372
+ entityId?: string;
373
+ entityType?: string;
374
+ source?: ScoringSource;
375
+ pagination?: StoragePagination;
376
+ filters?: ScoreTenancyFilters;
377
+ }): Promise<{
378
+ scores: ScoreRowData[];
379
+ pagination: PaginationInfo;
380
+ }>;
381
+ saveScore(score: SaveScorePayload): Promise<{
382
+ score: ScoreRowData;
383
+ }>;
384
+ listScoresByRunId({ runId, pagination, filters }: {
385
+ runId: string;
386
+ pagination?: StoragePagination;
387
+ filters?: ScoreTenancyFilters;
388
+ }): Promise<{
389
+ scores: ScoreRowData[];
390
+ pagination: PaginationInfo;
391
+ }>;
392
+ listScoresByEntityId({ entityId, entityType, pagination, filters }: {
393
+ entityId: string;
394
+ entityType?: string;
395
+ pagination?: StoragePagination;
396
+ filters?: ScoreTenancyFilters;
397
+ }): Promise<{
398
+ scores: ScoreRowData[];
399
+ pagination: PaginationInfo;
400
+ }>;
401
+ listScoresBySpan({ traceId, spanId, pagination, filters }: {
402
+ traceId: string;
403
+ spanId: string;
404
+ pagination?: StoragePagination;
405
+ filters?: ScoreTenancyFilters;
406
+ }): Promise<{
407
+ scores: ScoreRowData[];
408
+ pagination: PaginationInfo;
409
+ }>;
410
+ private fetchAndFilterScores;
411
+ }
412
+ //#endregion
413
+ export { type ElasticSearchAuth, type ElasticSearchConfig, ElasticSearchStore, ElasticSearchVector, type ElasticSearchVectorConfig, type ElasticSearchVectorFilter, MemoryElasticSearch, ScoresElasticSearch, WorkflowsElasticSearch };
142
414
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","names":[],"sources":["../src/vector/filter.ts","../src/vector/index.ts"],"mappings":";;;;KAUK,gCAAgC,KAAK;KAErC,uCAAuC,KAAK;KAE5C,2BAA2B;KAEpB,4BAA4B,mBAChC,+BACN,+BACA,sCACA;;;KCaG,4BAA4B,kBAAkB;KAEvC;EAAsB;;EAAqB;EAAkB;;EAAuB;;KAEpF;EACN;EAAY,QAAQ;EAAqB;EAAa;;EACtD;EAAY;EAAa,OAAO;EAAmB;;cAE5C,4BAA4B,aAAa;UAC5C;;;;;;;;EASI,YAAA,QAAQ;;;;;;;;;EA6Bd,cAAc,WAAW,WAAW,UAAqB,oBAAoB;;;;;;EAkD7E,eAAe;;;;;YAwBL,sBAAsB,mBAAmB,mBAAmB,iBAAiB;;;;;;;EAoDvF,gBAAgB,aAAa,sBAAsB,QAAQ;;;;;;;EAqB3D,cAAc,aAAa,oBAAoB;;;;;;;;;;EA4B/C,SAAS,WAAW,SAAS,UAAe,OAAO,qBAAqB;;;;;;;;;;;EA+HxE,QACJ,WACA,aACA,QACA,MACA,iBACC,4BAA4B,QAAQ;;;;;;;;UA+D/B;;;;;;;UAYA;;;;;;;;;;;EAeF,aAAa,QAAQ,mBAAmB,6BAA6B;;;;UAwD7D;;;;UAuFA;;;;;;;;EAyDR,eAAe,WAAW,MAAM,qBAAqB;EA2BrD,gBAAgB,WAAW,QAAQ,OAAO,oBAAoB,6BAA6B"}
1
+ {"version":3,"file":"index.d.ts","names":[],"sources":["../src/vector/filter.ts","../src/vector/index.ts","../src/storage/types.ts","../src/storage/store.ts","../src/storage/db.ts","../src/storage/domains/memory/index.ts","../src/storage/domains/workflows/index.ts","../src/storage/domains/scores/index.ts"],"mappings":";;;;;;;;;KAUK,gCAAgC,KAAK;KAErC,uCAAuC,KAAK;KAE5C,2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