@mastra/factory 0.29.0-alpha.1 → 0.29.0-alpha.3
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/README.md +40 -1
- package/dist/factory.d.ts +8 -0
- package/dist/factory.d.ts.map +1 -1
- package/dist/factory.js +26 -2
- package/dist/factory.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/integrations/github/reconcile-worker.d.ts.map +1 -1
- package/dist/integrations/github/reconcile-worker.js +30 -1
- package/dist/integrations/github/reconcile-worker.js.map +1 -1
- package/dist/integrations/github/rules.d.ts.map +1 -1
- package/dist/integrations/github/rules.js +17 -3
- package/dist/integrations/github/rules.js.map +1 -1
- package/dist/integrations/github/sandbox.d.ts.map +1 -1
- package/dist/integrations/github/sandbox.js +11 -2
- package/dist/integrations/github/sandbox.js.map +1 -1
- package/dist/integrations/linear/rules.d.ts.map +1 -1
- package/dist/integrations/linear/rules.js +11 -0
- package/dist/integrations/linear/rules.js.map +1 -1
- package/dist/metrics/collectors/postgres.d.ts +29 -0
- package/dist/metrics/collectors/postgres.d.ts.map +1 -0
- package/dist/metrics/collectors/postgres.js +121 -0
- package/dist/metrics/collectors/postgres.js.map +1 -0
- package/dist/metrics/collectors/probe.d.ts +22 -0
- package/dist/metrics/collectors/probe.d.ts.map +1 -0
- package/dist/metrics/collectors/probe.js +69 -0
- package/dist/metrics/collectors/probe.js.map +1 -0
- package/dist/metrics/collectors/process.d.ts +13 -0
- package/dist/metrics/collectors/process.d.ts.map +1 -0
- package/dist/metrics/collectors/process.js +85 -0
- package/dist/metrics/collectors/process.js.map +1 -0
- package/dist/metrics/collectors/redis.d.ts +29 -0
- package/dist/metrics/collectors/redis.d.ts.map +1 -0
- package/dist/metrics/collectors/redis.js +97 -0
- package/dist/metrics/collectors/redis.js.map +1 -0
- package/dist/metrics/config.d.ts +33 -0
- package/dist/metrics/config.d.ts.map +1 -0
- package/dist/metrics/config.js +65 -0
- package/dist/metrics/config.js.map +1 -0
- package/dist/metrics/index.d.ts +20 -0
- package/dist/metrics/index.d.ts.map +1 -0
- package/dist/metrics/index.js +65 -0
- package/dist/metrics/index.js.map +1 -0
- package/dist/metrics/intake.d.ts +28 -0
- package/dist/metrics/intake.d.ts.map +1 -0
- package/dist/metrics/intake.js +76 -0
- package/dist/metrics/intake.js.map +1 -0
- package/dist/metrics/metrics.d.ts +60 -0
- package/dist/metrics/metrics.d.ts.map +1 -0
- package/dist/metrics/metrics.js +182 -0
- package/dist/metrics/metrics.js.map +1 -0
- package/dist/metrics/sandbox.d.ts +35 -0
- package/dist/metrics/sandbox.d.ts.map +1 -0
- package/dist/metrics/sandbox.js +156 -0
- package/dist/metrics/sandbox.js.map +1 -0
- package/dist/routes/surface.d.ts.map +1 -1
- package/dist/routes/surface.js +1 -0
- package/dist/routes/surface.js.map +1 -1
- package/dist/rules/dispatcher.d.ts +1 -0
- package/dist/rules/dispatcher.d.ts.map +1 -1
- package/dist/rules/dispatcher.js +26 -8
- package/dist/rules/dispatcher.js.map +1 -1
- package/dist/rules/start-coordinator.d.ts +1 -0
- package/dist/rules/start-coordinator.d.ts.map +1 -1
- package/dist/rules/start-coordinator.js +1 -0
- package/dist/rules/start-coordinator.js.map +1 -1
- package/dist/rules/types.d.ts +2 -2
- package/dist/rules/types.d.ts.map +1 -1
- package/dist/rules/types.js +4 -1
- package/dist/rules/types.js.map +1 -1
- package/dist/rules/validation.d.ts.map +1 -1
- package/dist/rules/validation.js +1 -0
- package/dist/rules/validation.js.map +1 -1
- package/dist/sandbox/session-retirement.d.ts.map +1 -1
- package/dist/sandbox/session-retirement.js +22 -14
- package/dist/sandbox/session-retirement.js.map +1 -1
- package/dist/sandbox/session-sandbox.d.ts +2 -0
- package/dist/sandbox/session-sandbox.d.ts.map +1 -1
- package/dist/sandbox/session-sandbox.js +7 -1
- package/dist/sandbox/session-sandbox.js.map +1 -1
- package/dist/storage/domains/work-items/base.d.ts +5 -0
- package/dist/storage/domains/work-items/base.d.ts.map +1 -1
- package/dist/storage/domains/work-items/base.js +19 -2
- package/dist/storage/domains/work-items/base.js.map +1 -1
- package/dist/timing.d.ts +4 -1
- package/dist/timing.d.ts.map +1 -1
- package/dist/timing.js +12 -4
- package/dist/timing.js.map +1 -1
- package/dist/work-item-branch.d.ts +1 -1
- package/dist/work-item-branch.d.ts.map +1 -1
- package/dist/work-item-branch.js +1 -0
- package/dist/work-item-branch.js.map +1 -1
- package/dist/workspace.d.ts.map +1 -1
- package/dist/workspace.js +7 -1
- package/dist/workspace.js.map +1 -1
- package/package.json +6 -6
package/README.md
CHANGED
|
@@ -84,6 +84,45 @@ Dry-run mode is only for pre-cutover databases. Once any split board items exist
|
|
|
84
84
|
|
|
85
85
|
During mixed-version deployments, a changed legacy row is recopied only while its split records still match the migration baseline. Conflicting split-side edits are skipped and logged rather than overwritten. Legacy claim values remain inert and are not copied into split storage. Avoid simultaneous writes from old and new versions during the cutover.
|
|
86
86
|
|
|
87
|
+
### Health metrics
|
|
88
|
+
|
|
89
|
+
Factory can send health metrics through `mastra.metrics` (so through whatever observability exporter the Mastra instance has; on Mastra Platform that's added for you). They're off by default: every record counts towards observability usage, so you turn on only the groups you want.
|
|
90
|
+
|
|
91
|
+
See [Health metrics](https://factory.mastra.ai/configure/metrics) for what each metric means, its unit, and how to read it when Factory is slow.
|
|
92
|
+
|
|
93
|
+
```ts
|
|
94
|
+
new MastraFactory({
|
|
95
|
+
// ...
|
|
96
|
+
metrics: {
|
|
97
|
+
groups: ['process', 'postgres', 'sandbox'], // or 'all'
|
|
98
|
+
intervalMs: 60_000, // default 60s, minimum 15s
|
|
99
|
+
maxRecordsPerMinute: 500, // default 500 per process
|
|
100
|
+
},
|
|
101
|
+
});
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
Env vars override the code option:
|
|
105
|
+
|
|
106
|
+
| Variable | Meaning |
|
|
107
|
+
| ----------------------------- | -------------------------------------------------------------------------- |
|
|
108
|
+
| `FACTORY_METRICS` | `all`, `0`/`off` (turns metrics off), or a list such as `sandbox,intake` |
|
|
109
|
+
| `FACTORY_METRICS_INTERVAL_MS` | How often gauges are sampled and aggregated timings are sent (min 15000) |
|
|
110
|
+
| `FACTORY_METRICS_MAX_PER_MIN` | Most records sent per minute per process; the rest are dropped and counted |
|
|
111
|
+
|
|
112
|
+
A group that's off does nothing: no timers, no probes, no connections, no records. Unknown group names are logged once at boot.
|
|
113
|
+
|
|
114
|
+
| Group | Series (all prefixed `mastra_factory_`) |
|
|
115
|
+
| ---------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
|
|
116
|
+
| `process` | `event_loop_delay_ms{stat}`, `event_loop_utilization`, `gc_ms{kind=major\|incremental}`, `process_memory_bytes{kind=rss\|heap_used\|heap_limit}`, `process_heap_utilization` (heap used ÷ limit, 0 to 1), `process_cpu_cores` (cores used across all threads, can exceed 1; compare with `process_cpu_limit_cores`), `process_cpu_limit_cores`, `process_uptime_ms` |
|
|
117
|
+
| `postgres` | `db_pool{pool,state}`, `probe_duration_ms` / `probe_failures_total` for `db_<pool>` (a pool that closed its idle connections opens one for the probe, so its duration can include connecting), `db_sessions{state}`, `db_longest_ms{kind}`; the statements that used the most time are logged every 10 minutes when `pg_stat_statements` is installed (other users' statements need the `pg_read_all_stats` role) |
|
|
118
|
+
| `redis` | `probe_duration_ms{component=redis}`, `redis_memory_bytes{kind=used\|max}` (`max` only when `maxmemory` is set), `redis_memory_utilization` (used ÷ `maxmemory`, only when set), `redis_clients`, `redis_evicted_keys_total`, `redis_stream_backlog{topic,kind}`; only with `RedisStreamsPubSub`, and only the probe on a cluster |
|
|
119
|
+
| `sandbox` | `session_ready_ms{kind=first\|resume,outcome}` (a start, from the first request to the end of the onStart hook, failures included), `session_sandbox_wait_ms{kind,outcome}` (how long the first caller other than the eager start waited for it), `sessions_starting` and `session_start_oldest_age_ms` (starts in flight, sent every interval), `sandbox_start_ms{sandbox_provider,outcome}`, `sandbox_start_failures_total{sandbox_provider,cause}` (sent as 0 once a sandbox has been created), `sandbox_phase_ms{phase,outcome}`, `sandbox_command_ms{step,outcome}`, `sandbox_recreated_total{kind}`, `sandbox_retired_total`, `sandboxes_active` |
|
|
120
|
+
| `intake` | `intake_events_total{source,outcome}` (`committed` and `error` sent as 0 for each configured GitHub or Linear integration), `intake_replayed_total{source,kind}` (each one is a missed webhook), `intake_sweep_failures_total{source,kind}` (sent as 0 once the sweep worker starts), `intake_last_sweep_age_ms{source,kind}` (counted from when the sweep worker starts; no series means no sweep worker runs in that process) |
|
|
121
|
+
|
|
122
|
+
Counts and timings are aggregated in the process and sent once per interval: a counter is one record per series, a timing is `stat=avg|p95|max` on its `_ms` series, which is always in milliseconds, plus a `<name>_count` series with the number of observations (for example `session_ready_ms_count`). Those stats are per interval and per process: p95 values can't be averaged across intervals or processes, so chart the worst p95 per time bucket, use `max` for the worst case and `_count` to weight averages. `event_loop_delay_ms` has the same shape, where `event_loop_delay_ms_count` is the number of delay samples. Every duration is in milliseconds. Event counts and timings are sent before gauges, so the cap drops gauges first. Records past the per-minute cap are dropped and counted in `mastra_factory_metrics_dropped_total`. Labels only take values from fixed lists; IDs, paths and repository names are never sent.
|
|
123
|
+
|
|
124
|
+
Every record has a `service` label read from `MASTRA_WORKERS`: `api` when it's `false`, `worker` when it's set to anything else, `all` when unset. On a split deployment (API plus worker service) the database-wide and Redis-wide stats (`db_sessions`, `db_longest_ms`, slow statements, `redis_memory_bytes`, `redis_clients`, `redis_evicted_keys_total`, `redis_stream_backlog`) run only on `worker`, so they aren't reported twice. `intake_last_sweep_age_ms` only advances on the process that ran the sweep, so take the minimum across processes.
|
|
125
|
+
|
|
87
126
|
### Product telemetry
|
|
88
127
|
|
|
89
128
|
Factory records `factory_web_activity` in Mastra's existing PostHog project for users signed in through the default `mastra-studio` auth provider. The browser sends only a known page category and an activity type to the authenticated `/web/telemetry/activity` endpoint. The server adds the verified account and deployment context.
|
|
@@ -547,7 +586,7 @@ A new pull request or merge request that belongs to a card already on a board th
|
|
|
547
586
|
|
|
548
587
|
When Factory first sees a pull request (GitHub `pull_request.opened`) or merge request (GitLab `open`), it looks for a home card in the same Factory project and repository. The home card must be on a board that reviews pull requests, not in one of its terminal phases, and not a pull request's own card. Factory checks, in order:
|
|
549
588
|
|
|
550
|
-
1. **A pull request Factory opened for one of its cards** goes to that card, found by provenance or by the head branch matching the card's session branch. On GitHub
|
|
589
|
+
1. **A pull request Factory opened for one of its cards** goes to that card, found by provenance or by the head branch matching the card's session branch. On GitHub the card must own an issue of its own: a GitHub card must be from the same repository, while a card whose issue lives in Jira, Linear or incident.io carries no repository to match against and is taken as it is. On GitLab, any card with an issue of its own (GitLab, Linear, Jira or incident.io). A card from the other forge never takes one (a GitLab card keeps only merge requests), and neither does a manual card, since the pull request would become its only source; its pull request gets a separate card. A card still in Building moves to the board's pull request review phase (on a board with self-review, that phase opens the pull request itself, so it has been skipped). A review request or `@<app> review` still sends it there.
|
|
551
590
|
2. **A pull request that closes an issue** can join that issue's card if a project [intake route](#intake-routes) with a `joinClosedIssue` target says so. Factory reads closing keywords from the pull request body or merge request description: `close`, `closes`, `closed`, `fix`, `fixes`, `fixed`, `resolve`, `resolves`, `resolved`, and on GitLab also `implement`, `implements`, `implemented`, `implementing`. The target is `#N`, or `owner/repo#N` (`group/project#N`) naming the same repository. References to other repositories, links, and code spans don't count. If the pull request names several issues, the first one with an eligible card is the one routes see. The default route joins a trusted author's pull request to a card still waiting in Intake with no pull request yet, and moves that card to Review. Once the card has moved on (Triage, Planning or Building), or already carries a pull request, someone else's pull request gets its own card in Review and is reviewed right away. Done and Canceled cards are finished, so a pull request for them gets its own card too.
|
|
552
591
|
3. **Anything else** gets its own card, exactly as before.
|
|
553
592
|
|
package/dist/factory.d.ts
CHANGED
|
@@ -34,6 +34,7 @@ import type { InstalledBoard } from './boards/index.js';
|
|
|
34
34
|
import type { FactoryIntegration, IntegrationTools } from './integrations/base.js';
|
|
35
35
|
import type { GithubRuleOverrides } from './integrations/github/default-rules.js';
|
|
36
36
|
import type { FactoryMcpConfig } from './mcp/routes.js';
|
|
37
|
+
import type { FactoryMetricsOptions } from './metrics/index.js';
|
|
37
38
|
import type { MastraFactorySandboxOption } from './sandbox/session-sandbox.js';
|
|
38
39
|
import type { FactorySecretEncryption } from './secret-encryption.js';
|
|
39
40
|
import type { ReviewedChangeRequest } from './session/source-control-tools.js';
|
|
@@ -96,6 +97,13 @@ export interface MastraFactoryConfig {
|
|
|
96
97
|
* leases. Omitted → in-process default.
|
|
97
98
|
*/
|
|
98
99
|
pubsub?: PubSub;
|
|
100
|
+
/**
|
|
101
|
+
* Factory health metrics, sent through `mastra.metrics` (off by default: every record counts
|
|
102
|
+
* towards observability usage). Pick groups — `process`, `postgres`, `redis`, `sandbox`,
|
|
103
|
+
* `sessions`, `intake` — or `'all'`. Env overrides: `FACTORY_METRICS` (`all`, `0`, or a list
|
|
104
|
+
* like `sandbox,intake`), `FACTORY_METRICS_INTERVAL_MS`, `FACTORY_METRICS_MAX_PER_MIN`.
|
|
105
|
+
*/
|
|
106
|
+
metrics?: FactoryMetricsOptions;
|
|
99
107
|
/**
|
|
100
108
|
* Browser-facing origin used to build integration OAuth/install callback
|
|
101
109
|
* URLs and to derive the auth redirect URI. On the platform the SPA is
|
package/dist/factory.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"factory.d.ts","sourceRoot":"","sources":["../src/factory.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAMH,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAIzD,OAAO,KAAK,EAAiC,aAAa,EAAE,MAAM,+BAA+B,CAAC;AAClG,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAG1D,OAAO,KAAK,EAAE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,EAAE,CAAA;KAAE,CAAC,CA6CvG;IAED;;;;;;;;;;;;;;;;;;;;OAoBG;IACG,qBAAqB,CAAC,cAAc,EAAE,cAAc,GAAG,OAAO,CAAC,qBAAqB,GAAG,SAAS,CAAC,CAKtG;IAED;;;;OAIG;IACG,OAAO,IAAI,OAAO,CAAC,UAAU,CAAC,CAmuDnC;IAED;;;;OAIG;IACG,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC,CAyB9B;IAiBD,oGAAoG;IAC9F,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC,CA+C9B;CACF"}
|
package/dist/factory.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { FactoryMetrics, installFactoryMetrics } from "./metrics/metrics.js";
|
|
1
2
|
import { buildAuthDisabledRoutes, buildAuthRoutes, createFactoryAuthGate, createFactoryInteractiveMarker, createFactoryRouteAuth, getFactoryAuthOrgId, getFactoryAuthUserFromContext, getFactoryAuthUserId } from "./auth.js";
|
|
2
3
|
import { publishBoardChange, subscribeBoardChanges } from "./board-changes.js";
|
|
3
4
|
import { BoardWriteError, BoardWrites } from "./boards/board-writes.js";
|
|
@@ -23,6 +24,7 @@ import { logIntegrationSummary } from "./integrations/startup-summary.js";
|
|
|
23
24
|
import { createSessionAsRowOwner, prepareSessionRunContext } from "./integrations/subscription-session.js";
|
|
24
25
|
import { shareLinkedRepositoryChanges } from "./linked-repositories-changed.js";
|
|
25
26
|
import { buildFactoryMcpRoutes, resolveMcpAuthorizationServers } from "./mcp/routes.js";
|
|
27
|
+
import { startFactoryMetrics } from "./metrics/index.js";
|
|
26
28
|
import { resolveDeploymentModelProviders } from "./routes/config.js";
|
|
27
29
|
import { createCustomProvidersPrimer, primeCustomProvidersForRequestContext, registerCustomProvidersSource } from "./routes/custom-provider-source.js";
|
|
28
30
|
import { buildFeedEventsRoutes } from "./routes/feed-events.js";
|
|
@@ -43,8 +45,8 @@ import { createFactoryTransitionTools } from "./rules/tools.js";
|
|
|
43
45
|
import { FactoryTransitionService } from "./rules/transition-service.js";
|
|
44
46
|
import { assertFactoryConfigVersion } from "./rules/validation.js";
|
|
45
47
|
import { CallbackFactorySandbox } from "./sandbox/callback-factory-sandbox.js";
|
|
46
|
-
import { controllerRunInFlight, createContextSandboxStops, createTerminalSandboxStops } from "./sandbox/context-sandboxes.js";
|
|
47
48
|
import { resolveFactoryToolScope } from "./tools/scope.js";
|
|
49
|
+
import { controllerRunInFlight, createContextSandboxStops, createTerminalSandboxStops } from "./sandbox/context-sandboxes.js";
|
|
48
50
|
import { isValidGitRef } from "./sandbox/git-ref.js";
|
|
49
51
|
import { LocalFactorySandbox } from "./sandbox/local-factory-sandbox.js";
|
|
50
52
|
import { CachedSandboxEnvs } from "./sandbox/sandbox-env-cache.js";
|
|
@@ -52,9 +54,10 @@ import { SessionRetirementCoordinator } from "./sandbox/session-retirement.js";
|
|
|
52
54
|
import { peekSessionSandbox } from "./sandbox/session-sandbox.js";
|
|
53
55
|
import { createPlaintextFactorySecretEncryption } from "./secret-encryption.js";
|
|
54
56
|
import { handleServerError } from "./server-error.js";
|
|
55
|
-
import { resolveFactoryCredentialTenant, resolveFactoryModelPolicy } from "./session/credential-policy.js";
|
|
56
57
|
import { applyFactoryToolPermissions } from "./tools/permissions.js";
|
|
58
|
+
import { resolveFactoryCredentialTenant, resolveFactoryModelPolicy } from "./session/credential-policy.js";
|
|
57
59
|
import { hydrateSessionDefaultModel } from "./session/default-model-hydration.js";
|
|
60
|
+
import { metricsService, resolveMetricsConfig } from "./metrics/config.js";
|
|
58
61
|
import { environmentSlugs, resolveSessionRepositories } from "./session/environment-repositories.js";
|
|
59
62
|
import { FactoryEnvironmentStateProcessor } from "./session/environment-state-processor.js";
|
|
60
63
|
import { createSourceControlSessionLookup } from "./session/factory-session.js";
|
|
@@ -264,6 +267,8 @@ var MastraFactory = class {
|
|
|
264
267
|
#factoryProcessor;
|
|
265
268
|
#channelShutdowns = [];
|
|
266
269
|
#shutdownPromise;
|
|
270
|
+
#metrics;
|
|
271
|
+
#stopMetrics;
|
|
267
272
|
/** Environment builds through the sandbox's `builds`; undefined when the sandbox has none. */
|
|
268
273
|
#environmentBuilds;
|
|
269
274
|
/** The background session resource migration; resolves `true` when it moved run bindings. */
|
|
@@ -283,6 +288,8 @@ var MastraFactory = class {
|
|
|
283
288
|
for (const problem of findBoardSkillProblems(this.#boards, this.#skills)) console.warn(`[factory] ${problem}`);
|
|
284
289
|
this.#configVersion = assertFactoryConfigVersion(config.configVersion ?? "factory-config-v1");
|
|
285
290
|
this.#config = config;
|
|
291
|
+
this.#metrics = new FactoryMetrics(resolveMetricsConfig(config.metrics), metricsService());
|
|
292
|
+
installFactoryMetrics(this.#metrics);
|
|
286
293
|
}
|
|
287
294
|
/**
|
|
288
295
|
* The host sandbox's provider, settings schema (JSON Schema) and
|
|
@@ -1619,9 +1626,23 @@ var MastraFactory = class {
|
|
|
1619
1626
|
await this.#environmentBuilds?.probeSchedules();
|
|
1620
1627
|
this.#sessionResourceMigration?.then((movedRunBindings) => movedRunBindings ? this.#factoryProcessor?.reconcileAllBoundThreads() : void 0).catch((error) => console.warn(`[factory] reconciling bound threads after the session resource migration failed: ${error instanceof Error ? error.message : error}`));
|
|
1621
1628
|
this.#dispatcher?.start();
|
|
1629
|
+
this.#startMetrics();
|
|
1622
1630
|
if (bootDiagnosticsEnabled && this.#prepareStartedAt !== void 0) logTiming(`boot ${Math.round(performance.now() - this.#prepareStartedAt)}ms`);
|
|
1623
1631
|
if (process.env.MASTRA_FACTORY_DEV === "true") logIntegrationSummary(this.#integrations);
|
|
1624
1632
|
}
|
|
1633
|
+
#startMetrics() {
|
|
1634
|
+
if (this.#stopMetrics) return;
|
|
1635
|
+
const getMastra = () => this.#prepared?.base.controller.getMastra();
|
|
1636
|
+
this.#stopMetrics = startFactoryMetrics(this.#metrics, {
|
|
1637
|
+
getMetrics: () => getMastra()?.metrics,
|
|
1638
|
+
getLogger: () => getMastra()?.getLogger()
|
|
1639
|
+
}, {
|
|
1640
|
+
storage: this.#config.storage.getMastraStorage(),
|
|
1641
|
+
vector: this.#config.vector,
|
|
1642
|
+
pubsub: this.#config.pubsub,
|
|
1643
|
+
integrationIds: this.#integrations.map((integration) => integration.id)
|
|
1644
|
+
});
|
|
1645
|
+
}
|
|
1625
1646
|
/** Stop Factory-owned background work and channel transports before the host process shuts down. */
|
|
1626
1647
|
async shutdown() {
|
|
1627
1648
|
if (this.#shutdownPromise) return this.#shutdownPromise;
|
|
@@ -1640,6 +1661,9 @@ var MastraFactory = class {
|
|
|
1640
1661
|
this.#unsubscribeLinkedRepositoryChanges = void 0;
|
|
1641
1662
|
await unsubscribeLinkedRepositoryChanges?.then((unsubscribe) => unsubscribe()).catch(() => void 0);
|
|
1642
1663
|
await unsubscribeDispatchWakes?.then((unsubscribe) => unsubscribe?.()).catch((error) => console.warn(`[factory] unsubscribing from dispatcher wakes failed: ${error instanceof Error ? error.message : error}`));
|
|
1664
|
+
const stopMetrics = this.#stopMetrics;
|
|
1665
|
+
this.#stopMetrics = void 0;
|
|
1666
|
+
await stopMetrics?.().catch(() => void 0);
|
|
1643
1667
|
const backfill = this.#workItemSplitBackfill;
|
|
1644
1668
|
backfill?.controller.abort();
|
|
1645
1669
|
const results = await Promise.allSettled([
|