@mastra/factory 0.19.2-alpha.8 → 0.20.0-alpha.10
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/factory.js +7 -7
- package/dist/factory.js.map +1 -1
- package/dist/integrations/base.d.ts +5 -5
- package/dist/integrations/base.d.ts.map +1 -1
- package/dist/integrations/github/default-rules.d.ts +4 -4
- package/dist/integrations/github/default-rules.d.ts.map +1 -1
- package/dist/integrations/github/default-rules.js +13 -2
- package/dist/integrations/github/default-rules.js.map +1 -1
- package/dist/integrations/github/integration.js +1 -1
- package/dist/integrations/github/provenance.d.ts.map +1 -1
- package/dist/integrations/github/provenance.js +2 -1
- package/dist/integrations/github/provenance.js.map +1 -1
- package/dist/integrations/github/routes.d.ts.map +1 -1
- package/dist/integrations/github/routes.js +3 -1
- package/dist/integrations/github/routes.js.map +1 -1
- package/dist/integrations/github/rules.d.ts +8 -0
- package/dist/integrations/github/rules.d.ts.map +1 -1
- package/dist/integrations/github/rules.js +2 -2
- package/dist/integrations/github/rules.js.map +1 -1
- package/dist/integrations/github/session-subscriptions.js +1 -1
- package/dist/integrations/platform/github/integration.js +1 -1
- package/dist/integrations/slack/integration.js +1 -1
- package/dist/integrations/slack/integration.js.map +1 -1
- package/dist/integrations/slack/slack.d.ts +10 -11
- package/dist/integrations/slack/slack.d.ts.map +1 -1
- package/dist/integrations/slack/slack.js +36 -37
- package/dist/integrations/slack/slack.js.map +1 -1
- package/dist/routes/config.d.ts +15 -61
- package/dist/routes/config.d.ts.map +1 -1
- package/dist/routes/config.js +40 -217
- package/dist/routes/config.js.map +1 -1
- package/dist/routes/projects.d.ts.map +1 -1
- package/dist/routes/projects.js +2 -17
- package/dist/routes/projects.js.map +1 -1
- package/dist/routes/surface.d.ts +4 -4
- package/dist/routes/surface.d.ts.map +1 -1
- package/dist/routes/surface.js +3 -3
- package/dist/routes/surface.js.map +1 -1
- package/dist/session/default-model-hydration.d.ts +40 -0
- package/dist/session/default-model-hydration.d.ts.map +1 -0
- package/dist/session/default-model-hydration.js +45 -0
- package/dist/session/default-model-hydration.js.map +1 -0
- package/dist/session/factory-session.js +1 -1
- package/dist/session/factory-session.js.map +1 -1
- package/dist/storage/domains/model-defaults/base.d.ts +29 -0
- package/dist/storage/domains/model-defaults/base.d.ts.map +1 -0
- package/dist/storage/domains/model-defaults/base.js +79 -0
- package/dist/storage/domains/model-defaults/base.js.map +1 -0
- package/package.json +7 -7
- package/dist/session/model-pack-hydration.d.ts +0 -55
- package/dist/session/model-pack-hydration.d.ts.map +0 -1
- package/dist/session/model-pack-hydration.js +0 -56
- package/dist/session/model-pack-hydration.js.map +0 -1
- package/dist/storage/domains/model-packs/base.d.ts +0 -75
- package/dist/storage/domains/model-packs/base.d.ts.map +0 -1
- package/dist/storage/domains/model-packs/base.js +0 -185
- package/dist/storage/domains/model-packs/base.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/routes/config.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,+BAA+B,CAAC;AAGjE,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/routes/config.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,+BAA+B,CAAC;AAGjE,OAAO,KAAK,EAAE,cAAc,EAAuB,MAAM,mCAAmC,CAAC;AAQ7F,OAAO,KAAK,EAAyB,oBAAoB,EAAE,MAAM,sCAAsC,CAAC;AACxG,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAUpD,OAAO,KAAK,EACV,gBAAgB,EAChB,gBAAgB,EAChB,uBAAuB,EACxB,MAAM,wCAAwC,CAAC;AAChD,OAAO,KAAK,EAAwB,sBAAsB,EAAE,MAAM,6CAA6C,CAAC;AAEhH,OAAO,KAAK,EAIV,qBAAqB,EAC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AK,IAAI,CAAC;IAC5E,6FAA6F;IAC7F,wBAAwB,CAAC,EAAE,CAAC,MAAM,EAAE;QAAE,KAAK,EAAE,MAAM,CAAA;KAAE,KAAK,IAAI,CAAC;IAC/D;;;OAGG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,qBAAa,YAAa,SAAQ,KAAK,CAAC,gBAAgB,CAAC;IACvD,MAAM,IAAI,QAAQ,EAAE;CAmtBrB"}
|
package/dist/routes/config.js
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
import { peekSessionSandbox } from "../sandbox/session-sandbox.js";
|
|
2
1
|
import { WEB_OAUTH_FLOW_KINDS, getAuthProviderId, listTenantCredentialsForRequest, resolveCredentialContext, tenantOrgId } from "./provider-credentials.js";
|
|
3
2
|
import { Route } from "./route.js";
|
|
4
3
|
import { factoryMemorySettingsUserId } from "../storage/domains/memory-settings/base.js";
|
|
5
4
|
import { applyStoredMemorySettings } from "../session/memory-settings-hydration.js";
|
|
6
|
-
import { applyActiveModelPack } from "../session/model-pack-hydration.js";
|
|
7
5
|
import { seedPersonalOmDefaults } from "./om-seed.js";
|
|
8
6
|
import { registerApiRoute } from "@mastra/core/server";
|
|
9
|
-
import {
|
|
7
|
+
import { z } from "zod";
|
|
8
|
+
import { resolveProviderOMDefault } from "@mastra/code-sdk/onboarding/packs";
|
|
10
9
|
import { DEFAULT_OM_MODEL_ID } from "@mastra/code-sdk/constants";
|
|
11
10
|
import { THINKING_LEVEL_VALUES, getCustomProviderId, isThinkingLevelSetting, loadSettings, saveSettings } from "@mastra/code-sdk/onboarding/settings";
|
|
12
11
|
//#region src/routes/config.ts
|
|
@@ -162,67 +161,28 @@ async function buildProviderAccess({ controller, authStorage, tenantCredentials
|
|
|
162
161
|
function canUseModelProvider(access, provider) {
|
|
163
162
|
return Boolean(access[provider]);
|
|
164
163
|
}
|
|
165
|
-
/** Resolve the
|
|
166
|
-
async function
|
|
164
|
+
/** Resolve the default-model context for a request, or a ready-to-return error response. */
|
|
165
|
+
async function resolveModelDefaultsContext({ c, auth, modelDefaults }) {
|
|
167
166
|
await auth.ensureUser(c);
|
|
168
167
|
const tenant = auth.tenant(c);
|
|
169
168
|
if (!tenant && auth.enabled()) return { response: c.json({ error: "unauthorized" }, 401) };
|
|
170
|
-
if (
|
|
171
|
-
await
|
|
169
|
+
if (modelDefaults) try {
|
|
170
|
+
await modelDefaults.ensureReady();
|
|
172
171
|
return tenant ? {
|
|
173
|
-
storage:
|
|
172
|
+
storage: modelDefaults,
|
|
174
173
|
orgId: tenantOrgId(tenant),
|
|
175
174
|
userId: tenant.userId
|
|
176
175
|
} : {
|
|
177
|
-
storage:
|
|
176
|
+
storage: modelDefaults,
|
|
178
177
|
orgId: "local",
|
|
179
178
|
userId: "local"
|
|
180
179
|
};
|
|
181
180
|
} catch {}
|
|
182
181
|
return { response: c.json({
|
|
183
|
-
error: "
|
|
184
|
-
message: "
|
|
182
|
+
error: "model_defaults_unavailable",
|
|
183
|
+
message: "Default model storage is unavailable — the app database is not configured or failed to start."
|
|
185
184
|
}, 503) };
|
|
186
185
|
}
|
|
187
|
-
async function authorizePackSession({ c, auth, sessions, packContext, resourceId, scope }) {
|
|
188
|
-
if (!auth.enabled()) return null;
|
|
189
|
-
if (!sessions) return c.json({ error: "session_authorization_unavailable" }, 503);
|
|
190
|
-
const sourceSession = await sessions.getBySessionId(resourceId);
|
|
191
|
-
const liveWorkdir = peekSessionSandbox(sourceSession?.id ?? "")?.workdir;
|
|
192
|
-
if (!sourceSession || sourceSession.orgId !== packContext.orgId || sourceSession.userId !== packContext.userId || scope !== void 0 && scope !== liveWorkdir) return c.json({ error: `No session for resourceId "${resourceId}"` }, 404);
|
|
193
|
-
return null;
|
|
194
|
-
}
|
|
195
|
-
/** DB row → the `ModePack` shape the packs list and activation flow consume. */
|
|
196
|
-
function recordToModePack(record) {
|
|
197
|
-
return {
|
|
198
|
-
id: `custom:${record.id}`,
|
|
199
|
-
name: record.name,
|
|
200
|
-
description: "Saved custom pack",
|
|
201
|
-
models: record.models
|
|
202
|
-
};
|
|
203
|
-
}
|
|
204
|
-
/**
|
|
205
|
-
* List available model packs (built-in, gated by provider access, plus saved
|
|
206
|
-
* custom packs from the request's pack context). Drops the synthetic
|
|
207
|
-
* "New Custom" placeholder because the web client has its own create flow.
|
|
208
|
-
* `active` marks the user's default pack for new interactive chats.
|
|
209
|
-
*/
|
|
210
|
-
async function listModelPacks({ controller, authStorage, tenantCredentials, packContext, activePackId }) {
|
|
211
|
-
return [...getAvailableModePacks(await buildProviderAccess({
|
|
212
|
-
controller,
|
|
213
|
-
authStorage,
|
|
214
|
-
tenantCredentials
|
|
215
|
-
})), ...(await packContext.storage.list({ orgId: packContext.orgId })).map(recordToModePack)].filter((p) => p.id !== "custom").map((p) => ({
|
|
216
|
-
...p,
|
|
217
|
-
custom: p.id.startsWith("custom:"),
|
|
218
|
-
active: activePackId != null && p.id === activePackId
|
|
219
|
-
}));
|
|
220
|
-
}
|
|
221
|
-
async function resolveSessionModelPackId(session) {
|
|
222
|
-
if (!session?.thread.getId()) return null;
|
|
223
|
-
const value = await session.thread.getSetting({ key: "activeModelPackId" });
|
|
224
|
-
return typeof value === "string" ? value : null;
|
|
225
|
-
}
|
|
226
186
|
function readOMConfig(session) {
|
|
227
187
|
const observeAttachments = (session.state.get() ?? {}).observeAttachments;
|
|
228
188
|
return {
|
|
@@ -597,216 +557,79 @@ var ConfigRoutes = class extends Route {
|
|
|
597
557
|
}
|
|
598
558
|
}
|
|
599
559
|
}),
|
|
600
|
-
registerApiRoute("/web/config/model
|
|
560
|
+
registerApiRoute("/web/config/default-model", {
|
|
601
561
|
method: "GET",
|
|
602
562
|
requiresAuth: false,
|
|
603
563
|
handler: async (c) => {
|
|
604
|
-
const
|
|
564
|
+
const context = await resolveModelDefaultsContext({
|
|
605
565
|
c: loose(c),
|
|
606
566
|
auth,
|
|
607
|
-
|
|
567
|
+
modelDefaults: options.modelDefaults
|
|
608
568
|
});
|
|
609
|
-
if ("response" in
|
|
610
|
-
const resourceId = c.req.query("resourceId");
|
|
611
|
-
const scope = c.req.query("scope") || void 0;
|
|
569
|
+
if ("response" in context) return context.response;
|
|
612
570
|
try {
|
|
613
|
-
const
|
|
614
|
-
orgId:
|
|
615
|
-
userId:
|
|
616
|
-
}))?.packId ?? null;
|
|
617
|
-
if (resourceId) {
|
|
618
|
-
const unauthorized = await authorizePackSession({
|
|
619
|
-
c: loose(c),
|
|
620
|
-
auth,
|
|
621
|
-
sessions: options.sourceControlSessions,
|
|
622
|
-
packContext,
|
|
623
|
-
resourceId,
|
|
624
|
-
scope
|
|
625
|
-
});
|
|
626
|
-
if (unauthorized) return unauthorized;
|
|
627
|
-
}
|
|
628
|
-
const sessionPackId = await resolveSessionModelPackId(resourceId ? await controller.getSessionByResource?.(resourceId, scope) : void 0);
|
|
629
|
-
const tenantCredentials = await listTenantCredentialsForRequest({
|
|
630
|
-
c: loose(c),
|
|
631
|
-
auth,
|
|
632
|
-
credentials: options.modelCredentials
|
|
633
|
-
});
|
|
634
|
-
return c.json({
|
|
635
|
-
packs: await listModelPacks({
|
|
636
|
-
controller,
|
|
637
|
-
authStorage: tenantCredentials ? void 0 : authStorage,
|
|
638
|
-
tenantCredentials,
|
|
639
|
-
packContext,
|
|
640
|
-
activePackId
|
|
641
|
-
}),
|
|
642
|
-
activePackId,
|
|
643
|
-
sessionPackId
|
|
571
|
+
const record = await context.storage.get({
|
|
572
|
+
orgId: context.orgId,
|
|
573
|
+
userId: context.userId
|
|
644
574
|
});
|
|
575
|
+
return c.json({ modelId: record?.modelId ?? null });
|
|
645
576
|
} catch (error) {
|
|
646
577
|
return c.json({ error: error instanceof Error ? error.message : String(error) }, 500);
|
|
647
578
|
}
|
|
648
579
|
}
|
|
649
580
|
}),
|
|
650
|
-
registerApiRoute("/web/config/model
|
|
651
|
-
method: "
|
|
581
|
+
registerApiRoute("/web/config/default-model", {
|
|
582
|
+
method: "PUT",
|
|
652
583
|
requiresAuth: false,
|
|
653
584
|
handler: async (c) => {
|
|
654
|
-
const
|
|
585
|
+
const context = await resolveModelDefaultsContext({
|
|
655
586
|
c: loose(c),
|
|
656
587
|
auth,
|
|
657
|
-
|
|
588
|
+
modelDefaults: options.modelDefaults
|
|
658
589
|
});
|
|
659
|
-
if ("response" in
|
|
590
|
+
if ("response" in context) return context.response;
|
|
660
591
|
let body;
|
|
661
592
|
try {
|
|
662
593
|
body = await c.req.json();
|
|
663
594
|
} catch {
|
|
664
595
|
return c.json({ error: "Invalid JSON body" }, 400);
|
|
665
596
|
}
|
|
666
|
-
const
|
|
667
|
-
if (!
|
|
668
|
-
const
|
|
669
|
-
const build = typeof m.build === "string" ? m.build.trim() : "";
|
|
670
|
-
const plan = typeof m.plan === "string" ? m.plan.trim() : "";
|
|
671
|
-
const fast = typeof m.fast === "string" ? m.fast.trim() : "";
|
|
672
|
-
if (!build || !plan || !fast) return c.json({ error: "models.build, models.plan and models.fast are required" }, 400);
|
|
597
|
+
const parsed = z.object({ modelId: z.string().trim().min(1).max(256) }).safeParse(body);
|
|
598
|
+
if (!parsed.success) return c.json({ error: "Missing required field: modelId" }, 400);
|
|
599
|
+
const { modelId } = parsed.data;
|
|
673
600
|
try {
|
|
674
|
-
|
|
675
|
-
orgId:
|
|
676
|
-
userId:
|
|
677
|
-
|
|
678
|
-
name,
|
|
679
|
-
models: {
|
|
680
|
-
build,
|
|
681
|
-
plan,
|
|
682
|
-
fast
|
|
683
|
-
}
|
|
684
|
-
}
|
|
685
|
-
});
|
|
686
|
-
return c.json({
|
|
687
|
-
ok: true,
|
|
688
|
-
pack: recordToModePack(record)
|
|
689
|
-
});
|
|
690
|
-
} catch (error) {
|
|
691
|
-
return c.json({ error: error instanceof Error ? error.message : String(error) }, 500);
|
|
692
|
-
}
|
|
693
|
-
}
|
|
694
|
-
}),
|
|
695
|
-
registerApiRoute("/web/config/model-packs/active", {
|
|
696
|
-
method: "DELETE",
|
|
697
|
-
requiresAuth: false,
|
|
698
|
-
handler: async (c) => {
|
|
699
|
-
const packContext = await resolvePackContext({
|
|
700
|
-
c: loose(c),
|
|
701
|
-
auth,
|
|
702
|
-
modelPacks: options.modelPacks
|
|
703
|
-
});
|
|
704
|
-
if ("response" in packContext) return packContext.response;
|
|
705
|
-
try {
|
|
706
|
-
await packContext.storage.clearActive({
|
|
707
|
-
orgId: packContext.orgId,
|
|
708
|
-
userId: packContext.userId
|
|
601
|
+
await context.storage.set({
|
|
602
|
+
orgId: context.orgId,
|
|
603
|
+
userId: context.userId,
|
|
604
|
+
modelId
|
|
709
605
|
});
|
|
710
606
|
return c.json({
|
|
711
607
|
ok: true,
|
|
712
|
-
|
|
608
|
+
modelId
|
|
713
609
|
});
|
|
714
610
|
} catch (error) {
|
|
715
611
|
return c.json({ error: error instanceof Error ? error.message : String(error) }, 500);
|
|
716
612
|
}
|
|
717
613
|
}
|
|
718
614
|
}),
|
|
719
|
-
registerApiRoute("/web/config/model
|
|
615
|
+
registerApiRoute("/web/config/default-model", {
|
|
720
616
|
method: "DELETE",
|
|
721
617
|
requiresAuth: false,
|
|
722
618
|
handler: async (c) => {
|
|
723
|
-
const
|
|
619
|
+
const context = await resolveModelDefaultsContext({
|
|
724
620
|
c: loose(c),
|
|
725
621
|
auth,
|
|
726
|
-
|
|
622
|
+
modelDefaults: options.modelDefaults
|
|
727
623
|
});
|
|
728
|
-
if ("response" in
|
|
729
|
-
const id = decodeURIComponent(c.req.param("id"));
|
|
730
|
-
try {
|
|
731
|
-
const recordId = id.startsWith("custom:") ? id.slice(7) : id;
|
|
732
|
-
return await packContext.storage.delete({
|
|
733
|
-
orgId: packContext.orgId,
|
|
734
|
-
id: recordId
|
|
735
|
-
}) ? c.json({ ok: true }) : c.json({ error: `Unknown pack "${id}"` }, 404);
|
|
736
|
-
} catch (error) {
|
|
737
|
-
return c.json({ error: error instanceof Error ? error.message : String(error) }, 500);
|
|
738
|
-
}
|
|
739
|
-
}
|
|
740
|
-
}),
|
|
741
|
-
registerApiRoute("/web/config/model-packs/:id/activate", {
|
|
742
|
-
method: "POST",
|
|
743
|
-
requiresAuth: false,
|
|
744
|
-
handler: async (c) => {
|
|
745
|
-
const packContext = await resolvePackContext({
|
|
746
|
-
c: loose(c),
|
|
747
|
-
auth,
|
|
748
|
-
modelPacks: options.modelPacks
|
|
749
|
-
});
|
|
750
|
-
if ("response" in packContext) return packContext.response;
|
|
751
|
-
const id = decodeURIComponent(c.req.param("id"));
|
|
752
|
-
let body;
|
|
753
|
-
try {
|
|
754
|
-
body = await c.req.json();
|
|
755
|
-
} catch {
|
|
756
|
-
return c.json({ error: "Invalid JSON body" }, 400);
|
|
757
|
-
}
|
|
758
|
-
const target = body.target ?? "default";
|
|
759
|
-
if (target !== "default" && target !== "session") return c.json({ error: "target must be \"default\" or \"session\"" }, 400);
|
|
760
|
-
const resourceId = typeof body.resourceId === "string" && body.resourceId ? body.resourceId : void 0;
|
|
761
|
-
const scope = typeof body.scope === "string" && body.scope ? body.scope : void 0;
|
|
762
|
-
if (target === "session" && !resourceId) return c.json({ error: "Missing required field for session activation: resourceId" }, 400);
|
|
624
|
+
if ("response" in context) return context.response;
|
|
763
625
|
try {
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
auth,
|
|
768
|
-
sessions: options.sourceControlSessions,
|
|
769
|
-
packContext,
|
|
770
|
-
resourceId,
|
|
771
|
-
scope
|
|
772
|
-
});
|
|
773
|
-
if (unauthorized) return unauthorized;
|
|
774
|
-
}
|
|
775
|
-
const session = target === "session" && resourceId ? await controller.getSessionByResource?.(resourceId, scope) : void 0;
|
|
776
|
-
if (target === "session" && !session) return c.json({ error: `No session for resourceId "${resourceId}"` }, 404);
|
|
777
|
-
const tenantCredentials = await listTenantCredentialsForRequest({
|
|
778
|
-
c: loose(c),
|
|
779
|
-
auth,
|
|
780
|
-
credentials: options.modelCredentials
|
|
781
|
-
});
|
|
782
|
-
const pack = (await listModelPacks({
|
|
783
|
-
controller,
|
|
784
|
-
authStorage: tenantCredentials ? void 0 : authStorage,
|
|
785
|
-
tenantCredentials,
|
|
786
|
-
packContext
|
|
787
|
-
})).find((p) => p.id === id);
|
|
788
|
-
if (!pack) return c.json({ error: `Unknown pack "${id}"` }, 404);
|
|
789
|
-
if (target === "default") {
|
|
790
|
-
await packContext.storage.setActive({
|
|
791
|
-
orgId: packContext.orgId,
|
|
792
|
-
userId: packContext.userId,
|
|
793
|
-
packId: pack.id,
|
|
794
|
-
models: pack.models
|
|
795
|
-
});
|
|
796
|
-
return c.json({
|
|
797
|
-
ok: true,
|
|
798
|
-
target,
|
|
799
|
-
activePackId: pack.id
|
|
800
|
-
});
|
|
801
|
-
}
|
|
802
|
-
if (session) await applyActiveModelPack(session, {
|
|
803
|
-
packId: pack.id,
|
|
804
|
-
models: pack.models
|
|
626
|
+
await context.storage.clear({
|
|
627
|
+
orgId: context.orgId,
|
|
628
|
+
userId: context.userId
|
|
805
629
|
});
|
|
806
630
|
return c.json({
|
|
807
631
|
ok: true,
|
|
808
|
-
|
|
809
|
-
sessionPackId: pack.id
|
|
632
|
+
modelId: null
|
|
810
633
|
});
|
|
811
634
|
} catch (error) {
|
|
812
635
|
return c.json({ error: error instanceof Error ? error.message : String(error) }, 500);
|
|
@@ -1109,6 +932,6 @@ var ConfigRoutes = class extends Route {
|
|
|
1109
932
|
}
|
|
1110
933
|
};
|
|
1111
934
|
//#endregion
|
|
1112
|
-
export { ConfigRoutes, buildProviderAccess,
|
|
935
|
+
export { ConfigRoutes, buildProviderAccess, listProviders, readOMConfig };
|
|
1113
936
|
|
|
1114
937
|
//# sourceMappingURL=config.js.map
|