@mastra/factory 0.1.0-alpha.3 → 0.1.0-alpha.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +33 -0
- package/dist/factory.d.ts.map +1 -1
- package/dist/factory.js +772 -206
- package/dist/factory.js.map +1 -1
- package/dist/index.js +772 -206
- package/dist/index.js.map +1 -1
- package/dist/integrations/github/integration.d.ts +2 -2
- package/dist/integrations/github/integration.js +43 -11
- package/dist/integrations/github/integration.js.map +1 -1
- package/dist/integrations/github/provenance.js.map +1 -1
- package/dist/integrations/github/routes.js +10 -9
- package/dist/integrations/github/routes.js.map +1 -1
- package/dist/integrations/github/sandbox.d.ts +1 -0
- package/dist/integrations/github/sandbox.d.ts.map +1 -1
- package/dist/integrations/github/sandbox.js +2 -2
- package/dist/integrations/github/sandbox.js.map +1 -1
- package/dist/integrations/github/session-subscriptions.d.ts +3 -0
- package/dist/integrations/github/session-subscriptions.d.ts.map +1 -1
- package/dist/integrations/github/session-subscriptions.js +30 -0
- package/dist/integrations/github/session-subscriptions.js.map +1 -1
- package/dist/integrations/github/token-refresh.d.ts +6 -0
- package/dist/integrations/github/token-refresh.d.ts.map +1 -0
- package/dist/integrations/github/token-refresh.js +17 -0
- package/dist/integrations/github/token-refresh.js.map +1 -0
- package/dist/integrations/platform/github/integration.js +41 -9
- package/dist/integrations/platform/github/integration.js.map +1 -1
- package/dist/routes/config.d.ts +16 -11
- package/dist/routes/config.d.ts.map +1 -1
- package/dist/routes/config.js +222 -109
- package/dist/routes/config.js.map +1 -1
- package/dist/routes/custom-provider-source.d.ts +52 -0
- package/dist/routes/custom-provider-source.d.ts.map +1 -0
- package/dist/routes/custom-provider-source.js +107 -0
- package/dist/routes/custom-provider-source.js.map +1 -0
- package/dist/routes/oauth.js +33 -1
- package/dist/routes/oauth.js.map +1 -1
- package/dist/routes/surface.d.ts +4 -0
- package/dist/routes/surface.d.ts.map +1 -1
- package/dist/routes/surface.js +266 -110
- package/dist/routes/surface.js.map +1 -1
- package/dist/sandbox/fleet.d.ts +3 -0
- package/dist/sandbox/fleet.d.ts.map +1 -1
- package/dist/sandbox/fleet.js +10 -3
- package/dist/sandbox/fleet.js.map +1 -1
- package/dist/spa-static.d.ts +4 -5
- package/dist/spa-static.d.ts.map +1 -1
- package/dist/spa-static.js +5 -2
- package/dist/spa-static.js.map +1 -1
- package/dist/storage/domains/custom-providers/base.d.ts +57 -0
- package/dist/storage/domains/custom-providers/base.d.ts.map +1 -0
- package/dist/storage/domains/custom-providers/base.js +150 -0
- package/dist/storage/domains/custom-providers/base.js.map +1 -0
- package/dist/storage/domains/memory-settings/base.d.ts +62 -0
- package/dist/storage/domains/memory-settings/base.d.ts.map +1 -0
- package/dist/storage/domains/memory-settings/base.js +111 -0
- package/dist/storage/domains/memory-settings/base.js.map +1 -0
- package/dist/workspace.d.ts.map +1 -1
- package/dist/workspace.js +17 -0
- package/dist/workspace.js.map +1 -1
- package/package.json +7 -6
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
// src/storage/domains/memory-settings/base.ts
|
|
2
|
+
import { FactoryStorageDomain, UniqueViolationError } from "@mastra/core/storage";
|
|
3
|
+
var MEMORY_SETTINGS_SCHEMA = {
|
|
4
|
+
name: "memory_settings",
|
|
5
|
+
columns: {
|
|
6
|
+
id: { type: "uuid-pk" },
|
|
7
|
+
org_id: { type: "text" },
|
|
8
|
+
user_id: { type: "text" },
|
|
9
|
+
observer_model_id: { type: "text", nullable: true },
|
|
10
|
+
reflector_model_id: { type: "text", nullable: true },
|
|
11
|
+
observation_threshold: { type: "integer", nullable: true },
|
|
12
|
+
reflection_threshold: { type: "integer", nullable: true },
|
|
13
|
+
// 'auto' | true | false — json keeps the tri-state without string encoding.
|
|
14
|
+
observe_attachments: { type: "json", nullable: true },
|
|
15
|
+
created_at: { type: "timestamp" },
|
|
16
|
+
updated_at: { type: "timestamp" }
|
|
17
|
+
},
|
|
18
|
+
uniqueIndexes: [{ name: "memory_settings_org_user_key", columns: ["org_id", "user_id"] }]
|
|
19
|
+
};
|
|
20
|
+
function toRecord(row) {
|
|
21
|
+
return {
|
|
22
|
+
orgId: row.org_id,
|
|
23
|
+
userId: row.user_id,
|
|
24
|
+
observerModelId: row.observer_model_id,
|
|
25
|
+
reflectorModelId: row.reflector_model_id,
|
|
26
|
+
observationThreshold: row.observation_threshold,
|
|
27
|
+
reflectionThreshold: row.reflection_threshold,
|
|
28
|
+
observeAttachments: row.observe_attachments,
|
|
29
|
+
createdAt: row.created_at,
|
|
30
|
+
updatedAt: row.updated_at
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
function patchToColumns(patch) {
|
|
34
|
+
const columns = {};
|
|
35
|
+
if (patch.observerModelId !== void 0) columns.observer_model_id = patch.observerModelId;
|
|
36
|
+
if (patch.reflectorModelId !== void 0) columns.reflector_model_id = patch.reflectorModelId;
|
|
37
|
+
if (patch.observationThreshold !== void 0) columns.observation_threshold = patch.observationThreshold;
|
|
38
|
+
if (patch.reflectionThreshold !== void 0) columns.reflection_threshold = patch.reflectionThreshold;
|
|
39
|
+
if (patch.observeAttachments !== void 0) columns.observe_attachments = patch.observeAttachments;
|
|
40
|
+
return columns;
|
|
41
|
+
}
|
|
42
|
+
var MemorySettingsStorage = class extends FactoryStorageDomain {
|
|
43
|
+
constructor() {
|
|
44
|
+
super("memory-settings");
|
|
45
|
+
}
|
|
46
|
+
async init() {
|
|
47
|
+
await this.ensureCollections([MEMORY_SETTINGS_SCHEMA]);
|
|
48
|
+
}
|
|
49
|
+
async dangerouslyClearAll() {
|
|
50
|
+
await this.ops.deleteMany("memory_settings", {});
|
|
51
|
+
}
|
|
52
|
+
get #db() {
|
|
53
|
+
return this.ops;
|
|
54
|
+
}
|
|
55
|
+
async get({ orgId, userId }) {
|
|
56
|
+
const row = await this.#db.findOne("memory_settings", { org_id: orgId, user_id: userId });
|
|
57
|
+
return row ? toRecord(row) : null;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Upsert the user's row, writing only the knobs present in `patch`.
|
|
61
|
+
* `fillIfUnset` knobs are written only where the stored value is still
|
|
62
|
+
* `NULL`, decided inside the atomic update so concurrent explicit writes
|
|
63
|
+
* win over fills. Concurrent first writes are resolved via the shared
|
|
64
|
+
* insert-then-catch-unique-violation pattern (see `queue_health`).
|
|
65
|
+
*/
|
|
66
|
+
async patch({
|
|
67
|
+
orgId,
|
|
68
|
+
userId,
|
|
69
|
+
patch,
|
|
70
|
+
fillIfUnset
|
|
71
|
+
}) {
|
|
72
|
+
const now = /* @__PURE__ */ new Date();
|
|
73
|
+
const updateExisting = () => this.#db.updateAtomic("memory_settings", { org_id: orgId, user_id: userId }, (row) => {
|
|
74
|
+
const columns = { ...patchToColumns(patch), updated_at: now };
|
|
75
|
+
if (fillIfUnset?.observerModelId !== void 0 && row.observer_model_id == null) {
|
|
76
|
+
columns.observer_model_id = patch.observerModelId ?? fillIfUnset.observerModelId;
|
|
77
|
+
}
|
|
78
|
+
if (fillIfUnset?.reflectorModelId !== void 0 && row.reflector_model_id == null) {
|
|
79
|
+
columns.reflector_model_id = patch.reflectorModelId ?? fillIfUnset.reflectorModelId;
|
|
80
|
+
}
|
|
81
|
+
return columns;
|
|
82
|
+
});
|
|
83
|
+
const updated = await updateExisting();
|
|
84
|
+
if (updated) return toRecord(updated);
|
|
85
|
+
try {
|
|
86
|
+
const row = await this.#db.insertOne("memory_settings", {
|
|
87
|
+
org_id: orgId,
|
|
88
|
+
user_id: userId,
|
|
89
|
+
observer_model_id: fillIfUnset?.observerModelId ?? null,
|
|
90
|
+
reflector_model_id: fillIfUnset?.reflectorModelId ?? null,
|
|
91
|
+
observation_threshold: null,
|
|
92
|
+
reflection_threshold: null,
|
|
93
|
+
observe_attachments: null,
|
|
94
|
+
...patchToColumns(patch),
|
|
95
|
+
created_at: now,
|
|
96
|
+
updated_at: now
|
|
97
|
+
});
|
|
98
|
+
return toRecord(row);
|
|
99
|
+
} catch (error) {
|
|
100
|
+
if (!(error instanceof UniqueViolationError)) throw error;
|
|
101
|
+
const row = await updateExisting();
|
|
102
|
+
if (!row) throw error;
|
|
103
|
+
return toRecord(row);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
export {
|
|
108
|
+
MEMORY_SETTINGS_SCHEMA,
|
|
109
|
+
MemorySettingsStorage
|
|
110
|
+
};
|
|
111
|
+
//# sourceMappingURL=base.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/storage/domains/memory-settings/base.ts"],"sourcesContent":["import { FactoryStorageDomain, UniqueViolationError } from '@mastra/core/storage';\nimport type { CollectionSchema, FactoryStorageOps } from '@mastra/core/storage';\n\n/**\n * A user's persisted memory (observational-memory) configuration. The\n * DB-backed tenant counterpart of the local `settings.json` OM fields\n * (`observerModelOverride`, `reflectorModelOverride`, `omObservationThreshold`,\n * `omReflectionThreshold`, `omObserveAttachments`): one row per `(org, user)`,\n * every knob nullable so only explicitly-changed values are stored.\n */\nexport interface MemorySettingsRecord {\n orgId: string;\n userId: string;\n observerModelId: string | null;\n reflectorModelId: string | null;\n observationThreshold: number | null;\n reflectionThreshold: number | null;\n observeAttachments: 'auto' | boolean | null;\n createdAt: Date;\n updatedAt: Date;\n}\n\n/** Partial update — only the provided knobs are written. */\nexport interface MemorySettingsPatch {\n observerModelId?: string;\n reflectorModelId?: string;\n observationThreshold?: number;\n reflectionThreshold?: number;\n observeAttachments?: 'auto' | boolean;\n}\n\n/**\n * Knobs written only when the stored value is still unset (`NULL`). The check\n * happens inside the backend's atomic-update primitive, so a concurrent\n * explicit write to the same knob is never clobbered by a fill.\n */\nexport interface MemorySettingsFillIfUnset {\n observerModelId?: string;\n reflectorModelId?: string;\n}\n\nexport const MEMORY_SETTINGS_SCHEMA: CollectionSchema = {\n name: 'memory_settings',\n columns: {\n id: { type: 'uuid-pk' },\n org_id: { type: 'text' },\n user_id: { type: 'text' },\n observer_model_id: { type: 'text', nullable: true },\n reflector_model_id: { type: 'text', nullable: true },\n observation_threshold: { type: 'integer', nullable: true },\n reflection_threshold: { type: 'integer', nullable: true },\n // 'auto' | true | false — json keeps the tri-state without string encoding.\n observe_attachments: { type: 'json', nullable: true },\n created_at: { type: 'timestamp' },\n updated_at: { type: 'timestamp' },\n },\n uniqueIndexes: [{ name: 'memory_settings_org_user_key', columns: ['org_id', 'user_id'] }],\n};\n\ninterface MemorySettingsDbRow extends Record<string, unknown> {\n id: string;\n org_id: string;\n user_id: string;\n observer_model_id: string | null;\n reflector_model_id: string | null;\n observation_threshold: number | null;\n reflection_threshold: number | null;\n observe_attachments: 'auto' | boolean | null;\n created_at: Date;\n updated_at: Date;\n}\n\nfunction toRecord(row: MemorySettingsDbRow): MemorySettingsRecord {\n return {\n orgId: row.org_id,\n userId: row.user_id,\n observerModelId: row.observer_model_id,\n reflectorModelId: row.reflector_model_id,\n observationThreshold: row.observation_threshold,\n reflectionThreshold: row.reflection_threshold,\n observeAttachments: row.observe_attachments,\n createdAt: row.created_at,\n updatedAt: row.updated_at,\n };\n}\n\nfunction patchToColumns(patch: MemorySettingsPatch): Partial<MemorySettingsDbRow> {\n const columns: Partial<MemorySettingsDbRow> = {};\n if (patch.observerModelId !== undefined) columns.observer_model_id = patch.observerModelId;\n if (patch.reflectorModelId !== undefined) columns.reflector_model_id = patch.reflectorModelId;\n if (patch.observationThreshold !== undefined) columns.observation_threshold = patch.observationThreshold;\n if (patch.reflectionThreshold !== undefined) columns.reflection_threshold = patch.reflectionThreshold;\n if (patch.observeAttachments !== undefined) columns.observe_attachments = patch.observeAttachments;\n return columns;\n}\n\nexport class MemorySettingsStorage extends FactoryStorageDomain {\n constructor() {\n super('memory-settings');\n }\n\n async init(): Promise<void> {\n await this.ensureCollections([MEMORY_SETTINGS_SCHEMA]);\n }\n\n async dangerouslyClearAll(): Promise<void> {\n await this.ops.deleteMany('memory_settings', {});\n }\n\n get #db(): FactoryStorageOps {\n return this.ops;\n }\n\n async get({ orgId, userId }: { orgId: string; userId: string }): Promise<MemorySettingsRecord | null> {\n const row = await this.#db.findOne<MemorySettingsDbRow>('memory_settings', { org_id: orgId, user_id: userId });\n return row ? toRecord(row) : null;\n }\n\n /**\n * Upsert the user's row, writing only the knobs present in `patch`.\n * `fillIfUnset` knobs are written only where the stored value is still\n * `NULL`, decided inside the atomic update so concurrent explicit writes\n * win over fills. Concurrent first writes are resolved via the shared\n * insert-then-catch-unique-violation pattern (see `queue_health`).\n */\n async patch({\n orgId,\n userId,\n patch,\n fillIfUnset,\n }: {\n orgId: string;\n userId: string;\n patch: MemorySettingsPatch;\n fillIfUnset?: MemorySettingsFillIfUnset;\n }): Promise<MemorySettingsRecord> {\n const now = new Date();\n const updateExisting = () =>\n this.#db.updateAtomic<MemorySettingsDbRow>('memory_settings', { org_id: orgId, user_id: userId }, row => {\n const columns: Partial<MemorySettingsDbRow> = { ...patchToColumns(patch), updated_at: now };\n if (fillIfUnset?.observerModelId !== undefined && row.observer_model_id == null) {\n columns.observer_model_id = patch.observerModelId ?? fillIfUnset.observerModelId;\n }\n if (fillIfUnset?.reflectorModelId !== undefined && row.reflector_model_id == null) {\n columns.reflector_model_id = patch.reflectorModelId ?? fillIfUnset.reflectorModelId;\n }\n return columns;\n });\n\n const updated = await updateExisting();\n if (updated) return toRecord(updated);\n\n try {\n const row = await this.#db.insertOne<MemorySettingsDbRow>('memory_settings', {\n org_id: orgId,\n user_id: userId,\n observer_model_id: fillIfUnset?.observerModelId ?? null,\n reflector_model_id: fillIfUnset?.reflectorModelId ?? null,\n observation_threshold: null,\n reflection_threshold: null,\n observe_attachments: null,\n ...patchToColumns(patch),\n created_at: now,\n updated_at: now,\n });\n return toRecord(row);\n } catch (error) {\n if (!(error instanceof UniqueViolationError)) throw error;\n // Lost the first-write race — apply the patch to the winning row.\n const row = await updateExisting();\n if (!row) throw error;\n return toRecord(row);\n }\n }\n}\n"],"mappings":";AAAA,SAAS,sBAAsB,4BAA4B;AAyCpD,IAAM,yBAA2C;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mB;AAAA,QACnD,oBAAoB,aAAa,oBAAoB;AAAA,QACrD,uBAAuB;AAAA,QACvB,sBAAsB;AAAA,QACtB,qBAAqB;AAAA,QACrB,GAAG,eAAe,KAAK;AAAA,QACvB,YAAY;AAAA,QACZ,YAAY;AAAA,MACd,CAAC;AACD,aAAO,SAAS,GAAG;AAAA,IACrB,SAAS,OAAO;AACd,UAAI,EAAE,iBAAiB,sBAAuB,OAAM;AAEpD,YAAM,MAAM,MAAM,eAAe;AACjC,UAAI,CAAC,IAAK,OAAM;AAChB,aAAO,SAAS,GAAG;AAAA,IACrB;AAAA,EACF;AACF;","names":[]}
|
package/dist/workspace.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"workspace.d.ts","sourceRoot":"","sources":["../src/workspace.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,iBAAiB,EAAE,MAAM,4CAA4C,CAAC;AAE/E,OAAO,EAAE,mBAAmB,EAAE,MAAM,mCAAmC,CAAC;AAKxE,OAAO,EAAE,YAAY,EAAoB,SAAS,EAAE,MAAM,wBAAwB,CAAC;AAInF,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,cAAc,CAAC;AAC/D,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,sCAAsC,CAAC;
|
|
1
|
+
{"version":3,"file":"workspace.d.ts","sourceRoot":"","sources":["../src/workspace.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,iBAAiB,EAAE,MAAM,4CAA4C,CAAC;AAE/E,OAAO,EAAE,mBAAmB,EAAE,MAAM,mCAAmC,CAAC;AAKxE,OAAO,EAAE,YAAY,EAAoB,SAAS,EAAE,MAAM,wBAAwB,CAAC;AAInF,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,cAAc,CAAC;AAC/D,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,sCAAsC,CAAC;AAG9E,OAAO,KAAK,EAAuB,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAK5E,wBAAgB,wBAAwB,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,CAElE;AA+ED,KAAK,uBAAuB,GAAG,UAAU,CAAC,OAAO,mBAAmB,CAAC,CAAC,CAAC,CAAC,CAAC;AAEzE,MAAM,WAAW,6BAA6B;IAC5C,wEAAwE;IACxE,OAAO,CAAC,EAAE,0BAA0B,CAAC;IACrC,gFAAgF;IAChF,MAAM,CAAC,EAAE,iBAAiB,CAAC;IAC3B,0EAA0E;IAC1E,KAAK,CAAC,EAAE,YAAY,CAAC;CACtB;AAED,wBAAgB,sBAAsB,CAAC,OAAO,GAAE,6BAAkC,IAKlE,4CAA4C,uBAAuB,wVAqHlF;AAED,eAAO,MAAM,mBAAmB,+CAvH4B,uBAAuB,uVAuHxB,CAAC"}
|
package/dist/workspace.js
CHANGED
|
@@ -193,6 +193,12 @@ async function runWorktreeSetup(sandbox, worktreePath, command) {
|
|
|
193
193
|
}
|
|
194
194
|
}
|
|
195
195
|
|
|
196
|
+
// src/integrations/github/token-refresh.ts
|
|
197
|
+
var GITHUB_TOKEN_INJECTOR_CONTEXT_KEY = "factoryGithubTokenInjector";
|
|
198
|
+
function registerGithubTokenInjector(requestContext, injector) {
|
|
199
|
+
requestContext.set(GITHUB_TOKEN_INJECTOR_CONTEXT_KEY, injector);
|
|
200
|
+
}
|
|
201
|
+
|
|
196
202
|
// src/workspace.ts
|
|
197
203
|
var WORKSPACE_ID_PREFIX = "mfw";
|
|
198
204
|
var SESSION_CHECKPOINT_PREFIX = "mastracode-session";
|
|
@@ -260,6 +266,7 @@ var factorySkillExtension = {
|
|
|
260
266
|
function createWorkspaceFactory(options = {}) {
|
|
261
267
|
const { sandbox: sandboxConfig, github, fleet } = options;
|
|
262
268
|
const isLocalSandbox = sandboxConfig?.machine instanceof LocalSandbox;
|
|
269
|
+
const githubTokenInjectors = /* @__PURE__ */ new Map();
|
|
263
270
|
return async ({ requestContext, mastra, skillExtension }) => {
|
|
264
271
|
const effectiveSkillExtension = skillExtension ?? factorySkillExtension;
|
|
265
272
|
const ctx = requestContext.get("controller");
|
|
@@ -311,6 +318,8 @@ function createWorkspaceFactory(options = {}) {
|
|
|
311
318
|
const existing = mastra?.getWorkspaceById(workspaceId);
|
|
312
319
|
if (existing) {
|
|
313
320
|
existing.setToolsConfig(MASTRACODE_WORKSPACE_TOOLS);
|
|
321
|
+
const injectGithubToken2 = githubTokenInjectors.get(workspaceId);
|
|
322
|
+
if (injectGithubToken2) registerGithubTokenInjector(requestContext, injectGithubToken2);
|
|
314
323
|
return existing;
|
|
315
324
|
}
|
|
316
325
|
} catch {
|
|
@@ -341,6 +350,14 @@ function createWorkspaceFactory(options = {}) {
|
|
|
341
350
|
repoFullName
|
|
342
351
|
});
|
|
343
352
|
if (projectRepository.setupCommand) await runWorktreeSetup(sandbox, workdir, projectRepository.setupCommand);
|
|
353
|
+
const injectGithubToken = (freshToken) => {
|
|
354
|
+
if (!sandbox.setEnvironmentVariable) {
|
|
355
|
+
throw new Error("The active sandbox provider does not support runtime GitHub token refresh.");
|
|
356
|
+
}
|
|
357
|
+
sandbox.setEnvironmentVariable("GH_TOKEN", freshToken);
|
|
358
|
+
};
|
|
359
|
+
githubTokenInjectors.set(workspaceId, injectGithubToken);
|
|
360
|
+
registerGithubTokenInjector(requestContext, injectGithubToken);
|
|
344
361
|
const filesystem = new SandboxFilesystem({ sandbox, workdir });
|
|
345
362
|
const projectSkillPaths = [path2.join(configDir, "skills"), ".claude/skills", ".agents/skills"];
|
|
346
363
|
const skillPaths = [...effectiveSkillExtension?.paths ?? [], ...projectSkillPaths];
|