@mastra/factory 0.29.1-alpha.1 → 0.30.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.
Files changed (43) hide show
  1. package/README.md +1 -1
  2. package/dist/factory.d.ts +13 -4
  3. package/dist/factory.d.ts.map +1 -1
  4. package/dist/factory.js +21 -5
  5. package/dist/factory.js.map +1 -1
  6. package/dist/routes/contracts.d.ts +8 -0
  7. package/dist/routes/contracts.d.ts.map +1 -1
  8. package/dist/routes/contracts.js +3 -1
  9. package/dist/routes/contracts.js.map +1 -1
  10. package/dist/routes/knowledge.d.ts +8 -5
  11. package/dist/routes/knowledge.d.ts.map +1 -1
  12. package/dist/routes/knowledge.js +25 -3
  13. package/dist/routes/knowledge.js.map +1 -1
  14. package/dist/routes/run-stop-marker.d.ts +13 -0
  15. package/dist/routes/run-stop-marker.d.ts.map +1 -0
  16. package/dist/routes/run-stop-marker.js +36 -0
  17. package/dist/routes/run-stop-marker.js.map +1 -0
  18. package/dist/routes/session-access.d.ts +1 -0
  19. package/dist/routes/session-access.d.ts.map +1 -1
  20. package/dist/routes/session-access.js +1 -1
  21. package/dist/routes/session-access.js.map +1 -1
  22. package/dist/routes/session-rows.d.ts.map +1 -1
  23. package/dist/routes/session-rows.js +1 -0
  24. package/dist/routes/session-rows.js.map +1 -1
  25. package/dist/routes/surface.d.ts +1 -0
  26. package/dist/routes/surface.d.ts.map +1 -1
  27. package/dist/routes/surface.js +2 -1
  28. package/dist/routes/surface.js.map +1 -1
  29. package/dist/rules/dispatcher.d.ts.map +1 -1
  30. package/dist/rules/dispatcher.js +57 -16
  31. package/dist/rules/dispatcher.js.map +1 -1
  32. package/dist/session/session-row-query.d.ts +6 -0
  33. package/dist/session/session-row-query.d.ts.map +1 -1
  34. package/dist/session/session-row-query.js +6 -2
  35. package/dist/session/session-row-query.js.map +1 -1
  36. package/dist/session/session-row-view.d.ts.map +1 -1
  37. package/dist/session/session-row-view.js +7 -2
  38. package/dist/session/session-row-view.js.map +1 -1
  39. package/dist/storage/domains/work-items/base.d.ts +19 -0
  40. package/dist/storage/domains/work-items/base.d.ts.map +1 -1
  41. package/dist/storage/domains/work-items/base.js +29 -0
  42. package/dist/storage/domains/work-items/base.js.map +1 -1
  43. package/package.json +8 -8
package/README.md CHANGED
@@ -66,7 +66,7 @@ Two reads answer questions about a project's cards without listing them. `GET /w
66
66
 
