@mastra/factory 0.28.0-alpha.6 → 0.28.0-alpha.8
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/boards/board-writes.d.ts +1 -1
- package/dist/boards/board-writes.d.ts.map +1 -1
- package/dist/boards/board-writes.js +1 -1
- package/dist/boards/board-writes.js.map +1 -1
- package/dist/environment/build-runner.d.ts.map +1 -1
- package/dist/environment/build-runner.js +2 -2
- package/dist/environment/build-runner.js.map +1 -1
- package/dist/environment/build-workflow.d.ts.map +1 -1
- package/dist/environment/build-workflow.js +6 -5
- package/dist/environment/build-workflow.js.map +1 -1
- package/dist/environment/build.d.ts +15 -2
- package/dist/environment/build.d.ts.map +1 -1
- package/dist/environment/build.js +32 -9
- package/dist/environment/build.js.map +1 -1
- package/dist/factory.d.ts.map +1 -1
- package/dist/factory.js +29 -3
- package/dist/factory.js.map +1 -1
- package/dist/integrations/github/integration.d.ts.map +1 -1
- package/dist/integrations/github/integration.js +7 -3
- package/dist/integrations/github/integration.js.map +1 -1
- package/dist/integrations/github/issue-reconciler.js +2 -2
- package/dist/integrations/github/issue-reconciler.js.map +1 -1
- package/dist/integrations/github/provenance.js +1 -1
- package/dist/integrations/github/provenance.js.map +1 -1
- package/dist/integrations/github/reconcile-worker.d.ts +5 -1
- package/dist/integrations/github/reconcile-worker.d.ts.map +1 -1
- package/dist/integrations/github/reconcile-worker.js +39 -6
- package/dist/integrations/github/reconcile-worker.js.map +1 -1
- package/dist/integrations/github/routes.d.ts +4 -3
- package/dist/integrations/github/routes.d.ts.map +1 -1
- package/dist/integrations/github/routes.js +9 -86
- package/dist/integrations/github/routes.js.map +1 -1
- package/dist/integrations/github/rules.d.ts +67 -0
- package/dist/integrations/github/rules.d.ts.map +1 -1
- package/dist/integrations/github/rules.js +215 -12
- package/dist/integrations/github/rules.js.map +1 -1
- package/dist/integrations/github/sandbox.d.ts +10 -2
- package/dist/integrations/github/sandbox.d.ts.map +1 -1
- package/dist/integrations/github/sandbox.js +20 -4
- package/dist/integrations/github/sandbox.js.map +1 -1
- package/dist/integrations/gitlab/merge-request-reconciler.js +1 -1
- package/dist/integrations/gitlab/merge-request-reconciler.js.map +1 -1
- package/dist/integrations/gitlab/rules.d.ts.map +1 -1
- package/dist/integrations/gitlab/rules.js +6 -5
- package/dist/integrations/gitlab/rules.js.map +1 -1
- package/dist/integrations/incidentio/rules.d.ts.map +1 -1
- package/dist/integrations/incidentio/rules.js +5 -2
- package/dist/integrations/incidentio/rules.js.map +1 -1
- package/dist/integrations/issue-reconciler.js +1 -1
- package/dist/integrations/issue-reconciler.js.map +1 -1
- package/dist/integrations/jira/rules.d.ts.map +1 -1
- package/dist/integrations/jira/rules.js +5 -2
- package/dist/integrations/jira/rules.js.map +1 -1
- package/dist/integrations/linear/rules.d.ts.map +1 -1
- package/dist/integrations/linear/rules.js +2 -2
- package/dist/integrations/linear/rules.js.map +1 -1
- package/dist/integrations/platform/github/event-worker.d.ts +4 -1
- package/dist/integrations/platform/github/event-worker.d.ts.map +1 -1
- package/dist/integrations/platform/github/event-worker.js +39 -3
- package/dist/integrations/platform/github/event-worker.js.map +1 -1
- package/dist/integrations/platform/github/integration.d.ts +8 -0
- package/dist/integrations/platform/github/integration.d.ts.map +1 -1
- package/dist/integrations/platform/github/integration.js +21 -3
- package/dist/integrations/platform/github/integration.js.map +1 -1
- package/dist/integrations/platform/linear/event-worker.d.ts +1 -1
- package/dist/integrations/platform/linear/event-worker.d.ts.map +1 -1
- package/dist/integrations/platform/linear/event-worker.js +1 -1
- package/dist/integrations/platform/linear/event-worker.js.map +1 -1
- package/dist/mcp/routes.js +1 -1
- package/dist/mcp/routes.js.map +1 -1
- package/dist/routes/attention-parked.js +1 -1
- package/dist/routes/attention-parked.js.map +1 -1
- package/dist/routes/board-snapshot.d.ts +15 -0
- package/dist/routes/board-snapshot.d.ts.map +1 -0
- package/dist/routes/board-snapshot.js +41 -0
- package/dist/routes/board-snapshot.js.map +1 -0
- package/dist/routes/boards.d.ts +1 -1
- package/dist/routes/boards.d.ts.map +1 -1
- package/dist/routes/boards.js.map +1 -1
- package/dist/routes/contracts.d.ts +117 -13
- package/dist/routes/contracts.d.ts.map +1 -1
- package/dist/routes/contracts.js +71 -14
- package/dist/routes/contracts.js.map +1 -1
- package/dist/routes/projects.d.ts.map +1 -1
- package/dist/routes/projects.js +70 -60
- package/dist/routes/projects.js.map +1 -1
- package/dist/routes/sandbox-envs.d.ts +26 -0
- package/dist/routes/sandbox-envs.d.ts.map +1 -0
- package/dist/routes/sandbox-envs.js +180 -0
- package/dist/routes/sandbox-envs.js.map +1 -0
- package/dist/routes/session-access.d.ts.map +1 -1
- package/dist/routes/session-access.js +12 -3
- package/dist/routes/session-access.js.map +1 -1
- package/dist/routes/work-items.d.ts.map +1 -1
- package/dist/routes/work-items.js +15 -6
- package/dist/routes/work-items.js.map +1 -1
- package/dist/rules/dispatcher.d.ts.map +1 -1
- package/dist/rules/dispatcher.js +3 -2
- package/dist/rules/dispatcher.js.map +1 -1
- package/dist/sandbox/sandbox-env-cache.d.ts +33 -0
- package/dist/sandbox/sandbox-env-cache.d.ts.map +1 -0
- package/dist/sandbox/sandbox-env-cache.js +140 -0
- package/dist/sandbox/sandbox-env-cache.js.map +1 -0
- package/dist/sandbox/sandbox-env.d.ts +77 -0
- package/dist/sandbox/sandbox-env.d.ts.map +1 -0
- package/dist/sandbox/sandbox-env.js +130 -0
- package/dist/sandbox/sandbox-env.js.map +1 -0
- package/dist/storage/domains/audit/actions.d.ts +1 -0
- package/dist/storage/domains/audit/actions.d.ts.map +1 -1
- package/dist/storage/domains/audit/actions.js +5 -0
- package/dist/storage/domains/audit/actions.js.map +1 -1
- package/dist/storage/domains/sandbox-envs/base.d.ts +70 -0
- package/dist/storage/domains/sandbox-envs/base.d.ts.map +1 -0
- package/dist/storage/domains/sandbox-envs/base.js +227 -0
- package/dist/storage/domains/sandbox-envs/base.js.map +1 -0
- package/dist/storage/domains/work-items/base.d.ts +2 -1
- package/dist/storage/domains/work-items/base.d.ts.map +1 -1
- package/dist/storage/domains/work-items/base.js +11 -2
- package/dist/storage/domains/work-items/base.js.map +1 -1
- package/dist/storage/domains/work-items/metrics.d.ts +1 -1
- package/dist/storage/domains/work-items/metrics.d.ts.map +1 -1
- package/dist/storage/domains/work-items/metrics.js.map +1 -1
- package/dist/workspace.d.ts +3 -0
- package/dist/workspace.d.ts.map +1 -1
- package/dist/workspace.js +21 -4
- package/dist/workspace.js.map +1 -1
- package/package.json +6 -6
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { PubSub } from '@mastra/core/events';
|
|
2
|
+
import type { ResolvedSandboxEnvs, SandboxEnvAppliesTo, SandboxEnvMetadata, SandboxEnvRevisions, SandboxEnvStore, SetSandboxEnvInput } from '../storage/domains/sandbox-envs/base.js';
|
|
3
|
+
/** One topic for every Factory: a replica drops its cached entry for the Factory named in the event. */
|
|
4
|
+
export declare const SANDBOX_ENV_CHANGED_TOPIC = "factory.sandbox-env";
|
|
5
|
+
/**
|
|
6
|
+
* The sandbox-envs store with reads served from memory. The revision is
|
|
7
|
+
* re-read only when a write is announced (by this replica or another one
|
|
8
|
+
* through the event bus) or the read gets old, and values are decrypted again
|
|
9
|
+
* only when the revision changed. Commands and workspace resolves then cost
|
|
10
|
+
* no storage reads while nobody edits a variable.
|
|
11
|
+
*
|
|
12
|
+
* Writes go through to the store, drop this replica's entry and announce the
|
|
13
|
+
* change, so the next command anywhere sees it.
|
|
14
|
+
*/
|
|
15
|
+
export declare class CachedSandboxEnvs implements SandboxEnvStore {
|
|
16
|
+
#private;
|
|
17
|
+
private readonly store;
|
|
18
|
+
private readonly options;
|
|
19
|
+
constructor(store: SandboxEnvStore, options?: {
|
|
20
|
+
pubsub?: PubSub;
|
|
21
|
+
crossProcess?: boolean;
|
|
22
|
+
now?: () => number;
|
|
23
|
+
});
|
|
24
|
+
/** Listen for other replicas' writes; resolves to the unsubscribe. */
|
|
25
|
+
subscribe(): Promise<() => Promise<void>>;
|
|
26
|
+
list(orgId: string, projectId: string): Promise<SandboxEnvMetadata[]>;
|
|
27
|
+
set(orgId: string, projectId: string, input: SetSandboxEnvInput, actorId: string): Promise<SandboxEnvMetadata>;
|
|
28
|
+
updateAppliesTo(orgId: string, projectId: string, name: string, appliesTo: SandboxEnvAppliesTo, actorId: string): Promise<SandboxEnvMetadata | null>;
|
|
29
|
+
delete(orgId: string, projectId: string, name: string): Promise<boolean>;
|
|
30
|
+
revisions(orgId: string, projectId: string): Promise<SandboxEnvRevisions | null>;
|
|
31
|
+
resolve(orgId: string, projectId: string): Promise<ResolvedSandboxEnvs>;
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=sandbox-env-cache.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sandbox-env-cache.d.ts","sourceRoot":"","sources":["../../src/sandbox/sandbox-env-cache.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAiB,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAGjE,OAAO,KAAK,EACV,mBAAmB,EACnB,mBAAmB,EACnB,kBAAkB,EAClB,mBAAmB,EACnB,eAAe,EACf,kBAAkB,EACnB,MAAM,yCAAyC,CAAC;AAEjD,wGAAwG;AACxG,eAAO,MAAM,yBAAyB,wBAAwB,CAAC;AAoB/D;;;;;;;;;GASG;AACH,qBAAa,iBAAkB,YAAW,eAAe;;IAWrD,OAAO,CAAC,QAAQ,CAAC,KAAK;IACtB,OAAO,CAAC,QAAQ,CAAC,OAAO;IAF1B,YACmB,KAAK,EAAE,eAAe,EACtB,OAAO,GAAE;QAAE,MAAM,CAAC,EAAE,MAAM,CAAC;QAAC,YAAY,CAAC,EAAE,OAAO,CAAC;QAAC,GAAG,CAAC,EAAE,MAAM,MAAM,CAAA;KAAO,EAG/F;IAED,sEAAsE;IAChE,SAAS,IAAI,OAAO,CAAC,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC,CAM9C;IAED,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,kBAAkB,EAAE,CAAC,CAEpE;IAEK,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,KAAK,EAAE,kBAAkB,EAAE,OAAO,EAAE,MAAM,+BAIrF;IAEK,eAAe,CACnB,KAAK,EAAE,MAAM,EACb,SAAS,EAAE,MAAM,EACjB,IAAI,EAAE,MAAM,EACZ,SAAS,EAAE,mBAAmB,EAC9B,OAAO,EAAE,MAAM,sCAKhB;IAEK,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,oBAI1D;IAED,SAAS,CAAC,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,mBAAmB,GAAG,IAAI,CAAC,CAE/E;IAEK,OAAO,CAAC,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,mBAAmB,CAAC,CAoB5E;CAgCF"}
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import { withAck } from "@mastra/core/events";
|
|
2
|
+
// src/sandbox/sandbox-env-cache.ts
|
|
3
|
+
/** One topic for every Factory: a replica drops its cached entry for the Factory named in the event. */
|
|
4
|
+
const SANDBOX_ENV_CHANGED_TOPIC = "factory.sandbox-env";
|
|
5
|
+
/**
|
|
6
|
+
* How long a revision read is trusted without hearing of a change. With a
|
|
7
|
+
* cross-process event bus, other replicas announce their writes, so this is
|
|
8
|
+
* only a safety net for a missed event. Without one, a write on another
|
|
9
|
+
* replica is only seen when the read expires.
|
|
10
|
+
*/
|
|
11
|
+
const TRUST_WITH_EVENTS_MS = 6e4;
|
|
12
|
+
const TRUST_WITHOUT_EVENTS_MS = 1e3;
|
|
13
|
+
/**
|
|
14
|
+
* The sandbox-envs store with reads served from memory. The revision is
|
|
15
|
+
* re-read only when a write is announced (by this replica or another one
|
|
16
|
+
* through the event bus) or the read gets old, and values are decrypted again
|
|
17
|
+
* only when the revision changed. Commands and workspace resolves then cost
|
|
18
|
+
* no storage reads while nobody edits a variable.
|
|
19
|
+
*
|
|
20
|
+
* Writes go through to the store, drop this replica's entry and announce the
|
|
21
|
+
* change, so the next command anywhere sees it.
|
|
22
|
+
*/
|
|
23
|
+
var CachedSandboxEnvs = class {
|
|
24
|
+
store;
|
|
25
|
+
options;
|
|
26
|
+
#entries = /* @__PURE__ */ new Map();
|
|
27
|
+
#origin = globalThis.crypto.randomUUID();
|
|
28
|
+
#trustMs;
|
|
29
|
+
#onEvent = withAck(async (event) => {
|
|
30
|
+
if (event.runId === this.#origin) return;
|
|
31
|
+
const { orgId, projectId } = event.data ?? {};
|
|
32
|
+
if (typeof orgId === "string" && typeof projectId === "string") this.#forget({
|
|
33
|
+
orgId,
|
|
34
|
+
projectId
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
constructor(store, options = {}) {
|
|
38
|
+
this.store = store;
|
|
39
|
+
this.options = options;
|
|
40
|
+
this.#trustMs = options.crossProcess ? TRUST_WITH_EVENTS_MS : TRUST_WITHOUT_EVENTS_MS;
|
|
41
|
+
}
|
|
42
|
+
/** Listen for other replicas' writes; resolves to the unsubscribe. */
|
|
43
|
+
async subscribe() {
|
|
44
|
+
const pubsub = this.options.pubsub;
|
|
45
|
+
if (!pubsub) return async () => {};
|
|
46
|
+
await pubsub.subscribe(SANDBOX_ENV_CHANGED_TOPIC, this.#onEvent, { startFrom: "latest" });
|
|
47
|
+
return () => pubsub.unsubscribe(SANDBOX_ENV_CHANGED_TOPIC, this.#onEvent);
|
|
48
|
+
}
|
|
49
|
+
list(orgId, projectId) {
|
|
50
|
+
return this.store.list(orgId, projectId);
|
|
51
|
+
}
|
|
52
|
+
async set(orgId, projectId, input, actorId) {
|
|
53
|
+
const env = await this.store.set(orgId, projectId, input, actorId);
|
|
54
|
+
this.#changed({
|
|
55
|
+
orgId,
|
|
56
|
+
projectId
|
|
57
|
+
});
|
|
58
|
+
return env;
|
|
59
|
+
}
|
|
60
|
+
async updateAppliesTo(orgId, projectId, name, appliesTo, actorId) {
|
|
61
|
+
const env = await this.store.updateAppliesTo(orgId, projectId, name, appliesTo, actorId);
|
|
62
|
+
if (env) this.#changed({
|
|
63
|
+
orgId,
|
|
64
|
+
projectId
|
|
65
|
+
});
|
|
66
|
+
return env;
|
|
67
|
+
}
|
|
68
|
+
async delete(orgId, projectId, name) {
|
|
69
|
+
const deleted = await this.store.delete(orgId, projectId, name);
|
|
70
|
+
if (deleted) this.#changed({
|
|
71
|
+
orgId,
|
|
72
|
+
projectId
|
|
73
|
+
});
|
|
74
|
+
return deleted;
|
|
75
|
+
}
|
|
76
|
+
revisions(orgId, projectId) {
|
|
77
|
+
return this.#entry({
|
|
78
|
+
orgId,
|
|
79
|
+
projectId
|
|
80
|
+
}).revisions;
|
|
81
|
+
}
|
|
82
|
+
async resolve(orgId, projectId) {
|
|
83
|
+
const entry = this.#entry({
|
|
84
|
+
orgId,
|
|
85
|
+
projectId
|
|
86
|
+
});
|
|
87
|
+
const current = (await entry.revisions)?.revision ?? "";
|
|
88
|
+
if (entry.resolved) {
|
|
89
|
+
const cached = await entry.resolved.catch(() => void 0);
|
|
90
|
+
if (cached?.revision === current) return cached;
|
|
91
|
+
}
|
|
92
|
+
const resolved = this.store.resolve(orgId, projectId);
|
|
93
|
+
entry.resolved = resolved;
|
|
94
|
+
resolved.then(({ revision, buildRevision }) => {
|
|
95
|
+
if (revision !== current) entry.revisions = Promise.resolve({
|
|
96
|
+
revision,
|
|
97
|
+
buildRevision
|
|
98
|
+
});
|
|
99
|
+
}, () => {
|
|
100
|
+
if (entry.resolved === resolved) entry.resolved = void 0;
|
|
101
|
+
});
|
|
102
|
+
return resolved;
|
|
103
|
+
}
|
|
104
|
+
#entry(scope) {
|
|
105
|
+
const key = keyOf(scope);
|
|
106
|
+
const now = (this.options.now ?? Date.now)();
|
|
107
|
+
const existing = this.#entries.get(key);
|
|
108
|
+
if (existing && now - existing.at < this.#trustMs) return existing;
|
|
109
|
+
const revisions = this.store.revisions(scope.orgId, scope.projectId);
|
|
110
|
+
const entry = {
|
|
111
|
+
at: now,
|
|
112
|
+
revisions,
|
|
113
|
+
...existing?.resolved ? { resolved: existing.resolved } : {}
|
|
114
|
+
};
|
|
115
|
+
this.#entries.set(key, entry);
|
|
116
|
+
revisions.catch(() => {
|
|
117
|
+
if (this.#entries.get(key) === entry) this.#entries.delete(key);
|
|
118
|
+
});
|
|
119
|
+
return entry;
|
|
120
|
+
}
|
|
121
|
+
#forget(scope) {
|
|
122
|
+
this.#entries.delete(keyOf(scope));
|
|
123
|
+
}
|
|
124
|
+
#changed(scope) {
|
|
125
|
+
this.#forget(scope);
|
|
126
|
+
this.options.pubsub?.publish(SANDBOX_ENV_CHANGED_TOPIC, {
|
|
127
|
+
type: "factory.sandbox-env.changed",
|
|
128
|
+
runId: this.#origin,
|
|
129
|
+
data: scope
|
|
130
|
+
}).catch((error) => {
|
|
131
|
+
console.warn("[Factory] Failed to announce a sandbox environment variable change", { error: error instanceof Error ? error.message : String(error) });
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
};
|
|
135
|
+
function keyOf(scope) {
|
|
136
|
+
return `${scope.orgId}\u0000${scope.projectId}`;
|
|
137
|
+
}
|
|
138
|
+
export { CachedSandboxEnvs, SANDBOX_ENV_CHANGED_TOPIC };
|
|
139
|
+
|
|
140
|
+
//# sourceMappingURL=sandbox-env-cache.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sandbox-env-cache.js","names":[],"sources":["../../src/sandbox/sandbox-env-cache.ts"],"sourcesContent":["import type { EventCallback, PubSub } from '@mastra/core/events';\nimport { withAck } from '@mastra/core/events';\n\nimport type {\n ResolvedSandboxEnvs,\n SandboxEnvAppliesTo,\n SandboxEnvMetadata,\n SandboxEnvRevisions,\n SandboxEnvStore,\n SetSandboxEnvInput,\n} from '../storage/domains/sandbox-envs/base.js';\n\n/** One topic for every Factory: a replica drops its cached entry for the Factory named in the event. */\nexport const SANDBOX_ENV_CHANGED_TOPIC = 'factory.sandbox-env';\n\n/**\n * How long a revision read is trusted without hearing of a change. With a\n * cross-process event bus, other replicas announce their writes, so this is\n * only a safety net for a missed event. Without one, a write on another\n * replica is only seen when the read expires.\n */\nconst TRUST_WITH_EVENTS_MS = 60_000;\nconst TRUST_WITHOUT_EVENTS_MS = 1_000;\n\ntype Scope = { orgId: string; projectId: string };\n\ninterface Entry {\n at: number;\n revisions: Promise<SandboxEnvRevisions | null>;\n /** Decrypted values, reused while the revision they were read at is current. */\n resolved?: Promise<ResolvedSandboxEnvs>;\n}\n\n/**\n * The sandbox-envs store with reads served from memory. The revision is\n * re-read only when a write is announced (by this replica or another one\n * through the event bus) or the read gets old, and values are decrypted again\n * only when the revision changed. Commands and workspace resolves then cost\n * no storage reads while nobody edits a variable.\n *\n * Writes go through to the store, drop this replica's entry and announce the\n * change, so the next command anywhere sees it.\n */\nexport class CachedSandboxEnvs implements SandboxEnvStore {\n readonly #entries = new Map<string, Entry>();\n readonly #origin = globalThis.crypto.randomUUID();\n readonly #trustMs: number;\n readonly #onEvent: EventCallback = withAck(async event => {\n if (event.runId === this.#origin) return;\n const { orgId, projectId } = (event.data ?? {}) as Partial<Scope>;\n if (typeof orgId === 'string' && typeof projectId === 'string') this.#forget({ orgId, projectId });\n });\n\n constructor(\n private readonly store: SandboxEnvStore,\n private readonly options: { pubsub?: PubSub; crossProcess?: boolean; now?: () => number } = {},\n ) {\n this.#trustMs = options.crossProcess ? TRUST_WITH_EVENTS_MS : TRUST_WITHOUT_EVENTS_MS;\n }\n\n /** Listen for other replicas' writes; resolves to the unsubscribe. */\n async subscribe(): Promise<() => Promise<void>> {\n const pubsub = this.options.pubsub;\n if (!pubsub) return async () => {};\n // Without `latest`, a retaining broker replays old changes on boot.\n await pubsub.subscribe(SANDBOX_ENV_CHANGED_TOPIC, this.#onEvent, { startFrom: 'latest' });\n return () => pubsub.unsubscribe(SANDBOX_ENV_CHANGED_TOPIC, this.#onEvent);\n }\n\n list(orgId: string, projectId: string): Promise<SandboxEnvMetadata[]> {\n return this.store.list(orgId, projectId);\n }\n\n async set(orgId: string, projectId: string, input: SetSandboxEnvInput, actorId: string) {\n const env = await this.store.set(orgId, projectId, input, actorId);\n this.#changed({ orgId, projectId });\n return env;\n }\n\n async updateAppliesTo(\n orgId: string,\n projectId: string,\n name: string,\n appliesTo: SandboxEnvAppliesTo,\n actorId: string,\n ) {\n const env = await this.store.updateAppliesTo(orgId, projectId, name, appliesTo, actorId);\n if (env) this.#changed({ orgId, projectId });\n return env;\n }\n\n async delete(orgId: string, projectId: string, name: string) {\n const deleted = await this.store.delete(orgId, projectId, name);\n if (deleted) this.#changed({ orgId, projectId });\n return deleted;\n }\n\n revisions(orgId: string, projectId: string): Promise<SandboxEnvRevisions | null> {\n return this.#entry({ orgId, projectId }).revisions;\n }\n\n async resolve(orgId: string, projectId: string): Promise<ResolvedSandboxEnvs> {\n const entry = this.#entry({ orgId, projectId });\n const current = (await entry.revisions)?.revision ?? '';\n if (entry.resolved) {\n const cached = await entry.resolved.catch(() => undefined);\n if (cached?.revision === current) return cached;\n }\n const resolved = this.store.resolve(orgId, projectId);\n entry.resolved = resolved;\n resolved.then(\n // The values carry their own revision; adopt it so the next call matches instead of decrypting again.\n ({ revision, buildRevision }) => {\n if (revision !== current) entry.revisions = Promise.resolve({ revision, buildRevision });\n },\n // Keep only a read that succeeded.\n () => {\n if (entry.resolved === resolved) entry.resolved = undefined;\n },\n );\n return resolved;\n }\n\n #entry(scope: Scope): Entry {\n const key = keyOf(scope);\n const now = (this.options.now ?? Date.now)();\n const existing = this.#entries.get(key);\n if (existing && now - existing.at < this.#trustMs) return existing;\n const revisions = this.store.revisions(scope.orgId, scope.projectId);\n // The decrypted values survive a re-read: `resolve` reuses them if the revision didn't move.\n const entry: Entry = { at: now, revisions, ...(existing?.resolved ? { resolved: existing.resolved } : {}) };\n this.#entries.set(key, entry);\n // A failed read is never served from memory.\n revisions.catch(() => {\n if (this.#entries.get(key) === entry) this.#entries.delete(key);\n });\n return entry;\n }\n\n #forget(scope: Scope): void {\n this.#entries.delete(keyOf(scope));\n }\n\n #changed(scope: Scope): void {\n this.#forget(scope);\n this.options.pubsub\n ?.publish(SANDBOX_ENV_CHANGED_TOPIC, { type: 'factory.sandbox-env.changed', runId: this.#origin, data: scope })\n .catch((error: unknown) => {\n console.warn('[Factory] Failed to announce a sandbox environment variable change', {\n error: error instanceof Error ? error.message : String(error),\n });\n });\n }\n}\n\nfunction keyOf(scope: Scope): string {\n return `${scope.orgId}\\u0000${scope.projectId}`;\n}\n"],"mappings":";;;AAaA,MAAa,4BAA4B;;;;;;;AAQzC,MAAM,uBAAuB;AAC7B,MAAM,0BAA0B;;;;;;;;;;;AAqBhC,IAAa,oBAAb,MAA0D;CAWrC;CACA;CAXnB,2BAAoB,IAAI,IAAmB;CAC3C,UAAmB,WAAW,OAAO,WAAW;CAChD;CACA,WAAmC,QAAQ,OAAM,UAAS;EACxD,IAAI,MAAM,UAAU,KAAK,SAAS;EAClC,MAAM,EAAE,OAAO,cAAe,MAAM,QAAQ,CAAC;EAC7C,IAAI,OAAO,UAAU,YAAY,OAAO,cAAc,UAAU,KAAK,QAAQ;GAAE;GAAO;EAAU,CAAC;CACnG,CAAC;CAED,YACE,OACA,UAA4F,CAAC,GAC7F;EAFiB,KAAA,QAAA;EACA,KAAA,UAAA;EAEjB,KAAK,WAAW,QAAQ,eAAe,uBAAuB;CAChE;;CAGA,MAAM,YAA0C;EAC9C,MAAM,SAAS,KAAK,QAAQ;EAC5B,IAAI,CAAC,QAAQ,OAAO,YAAY,CAAC;EAEjC,MAAM,OAAO,UAAU,2BAA2B,KAAK,UAAU,EAAE,WAAW,SAAS,CAAC;EACxF,aAAa,OAAO,YAAY,2BAA2B,KAAK,QAAQ;CAC1E;CAEA,KAAK,OAAe,WAAkD;EACpE,OAAO,KAAK,MAAM,KAAK,OAAO,S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,KAAK,QAAQ,OAAO,KAAK,IAAA,CAAK;EAC3C,MAAM,WAAW,KAAK,SAAS,IAAI,GAAG;EACtC,IAAI,YAAY,MAAM,SAAS,KAAK,KAAK,UAAU,OAAO;EAC1D,MAAM,YAAY,KAAK,MAAM,UAAU,MAAM,OAAO,MAAM,SAAS;EAEnE,MAAM,QAAe;GAAE,IAAI;GAAK;GAAW,GAAI,UAAU,WAAW,EAAE,UAAU,SAAS,SAAS,IAAI,CAAC;EAAG;EAC1G,KAAK,SAAS,IAAI,KAAK,KAAK;EAE5B,UAAU,YAAY;GACpB,IAAI,KAAK,SAAS,IAAI,GAAG,MAAM,OAAO,KAAK,SAAS,OAAO,GAAG;EAChE,CAAC;EACD,OAAO;CACT;CAEA,QAAQ,OAAoB;EAC1B,KAAK,SAAS,OAAO,MAAM,KAAK,CAAC;CACnC;CAEA,SAAS,OAAoB;EAC3B,KAAK,QAAQ,KAAK;EAClB,KAAK,QAAQ,QACT,QAAQ,2BAA2B;GAAE,MAAM;GAA+B,OAAO,KAAK;GAAS,MAAM;EAAM,CAAC,CAAC,CAC9G,OAAO,UAAmB;GACzB,QAAQ,KAAK,sEAAsE,EACjF,OAAO,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK,EAC9D,CAAC;EACH,CAAC;CACL;AACF;AAEA,SAAS,MAAM,OAAsB;CACnC,OAAO,GAAG,MAAM,MAAM,QAAQ,MAAM;AACtC"}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Sandbox environment variables: what a session sandbox's commands and builds
|
|
3
|
+
* get from the Factory's stored variables, and how a running sandbox picks up
|
|
4
|
+
* edits on its next command.
|
|
5
|
+
*/
|
|
6
|
+
import type { FactorySandboxContext } from '@mastra/core/workspace';
|
|
7
|
+
import type { SandboxEnvStore } from '../storage/domains/sandbox-envs/base.js';
|
|
8
|
+
export interface SandboxEnv {
|
|
9
|
+
/** Variables every command in the sandbox gets. */
|
|
10
|
+
runtime: Record<string, string>;
|
|
11
|
+
/** Variables template builds and Factory-run setup commands get; never runtime commands. */
|
|
12
|
+
build: Record<string, string>;
|
|
13
|
+
/** Read before the values: an edit landing in between makes the next check reload. */
|
|
14
|
+
revision: string;
|
|
15
|
+
buildRevision: string;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* The single place a sandbox's environment is resolved. v1 reads only the
|
|
19
|
+
* Factory-wide variables; personal and session layers merge in here later,
|
|
20
|
+
* with session over personal over Factory, so callers never change.
|
|
21
|
+
*/
|
|
22
|
+
export declare function resolveSandboxEnv(store: Pick<SandboxEnvStore, 'resolve'>, scope: {
|
|
23
|
+
orgId: string;
|
|
24
|
+
projectId: string;
|
|
25
|
+
}): Promise<SandboxEnv>;
|
|
26
|
+
/**
|
|
27
|
+
* `resolveSandboxEnv` for session boot and setup: a failed read (a storage
|
|
28
|
+
* blip, a value encrypted with a removed key) is logged and yields no Factory
|
|
29
|
+
* variables, so it can't stop a session from starting. Its empty revision
|
|
30
|
+
* makes the first command's refresh try again.
|
|
31
|
+
*/
|
|
32
|
+
export declare function resolveSandboxEnvOrEmpty(store: Pick<SandboxEnvStore, 'resolve'>, scope: {
|
|
33
|
+
orgId: string;
|
|
34
|
+
projectId: string;
|
|
35
|
+
}): Promise<SandboxEnv>;
|
|
36
|
+
/**
|
|
37
|
+
* The template-build fields of a sandbox context. Omitted when the Factory has
|
|
38
|
+
* no Build variables, so the template identity matches one built without them.
|
|
39
|
+
* Session boot and environment builds share this, so both name the same template.
|
|
40
|
+
*/
|
|
41
|
+
export declare function sandboxBuildContext(env: SandboxEnv | undefined): Pick<FactorySandboxContext, 'buildEnv' | 'buildEnvRevision'>;
|
|
42
|
+
/**
|
|
43
|
+
* Replace every Build value that appears in provider or command output with
|
|
44
|
+
* `***`. Each value is also matched without its edge whitespace, since output
|
|
45
|
+
* often drops a pasted trailing space or newline. Longest first, so a value
|
|
46
|
+
* that contains another is masked whole.
|
|
47
|
+
*/
|
|
48
|
+
export declare function maskSandboxEnvValues(text: string, env: Record<string, string> | undefined): string;
|
|
49
|
+
type EnvOverlay = Record<string, string | undefined>;
|
|
50
|
+
/**
|
|
51
|
+
* The Factory runtime values currently applied to a sandbox, so output from a
|
|
52
|
+
* command that ran in it (a failed teardown) can be masked without a storage read.
|
|
53
|
+
*/
|
|
54
|
+
export declare function appliedSandboxEnv(sandbox: object): Record<string, string>;
|
|
55
|
+
export interface RefreshableSandbox {
|
|
56
|
+
ensureRunning?: () => Promise<void>;
|
|
57
|
+
setEnv?: (update: (env: EnvOverlay) => EnvOverlay) => void;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Apply the Factory's runtime variables to a sandbox's env overlay and keep
|
|
61
|
+
* them current: after every `ensureRunning()` (which every command path awaits
|
|
62
|
+
* before reading the overlay) the Factory revision is checked, and on a change
|
|
63
|
+
* the variables are reloaded and re-applied, so an add, edit or delete reaches
|
|
64
|
+
* the next command. Processes already running keep the env they started with.
|
|
65
|
+
*
|
|
66
|
+
* A key the sandbox already had (its host `env`) is remembered before Factory
|
|
67
|
+
* first writes it and restored when the Factory variable goes away. A refresh
|
|
68
|
+
* that fails is logged and the command runs with the env last applied.
|
|
69
|
+
*/
|
|
70
|
+
export declare function attachSandboxEnvRefresh(sandbox: RefreshableSandbox, options: {
|
|
71
|
+
initial: Pick<SandboxEnv, 'runtime' | 'revision'>;
|
|
72
|
+
revision: () => Promise<string>;
|
|
73
|
+
load: () => Promise<Pick<SandboxEnv, 'runtime' | 'revision'>>;
|
|
74
|
+
onError?: (error: unknown) => void;
|
|
75
|
+
}): void;
|
|
76
|
+
export {};
|
|
77
|
+
//# sourceMappingURL=sandbox-env.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sandbox-env.d.ts","sourceRoot":"","sources":["../../src/sandbox/sandbox-env.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,wBAAwB,CAAC;AACpE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AAkB;IACjC,aAAa,CAAC,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IACpC,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,UAAU,KAAK,UAAU,KAAK,IAAI,CAAC;CAC5D;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,uBAAuB,CACrC,OAAO,EAAE,kBAAkB,EAC3B,OAAO,EAAE;IACP,OAAO,EAAE,IAAI,CAAC,UAAU,EAAE,SAAS,GAAG,UAAU,CAAC,CAAC;IAClD,QAAQ,EAAE,MAAM,OAAO,CAAC,MAAM,CAAC,CAAC;IAChC,IAAI,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,UAAU,EAAE,SAAS,GAAG,UAAU,CAAC,CAAC,CAAC;IAC9D,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,IAAI,CAAC;CACpC,GACA,IAAI,CAmDN"}
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
// src/sandbox/sandbox-env.ts
|
|
2
|
+
/**
|
|
3
|
+
* The single place a sandbox's environment is resolved. v1 reads only the
|
|
4
|
+
* Factory-wide variables; personal and session layers merge in here later,
|
|
5
|
+
* with session over personal over Factory, so callers never change.
|
|
6
|
+
*/
|
|
7
|
+
async function resolveSandboxEnv(store, scope) {
|
|
8
|
+
const { runtime, build, revision, buildRevision } = await store.resolve(scope.orgId, scope.projectId);
|
|
9
|
+
return {
|
|
10
|
+
runtime,
|
|
11
|
+
build,
|
|
12
|
+
revision,
|
|
13
|
+
buildRevision
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
function warnReadFailed(message, error) {
|
|
17
|
+
console.warn(`[Mastra Factory] ${message}`, { error: error instanceof Error ? error.message : String(error) });
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* `resolveSandboxEnv` for session boot and setup: a failed read (a storage
|
|
21
|
+
* blip, a value encrypted with a removed key) is logged and yields no Factory
|
|
22
|
+
* variables, so it can't stop a session from starting. Its empty revision
|
|
23
|
+
* makes the first command's refresh try again.
|
|
24
|
+
*/
|
|
25
|
+
async function resolveSandboxEnvOrEmpty(store, scope) {
|
|
26
|
+
try {
|
|
27
|
+
return await resolveSandboxEnv(store, scope);
|
|
28
|
+
} catch (error) {
|
|
29
|
+
warnReadFailed("Could not read sandbox environment variables; starting without them", error);
|
|
30
|
+
return {
|
|
31
|
+
runtime: {},
|
|
32
|
+
build: {},
|
|
33
|
+
revision: "",
|
|
34
|
+
buildRevision: ""
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* The template-build fields of a sandbox context. Omitted when the Factory has
|
|
40
|
+
* no Build variables, so the template identity matches one built without them.
|
|
41
|
+
* Session boot and environment builds share this, so both name the same template.
|
|
42
|
+
*/
|
|
43
|
+
function sandboxBuildContext(env) {
|
|
44
|
+
if (!env || Object.keys(env.build).length === 0) return {};
|
|
45
|
+
return {
|
|
46
|
+
buildEnv: env.build,
|
|
47
|
+
buildEnvRevision: env.buildRevision
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Replace every Build value that appears in provider or command output with
|
|
52
|
+
* `***`. Each value is also matched without its edge whitespace, since output
|
|
53
|
+
* often drops a pasted trailing space or newline. Longest first, so a value
|
|
54
|
+
* that contains another is masked whole.
|
|
55
|
+
*/
|
|
56
|
+
function maskSandboxEnvValues(text, env) {
|
|
57
|
+
if (!env) return text;
|
|
58
|
+
const values = new Set(Object.values(env).flatMap((value) => [value, value.trim()]));
|
|
59
|
+
let masked = text;
|
|
60
|
+
for (const value of [...values].sort((a, b) => b.length - a.length)) if (value) masked = masked.replaceAll(value, "***");
|
|
61
|
+
return masked;
|
|
62
|
+
}
|
|
63
|
+
const appliedBySandbox = /* @__PURE__ */ new WeakMap();
|
|
64
|
+
/**
|
|
65
|
+
* The Factory runtime values currently applied to a sandbox, so output from a
|
|
66
|
+
* command that ran in it (a failed teardown) can be masked without a storage read.
|
|
67
|
+
*/
|
|
68
|
+
function appliedSandboxEnv(sandbox) {
|
|
69
|
+
return appliedBySandbox.get(sandbox)?.() ?? {};
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Apply the Factory's runtime variables to a sandbox's env overlay and keep
|
|
73
|
+
* them current: after every `ensureRunning()` (which every command path awaits
|
|
74
|
+
* before reading the overlay) the Factory revision is checked, and on a change
|
|
75
|
+
* the variables are reloaded and re-applied, so an add, edit or delete reaches
|
|
76
|
+
* the next command. Processes already running keep the env they started with.
|
|
77
|
+
*
|
|
78
|
+
* A key the sandbox already had (its host `env`) is remembered before Factory
|
|
79
|
+
* first writes it and restored when the Factory variable goes away. A refresh
|
|
80
|
+
* that fails is logged and the command runs with the env last applied.
|
|
81
|
+
*/
|
|
82
|
+
function attachSandboxEnvRefresh(sandbox, options) {
|
|
83
|
+
const setEnv = sandbox.setEnv?.bind(sandbox);
|
|
84
|
+
if (!setEnv) return;
|
|
85
|
+
const shadowed = /* @__PURE__ */ new Map();
|
|
86
|
+
let applied = {};
|
|
87
|
+
let appliedRevision = options.initial.revision;
|
|
88
|
+
const apply = (next) => {
|
|
89
|
+
setEnv((env) => {
|
|
90
|
+
const out = { ...env };
|
|
91
|
+
for (const key of Object.keys(applied)) {
|
|
92
|
+
if (Object.hasOwn(next, key)) continue;
|
|
93
|
+
const previous = shadowed.get(key);
|
|
94
|
+
shadowed.delete(key);
|
|
95
|
+
if (previous === void 0) delete out[key];
|
|
96
|
+
else out[key] = previous;
|
|
97
|
+
}
|
|
98
|
+
for (const [key, value] of Object.entries(next)) {
|
|
99
|
+
if (!Object.hasOwn(applied, key)) shadowed.set(key, env[key]);
|
|
100
|
+
out[key] = value;
|
|
101
|
+
}
|
|
102
|
+
return out;
|
|
103
|
+
});
|
|
104
|
+
applied = { ...next };
|
|
105
|
+
};
|
|
106
|
+
apply(options.initial.runtime);
|
|
107
|
+
appliedBySandbox.set(sandbox, () => applied);
|
|
108
|
+
const original = sandbox.ensureRunning?.bind(sandbox);
|
|
109
|
+
if (!original) return;
|
|
110
|
+
let inFlight;
|
|
111
|
+
const refresh = async () => {
|
|
112
|
+
if (await options.revision() === appliedRevision) return;
|
|
113
|
+
const next = await options.load();
|
|
114
|
+
apply(next.runtime);
|
|
115
|
+
appliedRevision = next.revision;
|
|
116
|
+
};
|
|
117
|
+
sandbox.ensureRunning = async () => {
|
|
118
|
+
await original();
|
|
119
|
+
inFlight ??= refresh().catch((error) => {
|
|
120
|
+
if (options.onError) options.onError(error);
|
|
121
|
+
else warnReadFailed("Could not refresh sandbox environment variables; using the last applied", error);
|
|
122
|
+
}).finally(() => {
|
|
123
|
+
inFlight = void 0;
|
|
124
|
+
});
|
|
125
|
+
await inFlight;
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
export { appliedSandboxEnv, attachSandboxEnvRefresh, maskSandboxEnvValues, resolveSandboxEnv, resolveSandboxEnvOrEmpty, sandboxBuildContext };
|
|
129
|
+
|
|
130
|
+
//# sourceMappingURL=sandbox-env.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sandbox-env.js","names":[],"sources":["../../src/sandbox/sandbox-env.ts"],"sourcesContent":["/**\n * Sandbox environment variables: what a session sandbox's commands and builds\n * get from the Factory's stored variables, and how a running sandbox picks up\n * edits on its next command.\n */\n\nimport type { FactorySandboxContext } from '@mastra/core/workspace';\nimport type { SandboxEnvStore } from '../storage/domains/sandbox-envs/base.js';\n\nexport interface SandboxEnv {\n /** Variables every command in the sandbox gets. */\n runtime: Record<string, string>;\n /** Variables template builds and Factory-run setup commands get; never runtime commands. */\n build: Record<string, string>;\n /** Read before the values: an edit landing in between makes the next check reload. */\n revision: string;\n buildRevision: string;\n}\n\n/**\n * The single place a sandbox's environment is resolved. v1 reads only the\n * Factory-wide variables; personal and session layers merge in here later,\n * with session over personal over Factory, so callers never change.\n */\nexport async function resolveSandboxEnv(\n store: Pick<SandboxEnvStore, 'resolve'>,\n scope: { orgId: string; projectId: string },\n): Promise<SandboxEnv> {\n const { runtime, build, revision, buildRevision } = await store.resolve(scope.orgId, scope.projectId);\n return { runtime, build, revision, buildRevision };\n}\n\nfunction warnReadFailed(message: string, error: unknown) {\n console.warn(`[Mastra Factory] ${message}`, {\n // Storage and decryption errors name no values.\n error: error instanceof Error ? error.message : String(error),\n });\n}\n\n/**\n * `resolveSandboxEnv` for session boot and setup: a failed read (a storage\n * blip, a value encrypted with a removed key) is logged and yields no Factory\n * variables, so it can't stop a session from starting. Its empty revision\n * makes the first command's refresh try again.\n */\nexport async function resolveSandboxEnvOrEmpty(\n store: Pick<SandboxEnvStore, 'resolve'>,\n scope: { orgId: string; projectId: string },\n): Promise<SandboxEnv> {\n try {\n return await resolveSandboxEnv(store, scope);\n } catch (error) {\n warnReadFailed('Could not read sandbox environment variables; starting without them', error);\n return { runtime: {}, build: {}, revision: '', buildRevision: '' };\n }\n}\n\n/**\n * The template-build fields of a sandbox context. Omitted when the Factory has\n * no Build variables, so the template identity matches one built without them.\n * Session boot and environment builds share this, so both name the same template.\n */\nexport function sandboxBuildContext(\n env: SandboxEnv | undefined,\n): Pick<FactorySandboxContext, 'buildEnv' | 'buildEnvRevision'> {\n if (!env || Object.keys(env.build).length === 0) return {};\n return { buildEnv: env.build, buildEnvRevision: env.buildRevision };\n}\n\n/**\n * Replace every Build value that appears in provider or command output with\n * `***`. Each value is also matched without its edge whitespace, since output\n * often drops a pasted trailing space or newline. Longest first, so a value\n * that contains another is masked whole.\n */\nexport function maskSandboxEnvValues(text: string, env: Record<string, string> | undefined): string {\n if (!env) return text;\n const values = new Set(Object.values(env).flatMap(value => [value, value.trim()]));\n let masked = text;\n for (const value of [...values].sort((a, b) => b.length - a.length)) {\n if (value) masked = masked.replaceAll(value, '***');\n }\n return masked;\n}\n\ntype EnvOverlay = Record<string, string | undefined>;\n\nconst appliedBySandbox = new WeakMap<object, () => Record<string, string>>();\n\n/**\n * The Factory runtime values currently applied to a sandbox, so output from a\n * command that ran in it (a failed teardown) can be masked without a storage read.\n */\nexport function appliedSandboxEnv(sandbox: object): Record<string, string> {\n return appliedBySandbox.get(sandbox)?.() ?? {};\n}\n\nexport interface RefreshableSandbox {\n ensureRunning?: () => Promise<void>;\n setEnv?: (update: (env: EnvOverlay) => EnvOverlay) => void;\n}\n\n/**\n * Apply the Factory's runtime variables to a sandbox's env overlay and keep\n * them current: after every `ensureRunning()` (which every command path awaits\n * before reading the overlay) the Factory revision is checked, and on a change\n * the variables are reloaded and re-applied, so an add, edit or delete reaches\n * the next command. Processes already running keep the env they started with.\n *\n * A key the sandbox already had (its host `env`) is remembered before Factory\n * first writes it and restored when the Factory variable goes away. A refresh\n * that fails is logged and the command runs with the env last applied.\n */\nexport function attachSandboxEnvRefresh(\n sandbox: RefreshableSandbox,\n options: {\n initial: Pick<SandboxEnv, 'runtime' | 'revision'>;\n revision: () => Promise<string>;\n load: () => Promise<Pick<SandboxEnv, 'runtime' | 'revision'>>;\n onError?: (error: unknown) => void;\n },\n): void {\n const setEnv = sandbox.setEnv?.bind(sandbox);\n if (!setEnv) return;\n // Values the overlay held under a key before Factory first wrote it.\n const shadowed = new Map<string, string | undefined>();\n let applied: Record<string, string> = {};\n let appliedRevision = options.initial.revision;\n\n const apply = (next: Record<string, string>) => {\n setEnv(env => {\n const out = { ...env };\n for (const key of Object.keys(applied)) {\n if (Object.hasOwn(next, key)) continue;\n const previous = shadowed.get(key);\n shadowed.delete(key);\n if (previous === undefined) delete out[key];\n else out[key] = previous;\n }\n for (const [key, value] of Object.entries(next)) {\n if (!Object.hasOwn(applied, key)) shadowed.set(key, env[key]);\n out[key] = value;\n }\n return out;\n });\n applied = { ...next };\n };\n apply(options.initial.runtime);\n appliedBySandbox.set(sandbox, () => applied);\n\n const original = sandbox.ensureRunning?.bind(sandbox);\n if (!original) return;\n let inFlight: Promise<void> | undefined;\n // Never calls ensureRunning itself, so a command inside `onStart` can't wait on its own start.\n const refresh = async () => {\n if ((await options.revision()) === appliedRevision) return;\n const next = await options.load();\n apply(next.runtime);\n appliedRevision = next.revision;\n };\n sandbox.ensureRunning = async () => {\n await original();\n inFlight ??= refresh()\n .catch(error => {\n if (options.onError) options.onError(error);\n else warnReadFailed('Could not refresh sandbox environment variables; using the last applied', error);\n })\n .finally(() => {\n inFlight = undefined;\n });\n await inFlight;\n };\n}\n"],"mappings":";;;;;;AAwBA,eAAsB,kBACpB,OACA,OACqB;CACrB,MAAM,EAAE,SAAS,OAAO,UAAU,kBAAkB,MAAM,MAAM,QAAQ,MAAM,OAAO,MAAM,SAAS;CACpG,OAAO;EAAE;EAAS;EAAO;EAAU;CAAc;AACnD;AAEA,SAAS,eAAe,SAAiB,OAAgB;CACvD,QAAQ,KAAK,oBAAoB,WAAW,EAE1C,OAAO,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK,EAC9D,CAAC;AACH;;;;;;;AAQA,eAAsB,yBACpB,OACA,OACqB;CACrB,IAAI;EACF,OAAO,MAAM,kBAAkB,OAAO,KAAK;CAC7C,SAAS,OAAO;EACd,eAAe,uEAAuE,KAAK;EAC3F,OAAO;GAAE,SAAS,CAAC;GAAG,OAAO,CAAC;GAAG,UAAU;GAAI,eAAe;EAAG;CACnE;AACF;;;;;;AAOA,SAAgB,oBACd,KAC8D;CAC9D,IAAI,CAAC,OAAO,OAAO,KAAK,IAAI,KAAK,CAAC,CAAC,WAAW,GAAG,OAAO,CAAC;CACzD,OAAO;EAAE,UAAU,IAAI;EAAO,kBAAkB,IAAI;CAAc;AACpE;;;;;;;AAQA,SAAgB,qBAAqB,MAAc,KAAiD;CAClG,IAAI,CAAC,KAAK,OAAO;CACjB,MAAM,SAAS,IAAI,IAAI,OAAO,OAAO,GAAG,CAAC,CAAC,SAAQ,UAAS,CAAC,OAAO,MAAM,KAAK,CAAC,CAAC,CAAC;CACjF,IAAI,SAAS;CACb,KAAK,MAAM,SAAS,CAAC,GAAG,MAAM,CAAC,CAAC,MAAM,GAAG,MAAM,EAAE,SAAS,EAAE,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zB;CACA,QAAQ,gBAAgB,YAAY;EAClC,MAAM,SAAS;EACf,aAAa,QAAQ,CAAC,CACnB,OAAM,UAAS;GACd,IAAI,QAAQ,SAAS,QAAQ,QAAQ,KAAK;QACrC,eAAe,2EAA2E,KAAK;EACtG,CAAC,CAAC,CACD,cAAc;GACb,WAAW,KAAA;EACb,CAAC;EACH,MAAM;CACR;AACF"}
|
|
@@ -12,6 +12,7 @@ export declare const AUDIT_ACTIONS: {
|
|
|
12
12
|
readonly board: readonly ['created', 'updated', 'deleted', 'reset'];
|
|
13
13
|
readonly skill: readonly ['updated', 'reverted'];
|
|
14
14
|
readonly intake_route: readonly ['created', 'updated', 'deleted', 'reordered'];
|
|
15
|
+
readonly sandbox_env: readonly ['set', 'updated', 'deleted'];
|
|
15
16
|
};
|
|
16
17
|
export type AuditNamespace = keyof typeof AUDIT_ACTIONS;
|
|
17
18
|
export type AuditAction = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"actions.d.ts","sourceRoot":"","sources":["../../../../src/storage/domains/audit/actions.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,eAAO,MAAM,aAAa;aACxB,SAAS,YAAG,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,aAAa,EAAE,qBAAqB,EAAE,mBAAmB;aACtG,GAAG,YAAG,SAAS,EAAE,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,OAAO,EAAE,QAAQ,EAAE,UAAU;aAChF,GAAG,YAAG,QAAQ,EAAE,MAAM,EAAE,WAAW;aACnC,KAAK,YAAG,QAAQ,EAAE,MAAM,EAAE,WAAW,EAAE,UAAU;aACjD,MAAM,YAAG,gBAAgB,EAAE,iBAAiB,EAAE,qBAAqB;aACnE,OAAO,YAAG,mBAAmB;aAC7B,KAAK,YAAG,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,OAAO;aAChD,KAAK,YAAG,SAAS,EAAE,UAAU;aAC7B,YAAY,YAAG,SAAS,EAAE,SAAS,EAAE,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AAED,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG,KAAK,IAAI,WAAW,CAGjE;AAED,wBAAgB,wBAAwB,CAAC,UAAU,EAAE,SAAS,cAAc,EAAE,GAAG,MAAM,EAAE,CAExF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"actions.js","names":[],"sources":["../../../../src/storage/domains/audit/actions.ts"],"sourcesContent":["/**\n * Every action the trail can hold, by namespace. Register new ones in the\n * WorkOS dashboard under Audit Logs → Events before the mirror accepts them.\n */\nexport const AUDIT_ACTIONS = {\n work_item: ['created', 'updated', 'deleted', 'stage_moved', 'transition_rejected', 'labels_reconciled'],\n run: ['started', 'ended', 'approved', 'dismissed', 'retry', 'queued', 'rejected'],\n git: ['commit', 'push', 'pr_opened'],\n agent: ['commit', 'push', 'pr_opened', 'signaled'],\n intake: ['config_updated', 'binding_updated', 'label_route_updated'],\n session: ['owner_transferred'],\n board: ['created', 'updated', 'deleted', 'reset'],\n skill: ['updated', 'reverted'],\n intake_route: ['created', 'updated', 'deleted', 'reordered'],\n} as const;\n\nexport type AuditNamespace = keyof typeof AUDIT_ACTIONS;\n\nexport type AuditAction = {\n [Namespace in AuditNamespace]: `factory.${Namespace}.${(typeof AUDIT_ACTIONS)[Namespace][number]}`;\n}[AuditNamespace];\n\nexport function isAuditNamespace(value: string): value is AuditNamespace {\n return Object.hasOwn(AUDIT_ACTIONS, value);\n}\n\nexport function auditNamespaces(): AuditNamespace[] {\n return Object.keys(AUDIT_ACTIONS).filter(isAuditNamespace);\n}\n\nexport function parseAuditAction(action: string): { namespace: AuditNamespace; leaf: string } | undefined {\n const [prefix, namespace, leaf, ...rest] = action.split('.');\n if (prefix !== 'factory' || namespace === undefined || leaf === undefined || rest.length > 0) return undefined;\n return isAuditNamespace(namespace) ? { namespace, leaf } : undefined;\n}\n\nexport function isAuditAction(value: string): value is AuditAction {\n const parsed = parseAuditAction(value);\n return parsed !== undefined && AUDIT_ACTIONS[parsed.namespace].some(leaf => leaf === parsed.leaf);\n}\n\nexport function auditActionsInNamespaces(namespaces: readonly AuditNamespace[]): string[] {\n return namespaces.flatMap(namespace => AUDIT_ACTIONS[namespace].map(leaf => `factory.${namespace}.${leaf}`));\n}\n"],"mappings":";;;;;AAIA,MAAa,gBAAgB;CAC3B,WAAW;EAAC;EAAW;EAAW;EAAW;EAAe;EAAuB;CAAmB;CACtG,KAAK;EAAC;EAAW;EAAS;EAAY;EAAa;EAAS;EAAU;CAAU;CAChF,KAAK;EAAC;EAAU;EAAQ;CAAW;CACnC,OAAO;EAAC;EAAU;EAAQ;EAAa;CAAU;CACjD,QAAQ;EAAC;EAAkB;EAAmB;CAAqB;CACnE,SAAS,CAAC,mBAAmB;CAC7B,OAAO;EAAC;EAAW;EAAW;EAAW;CAAO;CAChD,OAAO,CAAC,WAAW,UAAU;CAC7B,cAAc;EAAC;EAAW;EAAW;EAAW;CAAW;
|
|
1
|
+
{"version":3,"file":"actions.js","names":[],"sources":["../../../../src/storage/domains/audit/actions.ts"],"sourcesContent":["/**\n * Every action the trail can hold, by namespace. Register new ones in the\n * WorkOS dashboard under Audit Logs → Events before the mirror accepts them.\n */\nexport const AUDIT_ACTIONS = {\n work_item: ['created', 'updated', 'deleted', 'stage_moved', 'transition_rejected', 'labels_reconciled'],\n run: ['started', 'ended', 'approved', 'dismissed', 'retry', 'queued', 'rejected'],\n git: ['commit', 'push', 'pr_opened'],\n agent: ['commit', 'push', 'pr_opened', 'signaled'],\n intake: ['config_updated', 'binding_updated', 'label_route_updated'],\n session: ['owner_transferred'],\n board: ['created', 'updated', 'deleted', 'reset'],\n skill: ['updated', 'reverted'],\n intake_route: ['created', 'updated', 'deleted', 'reordered'],\n sandbox_env: ['set', 'updated', 'deleted'],\n} as const;\n\nexport type AuditNamespace = keyof typeof AUDIT_ACTIONS;\n\nexport type AuditAction = {\n [Namespace in AuditNamespace]: `factory.${Namespace}.${(typeof AUDIT_ACTIONS)[Namespace][number]}`;\n}[AuditNamespace];\n\nexport function isAuditNamespace(value: string): value is AuditNamespace {\n return Object.hasOwn(AUDIT_ACTIONS, value);\n}\n\nexport function auditNamespaces(): AuditNamespace[] {\n return Object.keys(AUDIT_ACTIONS).filter(isAuditNamespace);\n}\n\nexport function parseAuditAction(action: string): { namespace: AuditNamespace; leaf: string } | undefined {\n const [prefix, namespace, leaf, ...rest] = action.split('.');\n if (prefix !== 'factory' || namespace === undefined || leaf === undefined || rest.length > 0) return undefined;\n return isAuditNamespace(namespace) ? { namespace, leaf } : undefined;\n}\n\nexport function isAuditAction(value: string): value is AuditAction {\n const parsed = parseAuditAction(value);\n return parsed !== undefined && AUDIT_ACTIONS[parsed.namespace].some(leaf => leaf === parsed.leaf);\n}\n\nexport function auditActionsInNamespaces(namespaces: readonly AuditNamespace[]): string[] {\n return namespaces.flatMap(namespace => AUDIT_ACTIONS[namespace].map(leaf => `factory.${namespace}.${leaf}`));\n}\n"],"mappings":";;;;;AAIA,MAAa,gBAAgB;CAC3B,WAAW;EAAC;EAAW;EAAW;EAAW;EAAe;EAAuB;CAAmB;CACtG,KAAK;EAAC;EAAW;EAAS;EAAY;EAAa;EAAS;EAAU;CAAU;CAChF,KAAK;EAAC;EAAU;EAAQ;CAAW;CACnC,OAAO;EAAC;EAAU;EAAQ;EAAa;CAAU;CACjD,QAAQ;EAAC;EAAkB;EAAmB;CAAqB;CACnE,SAAS,CAAC,mBAAmB;CAC7B,OAAO;EAAC;EAAW;EAAW;EAAW;CAAO;CAChD,OAAO,CAAC,WAAW,UAAU;CAC7B,cAAc;EAAC;EAAW;EAAW;EAAW;CAAW;CAC3D,aAAa;EAAC;EAAO;EAAW;CAAS;AAC3C;AAQA,SAAgB,iBAAiB,OAAwC;CACvE,OAAO,OAAO,OAAO,eAAe,KAAK;AAC3C;AAEA,SAAgB,kBAAoC;CAClD,OAAO,OAAO,KAAK,aAAa,CAAC,CAAC,OAAO,gBAAgB;AAC3D;AAEA,SAAgB,iBAAiB,QAAyE;CACxG,MAAM,CAAC,QAAQ,WAAW,MAAM,GAAG,QAAQ,OAAO,MAAM,GAAG;CAC3D,IAAI,WAAW,aAAa,cAAc,KAAA,KAAa,SAAS,KAAA,KAAa,KAAK,SAAS,GAAG,OAAO,KAAA;CACrG,OAAO,iBAAiB,SAAS,IAAI;EAAE;EAAW;CAAK,IAAI,KAAA;AAC7D;AAEA,SAAgB,cAAc,OAAqC;CACjE,MAAM,SAAS,iBAAiB,KAAK;CACrC,OAAO,WAAW,KAAA,KAAa,cAAc,OAAO,UAAU,CAAC,MAAK,SAAQ,SAAS,OAAO,IAAI;AAClG;AAEA,SAAgB,yBAAyB,YAAiD;CACxF,OAAO,WAAW,SAAQ,cAAa,cAAc,UAAU,CAAC,KAAI,SAAQ,WAAW,UAAU,GAAG,MAAM,CAAC;AAC7G"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { FactoryStorageDomain } from '@mastra/core/storage';
|
|
2
|
+
import type { CollectionSchema } from '@mastra/core/storage';
|
|
3
|
+
import type { FactorySecretEncryption } from '../../../secret-encryption.js';
|
|
4
|
+
/** Where a sandbox environment variable applies. */
|
|
5
|
+
export type SandboxEnvAppliesTo = 'build' | 'runtime' | 'both';
|
|
6
|
+
/** A variable's metadata. Values never leave the store through this shape. */
|
|
7
|
+
export interface SandboxEnvMetadata {
|
|
8
|
+
name: string;
|
|
9
|
+
appliesTo: SandboxEnvAppliesTo;
|
|
10
|
+
createdBy: string;
|
|
11
|
+
updatedBy: string;
|
|
12
|
+
createdAt: Date;
|
|
13
|
+
updatedAt: Date;
|
|
14
|
+
}
|
|
15
|
+
export interface SandboxEnvRevisions {
|
|
16
|
+
/** Changes on every add, edit or delete. */
|
|
17
|
+
revision: string;
|
|
18
|
+
/** Changes only when a Build-applicable variable is added, edited, deleted or moved into or out of build. */
|
|
19
|
+
buildRevision: string;
|
|
20
|
+
}
|
|
21
|
+
export interface ResolvedSandboxEnvs extends SandboxEnvRevisions {
|
|
22
|
+
runtime: Record<string, string>;
|
|
23
|
+
build: Record<string, string>;
|
|
24
|
+
}
|
|
25
|
+
export interface SetSandboxEnvInput {
|
|
26
|
+
name: string;
|
|
27
|
+
value: string;
|
|
28
|
+
appliesTo: SandboxEnvAppliesTo;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* The surface routes and sandbox wiring depend on, so another backend (for
|
|
32
|
+
* example a vault) can replace {@link SandboxEnvsStorage} without touching them.
|
|
33
|
+
*/
|
|
34
|
+
export interface SandboxEnvStore {
|
|
35
|
+
list(orgId: string, projectId: string): Promise<SandboxEnvMetadata[]>;
|
|
36
|
+
set(orgId: string, projectId: string, input: SetSandboxEnvInput, actorId: string): Promise<SandboxEnvMetadata>;
|
|
37
|
+
updateAppliesTo(orgId: string, projectId: string, name: string, appliesTo: SandboxEnvAppliesTo, actorId: string): Promise<SandboxEnvMetadata | null>;
|
|
38
|
+
delete(orgId: string, projectId: string, name: string): Promise<boolean>;
|
|
39
|
+
revisions(orgId: string, projectId: string): Promise<SandboxEnvRevisions | null>;
|
|
40
|
+
resolve(orgId: string, projectId: string): Promise<ResolvedSandboxEnvs>;
|
|
41
|
+
}
|
|
42
|
+
export declare const SANDBOX_ENVS_SCHEMA: CollectionSchema;
|
|
43
|
+
export declare const SANDBOX_ENV_REVISIONS_SCHEMA: CollectionSchema;
|
|
44
|
+
/**
|
|
45
|
+
* Factory-wide sandbox environment variables, values encrypted with
|
|
46
|
+
* {@link FactorySecretEncryption}. Every write lands the variable row first
|
|
47
|
+
* and the revision row second (there is no transaction primitive), so a
|
|
48
|
+
* reader that sees a new revision always sees the rows behind it. Revisions
|
|
49
|
+
* are random ids, never derived from values.
|
|
50
|
+
*/
|
|
51
|
+
export declare class SandboxEnvsStorage extends FactoryStorageDomain implements SandboxEnvStore {
|
|
52
|
+
#private;
|
|
53
|
+
private readonly encryption;
|
|
54
|
+
constructor(encryption?: FactorySecretEncryption);
|
|
55
|
+
init(): Promise<void>;
|
|
56
|
+
dangerouslyClearAll(): Promise<void>;
|
|
57
|
+
list(orgId: string, projectId: string): Promise<SandboxEnvMetadata[]>;
|
|
58
|
+
/** Create or replace a variable. Bumps the build revision whenever the old or new row applies to build. */
|
|
59
|
+
set(orgId: string, projectId: string, input: SetSandboxEnvInput, actorId: string): Promise<SandboxEnvMetadata>;
|
|
60
|
+
updateAppliesTo(orgId: string, projectId: string, name: string, appliesTo: SandboxEnvAppliesTo, actorId: string): Promise<SandboxEnvMetadata | null>;
|
|
61
|
+
delete(orgId: string, projectId: string, name: string): Promise<boolean>;
|
|
62
|
+
revisions(orgId: string, projectId: string): Promise<SandboxEnvRevisions | null>;
|
|
63
|
+
/**
|
|
64
|
+
* Decrypted values split by where they apply, plus the revisions read
|
|
65
|
+
* before them: if a write lands in between, the caller holds an older
|
|
66
|
+
* revision than the values it got and simply reloads on its next check.
|
|
67
|
+
*/
|
|
68
|
+
resolve(orgId: string, projectId: string): Promise<ResolvedSandboxEnvs>;
|
|
69
|
+
}
|
|
70
|
+
//# sourceMappingURL=base.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base.d.ts","sourceRoot":"","sources":["../../../../src/storage/domains/sandbox-envs/base.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,oBAAoB,EAAwB,MAAM,sBAAsB,CAAC;AAClF,OAAO,KAAK,EAAE,gBAAgB,EAAqB,MAAM,sBAAsB,CAAC;AAEhF,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,+BAA+B,CAAC;AAE7E,oDAAoD;AACpD,MAAM,MAAM,mBAAmB,GAAG,OAAO,GAAG,SAAS,GAAG,MAAM,CAAC;AAE/D,8EAA8E;AAC9E,MAAM,WAAW,kBAAkB;IACjC,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,mBAAmB,CAAC;IAC/B,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,IAAI,CAAC;IAChB,SAAS,EAAE,IAAI,CAAC;CACjB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