67
67
  Two more reads serve a board without sending every card. `GET /web/factory/projects/:id/boards/:boardKey/phases` returns one entry per phase of the board in `phases`, in the board's order: `phase` is its id, `total` counts the cards in it, and `cards` names the first of them as `{ id, version }`. `version` names the card's body: it is another value whenever anything in the body is, including a change that leaves `changedAt` as it was. `limit` sets how many each phase names (50 unless given, 200 at most), `window=<phase>:<count>` (repeatable) names more cards of one phase, and `item=<card id>` asks for one card wherever it lies: the answer names it in `item` as `{ id, version, places }`, where `places` gives each phase the view lists it under and its `position` there (how many cards the phase lists before it), and `cards=true` sends its body. No phase names more cards for it, so the answer is the same size for the oldest card of a phase as for the newest. `places` is empty when the search or filters leave the card out, and `item` is absent when the board does not hold the card. `sort` is `recent` (latest entry into the phase first, the default), `recent-mine` (the cards the signed-in user last moved into the phase first), `created-newest` or `created-oldest`. `q` keeps the cards whose title, key, number or source id contains every word in it; `label`, `source`, `linearProject`, `teammate`, `author`, `assignee`, `reviewer` and `worked` (all repeatable) keep the cards matching every field given. `boardTotal` counts the board's cards whatever the search and filters, `matchingTotal` the cards matching them, a card in two phases once. `related` names the cards related to a named card that no phase names, the first `limit` of each card's, and `relatedTotal` counts them all. Pass `cards=true` to also receive the body of every named card in `workItems`, each with its `version`; without it, read the cards whose `version` differs from the copy you kept with `GET /web/factory/projects/:id/work-items?workItemId=<id>`, which sends each card with its `version` too. A card in none of the board's phases is counted in the first one. A malformed parameter is a 400 `invalid_phases_query`; a board the project doesn't have is a 404; a `window` for a phase the board doesn't have is ignored. `GET /web/factory/projects/:id/work-items/filter-options` returns what a board can be filtered by, over every card of the project: `labels`, sorted; `people`, each person a source names as author, assignee or requested reviewer, as `{ id, name, source }`; and `actorIds`, the Factory users who filed, moved or started a card. Both answers carry an `ETag`; send it back as `If-None-Match` and an unchanged answer is a 304.
68
68
 
69
- Two reads serve the sidebar's sessions without sending every session and every card holding one. `GET /web/factory/projects/:id/session-rows` returns the rows of one view of the project's sessions, built on the server: one row per card for a card's sessions (`cardSessionIds` names them all; `children=true` lists the others under the row in `childRows` instead), and one row per session a person or Slack started. Each row carries its `session`, its `status` (`waiting`, `working`, `initializing`, `idle` or `done`), the card it works on, and the card's pull or merge request. `sort` is `activity` (the default), `updated` or `created`; `groupBy` is `none` (the default), `board`, `status` or `owner`; `owner` is `all`, `mine` or `owner:<user id>`; `status` and `updated` (`24h`, `7d` or `30d`) keep the matching rows. `groups` lists the groups holding a matching row, in the order their first row sorts, each with its `key`, its `total` and its first 5 `rows`; `window=<group key>:<count>` (repeatable, 500 at most) lists more of one group. `pin=<session id>` (repeatable) lists sessions before every other one of their group, and `open=<session id>` keeps that session's row listed in its group however deep it lies, with its place in `openIndex`. `total` counts every row, `matching` the rows the filters keep, and `boards` and `owners` name every board and person some row has, whatever the filters. `GET /web/factory/projects/:id/session-activity` returns which sessions are running or waiting on a person's answer, each card's status as its row in `session-rows` shows it in `cardStatuses` (only cards neither idle nor done), the cards one of whose sessions is coming up, running or parked on a person in `sessionHeldCardIds` (no other run may start on those), and how many of the cards in `cardStatuses` are working or waiting. Every write that changes either answer sends a frame on the project's feed, whichever replica made it: read again on a frame. Both carry an `ETag`; send it back as `If-None-Match` and an unchanged answer is a 304. A malformed `session-rows` parameter is a 400 `invalid_session_rows_query`.
69
+ Two reads serve the sidebar's sessions without sending every session and every card holding one. `GET /web/factory/projects/:id/session-rows` returns the rows of one view of the project's sessions, built on the server: one row per card for a card's sessions (`cardSessionIds` names them all; `children=true` lists the others under the row in `childRows` instead), and one row per session a person or Slack started. Each row carries its `session`, its `status` (`waiting`, `working`, `initializing`, `idle` or `done`), the card it works on, and the card's pull or merge request. `sort` is `activity` (the default), `updated` or `created`; `groupBy` is `none` (the default), `board`, `status` or `owner`; `owner` is `all`, `mine` or `owner:<user id>`; `status` and `updated` (`24h`, `7d` or `30d`) keep the matching rows; `source` keeps the rows that start in one place: `board:<board id>` for that board's cards, `user` for sessions a person started, `slack` for those Slack started, the same keys `groupBy=board` groups under. `groups` lists the groups holding a matching row, in the order their first row sorts, each with its `key`, its `total` and its first 5 `rows`; `window=<group key>:<count>` (repeatable, 500 at most) lists more of one group. `pin=<session id>` (repeatable) lists sessions before every other one of their group, and `open=<session id>` keeps that session's row listed in its group however deep it lies, with its place in `openIndex`. `total` counts every row, `matching` the rows the filters keep, and `boards` and `owners` name every board and person some row has, whatever the filters. `GET /web/factory/projects/:id/session-activity` returns which sessions are running or waiting on a person's answer, each card's status as its row in `session-rows` shows it in `cardStatuses` (only cards neither idle nor done), the cards one of whose sessions is coming up, running or parked on a person in `sessionHeldCardIds` (no other run may start on those), and how many of the cards in `cardStatuses` are working or waiting. Every write that changes either answer sends a frame on the project's feed, whichever replica made it: read again on a frame. Both carry an `ETag`; send it back as `If-None-Match` and an unchanged answer is a 304. A malformed `session-rows` parameter is a 400 `invalid_session_rows_query`.
70
70
 
71
71
  #### Migration and dry run
72
72
 
package/dist/factory.d.ts CHANGED
@@ -22,7 +22,7 @@ import type { MastraCodeConfig } from '@mastra/code-sdk';
22
22
  import type { BuiltinToolId } from '@mastra/core/agent-controller';
23
23
  import type { MastraBrowser } from '@mastra/core/browser';
24
24
  import type { PubSub } from '@mastra/core/events';
25
- import type { Knowledge } from '@mastra/core/knowledge';
25
+ import { Knowledge } from '@mastra/core/knowledge';
26
26
  import type { Mastra } from '@mastra/core/mastra';
27
27
  import { RequestContext } from '@mastra/core/request-context';
28
28
  import type { IMastraAuthProvider } from '@mastra/core/server';
@@ -91,13 +91,22 @@ export interface MastraFactoryConfig {
91
91
  */
92
92
  vector?: MastraVector;
93
93
  /**
94
- * Host-owned Knowledge runtime. Factory registers this exact instance under `key` and uses that
95
- * key for its read surfaces. Omitted leaves Mastra Code's experimental default wiring in place.
94
+ * Host-owned Knowledge runtime. Factory registers this exact instance under its `id` and uses that
95
+ * key for its read surfaces; pass `{ key, instance }` to register it under another key. Omitted,
96
+ * Knowledge stays off.
96
97
  */
97
- knowledge?: {
98
+ knowledge?: Knowledge | {
98
99
  key: string;
99
100
  instance: Knowledge;
100
101
  };
102
+ /**
103
+ * The scopes every Knowledge run acts with, like an Agent's `scopes`, such as `['org:acme']`. With an
104
+ * `org:` here, every project's sessions and Knowledge page act with these alone instead of their own
105
+ * `org:` and `project:` scopes, for a Knowledge instance that declares only that org; every org and
106
+ * project on this Factory then shares it. A `resource:` or `thread:` scope throws, since those are
107
+ * each run's own identity, and so does a `project:` beside an `org:`.
108
+ */
109
+ scopes?: string[];
101
110
  /**
102
111
  * Distributed event bus instance (e.g. `new RedisStreamsPubSub({ url })`).
103
112
  * When set, streams/workflows/signals ride it across processes and the
@@ -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;AAGzD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AACnE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAG1D,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAClD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AACxD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAClD,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAE9D,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAC/D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AACv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E,gBAAgB,EAAE,CAAC;QAAC,SAAS,EAAE,gBAAgB,EAAE,CAAA;KAAE,CAAC,CA+CvG;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,CAm1DnC;IAED;;;;OAIG;IACG,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC,CA0B9B;IAiBD,oGAAoG;IAC9F,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC,CAqD9B;CACF"}
package/dist/factory.js CHANGED
@@ -33,6 +33,7 @@ import { createCustomProvidersPrimer, primeCustomProvidersForRequestContext, reg
33
33
  import { buildFeedEventsRoutes } from "./routes/feed-events.js";
34
34
  import { ProjectRoutes } from "./routes/projects.js";
35
35
  import { tenantOrgId } from "./routes/provider-credentials.js";
36
+ import { createRunStopMarker } from "./routes/run-stop-marker.js";
36
37
  import { SandboxEnvRoutes } from "./routes/sandbox-envs.js";
37
38
  import { createSessionAccessGuard } from "./routes/session-access.js";
38
39
  import { assembleFactoryApiRoutes, buildIntegrationContext } from "./routes/surface.js";
@@ -47,19 +48,19 @@ import { createTerminalStageCleanup } from "./rules/terminal-cleanup.js";
47
48
  import { createFactoryTransitionTools } from "./rules/tools.js";
48
49
  import { FactoryTransitionService } from "./rules/transition-service.js";
49
50
  import { assertFactoryConfigVersion } from "./rules/validation.js";
50
- import { CallbackFactorySandbox } from "./sandbox/callback-factory-sandbox.js";
51
51
  import { resolveFactoryToolScope } from "./tools/scope.js";
52
+ import { CallbackFactorySandbox } from "./sandbox/callback-factory-sandbox.js";
52
53
  import { controllerRunInFlight, createContextSandboxStops, createTerminalSandboxStops } from "./sandbox/context-sandboxes.js";
53
54
  import { isValidGitRef } from "./sandbox/git-ref.js";
54
55
  import { LocalFactorySandbox } from "./sandbox/local-factory-sandbox.js";
55
56
  import { CachedSandboxEnvs } from "./sandbox/sandbox-env-cache.js";
56
57
  import { SessionRetirementCoordinator } from "./sandbox/session-retirement.js";
57
- import { peekSessionSandbox } from "./sandbox/session-sandbox.js";
58
58
  import { applyFactoryToolPermissions } from "./tools/permissions.js";
59
+ import { peekSessionSandbox } from "./sandbox/session-sandbox.js";
59
60
  import { createPlaintextFactorySecretEncryption } from "./secret-encryption.js";
60
61
  import { handleServerError } from "./server-error.js";
61
- import { resolveFactoryCredentialTenant, resolveFactoryModelPolicy } from "./session/credential-policy.js";
62
62
  import { metricsService, resolveMetricsConfig } from "./metrics/config.js";
63
+ import { resolveFactoryCredentialTenant, resolveFactoryModelPolicy } from "./session/credential-policy.js";
63
64
  import { hydrateSessionDefaultModel } from "./session/default-model-hydration.js";
64
65
  import { environmentSlugs, resolveSessionRepositories } from "./session/environment-repositories.js";
65
66
  import { FactoryEnvironmentStateProcessor } from "./session/environment-state-processor.js";
@@ -119,8 +120,10 @@ import { EventEmitterPubSub } from "@mastra/core/events";
119
120
  import { existsSync } from "fs";
120
121
  import { prepareAgentControllerMount } from "@mastra/code-sdk";
121
122
  import { getDynamicMemory } from "@mastra/code-sdk/agents/memory";
123
+ import { resolveKnowledgeSessionScopes } from "@mastra/code-sdk/knowledge-scope";
122
124
  import { getGlobalMcpPath } from "@mastra/code-sdk/mcp/config";
123
125
  import { AgentControllerChannels } from "@mastra/core/channels";
126
+ import { Knowledge } from "@mastra/core/knowledge";
124
127
  import { readObjective, resolveGoalStore, writeObjective } from "@mastra/core/tools";
125
128
  import { describeFactorySandbox, isFactorySandbox } from "@mastra/core/workspace";
126
129
  // src/factory.ts
@@ -288,6 +291,8 @@ var MastraFactory = class {
288
291
  #preparing = false;
289
292
  constructor(config) {
290
293
  if (!config?.storage) throw new Error("MastraFactory: 'storage' is required. Pass a FactoryStorage backend — e.g. new PgFactoryStorage({ connectionString }) from '@mastra/pg' for deployments, or new LibSQLFactoryStorage({ url }) from '@mastra/libsql' for local dev.");
294
+ const hostScopes = resolveKnowledgeSessionScopes({ factoryOrgId: "factory" }, config.scopes);
295
+ if (!hostScopes.resolved) throw new Error(`MastraFactory: 'scopes': ${hostScopes.reason}`);
291
296
  if (config.includeDefaultBoards !== void 0) warnIncludeDefaultBoards();
292
297
  this.#boards = createBoardRegistry({ boards: config.boards });
293
298
  warnDefinedBoards(this.#boards);
@@ -297,7 +302,10 @@ var MastraFactory = class {
297
302
  this.#forcedIntake = intakeEvaluatorFrom(process.env);
298
303
  for (const problem of findBoardSkillProblems(this.#boards, this.#skills)) console.warn(`[factory] ${problem}`);
299
304
  this.#configVersion = assertFactoryConfigVersion(config.configVersion ?? "factory-config-v1");
300
- this.#config = config;
305
+ this.#config = {
306
+ ...config,
307
+ ...config.scopes && { scopes: [...config.scopes] }
308
+ };
301
309
  this.#metrics = new FactoryMetrics(resolveMetricsConfig(config.metrics), metricsService());
302
310
  installFactoryMetrics(this.#metrics);
303
311
  }
@@ -1196,6 +1204,7 @@ var MastraFactory = class {
1196
1204
  disableScoreStorage: this.#config.disableScoreStorage ?? true,
1197
1205
  ...mastraStorageBackend ? { storageBackend: mastraStorageBackend } : {},
1198
1206
  knowledge: this.#config.knowledge ?? false,
1207
+ scopes: this.#config.scopes,
1199
1208
  inputProcessors: async ({ requestContext }) => {
1200
1209
  const environmentProcessor = new FactoryEnvironmentStateProcessor();
1201
1210
  const sessionsProcessor = workItemsStorage && storage.isDomainReady("source-control") ? [new FactorySessionsStateProcessor({
@@ -1436,7 +1445,8 @@ var MastraFactory = class {
1436
1445
  mcpEnabled,
1437
1446
  deploymentModelProviders,
1438
1447
  skills: this.#skills,
1439
- knowledgeKey: this.#config.knowledge?.key,
1448
+ knowledgeKey: this.#config.knowledge instanceof Knowledge ? this.#config.knowledge.id : this.#config.knowledge?.key.trim(),
1449
+ knowledgeScopes: this.#config.scopes,
1440
1450
  configVersion,
1441
1451
  boardRegistry: boards,
1442
1452
  intakeEvaluator: this.#forcedIntake,
@@ -1547,10 +1557,15 @@ var MastraFactory = class {
1547
1557
  const spa = uiDist ? [createSpaStaticMiddleware(uiDist)] : [];
1548
1558
  const timing = factoryTimingEnabled ? [createRequestTimingMiddleware()] : [];
1549
1559
  const sessionActivity = createSessionActivityMiddleware(() => this.#sessionUnloader);
1560
+ const runStopMarker = createRunStopMarker({
1561
+ auth: routeAuth,
1562
+ workItems: () => storage.isDomainReady("work-items") ? workItemsStorage : void 0
1563
+ });
1550
1564
  if (!auth) return {
1551
1565
  middleware: [
1552
1566
  ...timing,
1553
1567
  sessionActivity,
1568
+ runStopMarker,
1554
1569
  createFactoryInteractiveMarker(),
1555
1570
  createCustomProvidersPrimer({
1556
1571
  auth: routeAuth,
@@ -1577,6 +1592,7 @@ var MastraFactory = class {
1577
1592
  } },
1578
1593
  controller: () => this.#prepared?.base.controller
1579
1594
  }),
1595
+ runStopMarker,
1580
1596
  sessionActivity,
1581
1597
  createTenantCredentialPrimer({
1582
1598
  auth: routeAuth,