@mastra/factory 0.1.0-alpha.3 → 0.1.0-alpha.5
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 +42 -0
- package/dist/capabilities/intake.d.ts +2 -0
- package/dist/capabilities/intake.d.ts.map +1 -1
- package/dist/capabilities/version-control.d.ts +6 -0
- package/dist/capabilities/version-control.d.ts.map +1 -1
- package/dist/factory.d.ts.map +1 -1
- package/dist/factory.js +912 -242
- package/dist/factory.js.map +1 -1
- package/dist/index.js +912 -242
- package/dist/index.js.map +1 -1
- package/dist/integrations/github/integration.d.ts +2 -2
- package/dist/integrations/github/integration.js +45 -12
- package/dist/integrations/github/integration.js.map +1 -1
- package/dist/integrations/github/provenance.js.map +1 -1
- package/dist/integrations/github/routes.js +12 -10
- 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/api-client.d.ts +2 -0
- package/dist/integrations/platform/api-client.d.ts.map +1 -1
- package/dist/integrations/platform/api-client.js +7 -0
- package/dist/integrations/platform/api-client.js.map +1 -1
- package/dist/integrations/platform/github/event-worker.js.map +1 -1
- package/dist/integrations/platform/github/integration.d.ts.map +1 -1
- package/dist/integrations/platform/github/integration.js +173 -45
- package/dist/integrations/platform/github/integration.js.map +1 -1
- package/dist/integrations/platform/linear/integration.js +3 -0
- package/dist/integrations/platform/linear/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 +8 -7
|
@@ -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;
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/routes/config.ts"],"names":[],"mapp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,UAAU,EAAE,YAAY,CAAC;IACzB,WAAW,CAAC,EAAE,WAAW,CAAC;IAC1B,qEAAqE;IACrE,gBAAgB,CAAC,EAAE,uBAAuB,CAAC;IAC3C,sEAAsE;IACtE,UAAU,CAAC,EAAE,iBAAiB,CAAC;IAC/B,0EAA0E;IAC1E,cAAc,CAAC,EAAE,qBAAqB,CAAC;IACvC,+EAA+E;IAC/E,eAAe,CAAC,EAAE,sBAAsB,CAAC;IACzC,kFAAkF;IAClF,oBAAoB,CAAC,EAAE,CAAC,MAAM,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,CAAA;KAAE,KAAK,IAAI,CAAC;IAC5E,6FAA6F;IAC7F,wBAAwB,CAAC,EAAE,CAAC,MAAM,EAAE;QAAE,KAAK,EAAE,MAAM,CAAA;KAAE,KAAK,IAAI,CAAC;CAChE;AAED;;;;;;;;;;;;;GAaG;AACH,qBAAa,YAAa,SAAQ,KAAK,CAAC,gBAAgB,CAAC;IACvD,MAAM,IAAI,QAAQ,EAAE;CAmjBrB"}
|
package/dist/routes/config.js
CHANGED
|
@@ -1,17 +1,7 @@
|
|
|
1
1
|
// src/routes/config.ts
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
removeCustomProviderFromSettings,
|
|
5
|
-
upsertCustomProviderInSettings
|
|
6
|
-
} from "@mastra/code-sdk/onboarding/custom-providers";
|
|
7
|
-
import { applyOmRoleOverride, persistOmObserveAttachments } from "@mastra/code-sdk/onboarding/om-settings";
|
|
2
|
+
import { DEFAULT_OM_MODEL_ID } from "@mastra/code-sdk/constants";
|
|
8
3
|
import { getAvailableModePacks } from "@mastra/code-sdk/onboarding/packs";
|
|
9
|
-
import {
|
|
10
|
-
getCustomProviderId,
|
|
11
|
-
loadSettings,
|
|
12
|
-
saveSettings,
|
|
13
|
-
THREAD_ACTIVE_MODEL_PACK_ID_KEY
|
|
14
|
-
} from "@mastra/code-sdk/onboarding/settings";
|
|
4
|
+
import { getCustomProviderId, THREAD_ACTIVE_MODEL_PACK_ID_KEY } from "@mastra/code-sdk/onboarding/settings";
|
|
15
5
|
import { registerApiRoute } from "@mastra/core/server";
|
|
16
6
|
|
|
17
7
|
// src/routes/provider-credentials.ts
|
|
@@ -126,15 +116,39 @@ async function listProviders({
|
|
|
126
116
|
}
|
|
127
117
|
return Array.from(seen.values()).sort((a, b) => a.provider.localeCompare(b.provider));
|
|
128
118
|
}
|
|
129
|
-
function
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
119
|
+
function toCustomProviderInfo(record) {
|
|
120
|
+
return {
|
|
121
|
+
id: record.providerId,
|
|
122
|
+
name: record.name,
|
|
123
|
+
url: record.url,
|
|
124
|
+
hasApiKey: Boolean(record.apiKey),
|
|
125
|
+
models: record.models
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
async function resolveCustomProvidersContext({
|
|
129
|
+
c,
|
|
130
|
+
auth,
|
|
131
|
+
customProviders
|
|
132
|
+
}) {
|
|
133
|
+
await auth.ensureUser(c);
|
|
134
|
+
const tenant = auth.tenant(c);
|
|
135
|
+
if (!tenant && auth.enabled()) return { response: c.json({ error: "unauthorized" }, 401) };
|
|
136
|
+
if (customProviders) {
|
|
137
|
+
try {
|
|
138
|
+
await customProviders.ensureReady();
|
|
139
|
+
return tenant ? { storage: customProviders, orgId: tenantOrgId(tenant), userId: tenant.userId } : { storage: customProviders, orgId: "local", userId: "local" };
|
|
140
|
+
} catch {
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
return {
|
|
144
|
+
response: c.json(
|
|
145
|
+
{
|
|
146
|
+
error: "custom_providers_unavailable",
|
|
147
|
+
message: "Custom provider storage is unavailable \u2014 the app database is not configured or failed to start."
|
|
148
|
+
},
|
|
149
|
+
503
|
|
150
|
+
)
|
|
151
|
+
};
|
|
138
152
|
}
|
|
139
153
|
function parseCustomProviderBody(body) {
|
|
140
154
|
if (!body || typeof body !== "object") return { error: "Invalid JSON body" };
|
|
@@ -199,15 +213,6 @@ async function buildProviderAccess({
|
|
|
199
213
|
function canUseModelProvider(access, provider) {
|
|
200
214
|
return Boolean(access[provider]);
|
|
201
215
|
}
|
|
202
|
-
async function getTenantModelPacksStorage(modelPacks) {
|
|
203
|
-
if (!modelPacks) return void 0;
|
|
204
|
-
try {
|
|
205
|
-
await modelPacks.ensureReady();
|
|
206
|
-
} catch {
|
|
207
|
-
return void 0;
|
|
208
|
-
}
|
|
209
|
-
return modelPacks;
|
|
210
|
-
}
|
|
211
216
|
async function resolvePackContext({
|
|
212
217
|
c,
|
|
213
218
|
auth,
|
|
@@ -215,23 +220,23 @@ async function resolvePackContext({
|
|
|
215
220
|
}) {
|
|
216
221
|
await auth.ensureUser(c);
|
|
217
222
|
const tenant = auth.tenant(c);
|
|
218
|
-
if (!tenant) {
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
response: c.json(
|
|
226
|
-
{
|
|
227
|
-
error: "model_packs_unavailable",
|
|
228
|
-
message: "Model pack storage is unavailable \u2014 the app database is not configured or failed to start."
|
|
229
|
-
},
|
|
230
|
-
503
|
|
231
|
-
)
|
|
232
|
-
};
|
|
223
|
+
if (!tenant && auth.enabled()) return { response: c.json({ error: "unauthorized" }, 401) };
|
|
224
|
+
if (modelPacks) {
|
|
225
|
+
try {
|
|
226
|
+
await modelPacks.ensureReady();
|
|
227
|
+
return tenant ? { storage: modelPacks, orgId: tenantOrgId(tenant), userId: tenant.userId } : { storage: modelPacks, orgId: "local", userId: "local" };
|
|
228
|
+
} catch {
|
|
229
|
+
}
|
|
233
230
|
}
|
|
234
|
-
return {
|
|
231
|
+
return {
|
|
232
|
+
response: c.json(
|
|
233
|
+
{
|
|
234
|
+
error: "model_packs_unavailable",
|
|
235
|
+
message: "Model pack storage is unavailable \u2014 the app database is not configured or failed to start."
|
|
236
|
+
},
|
|
237
|
+
503
|
|
238
|
+
)
|
|
239
|
+
};
|
|
235
240
|
}
|
|
236
241
|
function recordToModePack(record) {
|
|
237
242
|
return { id: `custom:${record.id}`, name: record.name, description: "Saved custom pack", models: record.models };
|
|
@@ -244,7 +249,7 @@ async function listModelPacks({
|
|
|
244
249
|
activePackId
|
|
245
250
|
}) {
|
|
246
251
|
const access = await buildProviderAccess({ controller, authStorage, tenantCredentials });
|
|
247
|
-
const packs =
|
|
252
|
+
const packs = [
|
|
248
253
|
...getAvailableModePacks(access),
|
|
249
254
|
...(await packContext.storage.list({ orgId: packContext.orgId })).map(recordToModePack)
|
|
250
255
|
];
|
|
@@ -302,20 +307,57 @@ function readOMConfig(session) {
|
|
|
302
307
|
observeAttachments: observeAttachments === true || observeAttachments === false ? observeAttachments : "auto"
|
|
303
308
|
};
|
|
304
309
|
}
|
|
305
|
-
function
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
saveSettings(settings);
|
|
310
|
-
}
|
|
311
|
-
function persistOmRoleOverride({
|
|
312
|
-
role,
|
|
313
|
-
modelId,
|
|
314
|
-
otherRoleCurrentModelId
|
|
310
|
+
async function resolveMemorySettingsContext({
|
|
311
|
+
c,
|
|
312
|
+
auth,
|
|
313
|
+
memorySettings
|
|
315
314
|
}) {
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
315
|
+
await auth.ensureUser(c);
|
|
316
|
+
const tenant = auth.tenant(c);
|
|
317
|
+
if (!tenant && auth.enabled()) return { response: c.json({ error: "unauthorized" }, 401) };
|
|
318
|
+
if (memorySettings) {
|
|
319
|
+
try {
|
|
320
|
+
await memorySettings.ensureReady();
|
|
321
|
+
return tenant ? { storage: memorySettings, orgId: tenantOrgId(tenant), userId: tenant.userId } : { storage: memorySettings, orgId: "local", userId: "local" };
|
|
322
|
+
} catch {
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
return {
|
|
326
|
+
response: c.json(
|
|
327
|
+
{
|
|
328
|
+
error: "memory_settings_unavailable",
|
|
329
|
+
message: "Memory settings storage is unavailable \u2014 the app database is not configured or failed to start."
|
|
330
|
+
},
|
|
331
|
+
503
|
|
332
|
+
)
|
|
333
|
+
};
|
|
334
|
+
}
|
|
335
|
+
async function persistMemorySettings(context, patch, fillIfUnset) {
|
|
336
|
+
await context.storage.patch({ orgId: context.orgId, userId: context.userId, patch, fillIfUnset });
|
|
337
|
+
}
|
|
338
|
+
async function hydrateSessionMemorySettings(session, record) {
|
|
339
|
+
for (const role of ["observer", "reflector"]) {
|
|
340
|
+
const stored = role === "observer" ? record?.observerModelId : record?.reflectorModelId;
|
|
341
|
+
const target = stored ?? DEFAULT_OM_MODEL_ID;
|
|
342
|
+
if (session.om[role].modelId() !== target) {
|
|
343
|
+
await session.om[role].switchModel({ modelId: target });
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
const state = session.state.get() ?? {};
|
|
347
|
+
const updates = {};
|
|
348
|
+
const observationThreshold = record?.observationThreshold ?? DEFAULT_OBSERVATION_THRESHOLD;
|
|
349
|
+
if (state.observationThreshold !== observationThreshold) {
|
|
350
|
+
updates.observationThreshold = observationThreshold;
|
|
351
|
+
}
|
|
352
|
+
const reflectionThreshold = record?.reflectionThreshold ?? DEFAULT_REFLECTION_THRESHOLD;
|
|
353
|
+
if (state.reflectionThreshold !== reflectionThreshold) {
|
|
354
|
+
updates.reflectionThreshold = reflectionThreshold;
|
|
355
|
+
}
|
|
356
|
+
const observeAttachments = record?.observeAttachments ?? "auto";
|
|
357
|
+
if ((state.observeAttachments ?? "auto") !== observeAttachments) {
|
|
358
|
+
updates.observeAttachments = observeAttachments;
|
|
359
|
+
}
|
|
360
|
+
if (Object.keys(updates).length > 0) await session.state.set(updates);
|
|
319
361
|
}
|
|
320
362
|
var ConfigRoutes = class extends Route {
|
|
321
363
|
routes() {
|
|
@@ -323,6 +365,8 @@ var ConfigRoutes = class extends Route {
|
|
|
323
365
|
const { controller, authStorage, auth } = options;
|
|
324
366
|
const onCredentialsChanged = options.onCredentialsChanged ?? (() => {
|
|
325
367
|
});
|
|
368
|
+
const onCustomProvidersChanged = options.onCustomProvidersChanged ?? (() => {
|
|
369
|
+
});
|
|
326
370
|
return [
|
|
327
371
|
registerApiRoute("/web/config/providers", {
|
|
328
372
|
method: "GET",
|
|
@@ -414,14 +458,22 @@ var ConfigRoutes = class extends Route {
|
|
|
414
458
|
}
|
|
415
459
|
}),
|
|
416
460
|
// ── Custom providers (OpenAI-compatible endpoints) ──────────────────────
|
|
417
|
-
// Mirrors the TUI's /custom-providers command
|
|
418
|
-
// (
|
|
461
|
+
// Mirrors the TUI's /custom-providers command, but backed by the
|
|
462
|
+
// `custom-providers` domain (org rows in tenant mode, a sentinel `local`
|
|
463
|
+
// org in no-auth mode) — the server never reads settings.json for these.
|
|
419
464
|
registerApiRoute("/web/config/custom-providers", {
|
|
420
465
|
method: "GET",
|
|
421
466
|
requiresAuth: false,
|
|
422
|
-
handler: (c) => {
|
|
467
|
+
handler: async (c) => {
|
|
468
|
+
const ctx = await resolveCustomProvidersContext({
|
|
469
|
+
c: loose(c),
|
|
470
|
+
auth,
|
|
471
|
+
customProviders: options.customProviders
|
|
472
|
+
});
|
|
473
|
+
if ("response" in ctx) return ctx.response;
|
|
423
474
|
try {
|
|
424
|
-
|
|
475
|
+
const records = await ctx.storage.list({ orgId: ctx.orgId });
|
|
476
|
+
return c.json({ providers: records.map(toCustomProviderInfo) });
|
|
425
477
|
} catch (error) {
|
|
426
478
|
return c.json({ error: error instanceof Error ? error.message : String(error) }, 500);
|
|
427
479
|
}
|
|
@@ -431,6 +483,12 @@ var ConfigRoutes = class extends Route {
|
|
|
431
483
|
method: "POST",
|
|
432
484
|
requiresAuth: false,
|
|
433
485
|
handler: async (c) => {
|
|
486
|
+
const ctx = await resolveCustomProvidersContext({
|
|
487
|
+
c: loose(c),
|
|
488
|
+
auth,
|
|
489
|
+
customProviders: options.customProviders
|
|
490
|
+
});
|
|
491
|
+
if ("response" in ctx) return ctx.response;
|
|
434
492
|
let body;
|
|
435
493
|
try {
|
|
436
494
|
body = await c.req.json();
|
|
@@ -441,11 +499,20 @@ var ConfigRoutes = class extends Route {
|
|
|
441
499
|
if ("error" in parsed) return c.json({ error: parsed.error }, 400);
|
|
442
500
|
const previousId = body && typeof body === "object" && typeof body.previousId === "string" ? body.previousId : void 0;
|
|
443
501
|
try {
|
|
444
|
-
const
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
502
|
+
const record = await ctx.storage.upsert({
|
|
503
|
+
orgId: ctx.orgId,
|
|
504
|
+
userId: ctx.userId,
|
|
505
|
+
input: {
|
|
506
|
+
providerId: getCustomProviderId(parsed.name),
|
|
507
|
+
name: parsed.name,
|
|
508
|
+
url: parsed.url,
|
|
509
|
+
apiKey: parsed.apiKey,
|
|
510
|
+
models: parsed.models
|
|
511
|
+
},
|
|
512
|
+
previousProviderId: previousId
|
|
513
|
+
});
|
|
514
|
+
onCustomProvidersChanged({ orgId: ctx.orgId });
|
|
515
|
+
return c.json({ ok: true, provider: toCustomProviderInfo(record) });
|
|
449
516
|
} catch (error) {
|
|
450
517
|
return c.json({ error: error instanceof Error ? error.message : String(error) }, 500);
|
|
451
518
|
}
|
|
@@ -454,12 +521,17 @@ var ConfigRoutes = class extends Route {
|
|
|
454
521
|
registerApiRoute("/web/config/custom-providers/:id", {
|
|
455
522
|
method: "DELETE",
|
|
456
523
|
requiresAuth: false,
|
|
457
|
-
handler: (c) => {
|
|
524
|
+
handler: async (c) => {
|
|
525
|
+
const ctx = await resolveCustomProvidersContext({
|
|
526
|
+
c: loose(c),
|
|
527
|
+
auth,
|
|
528
|
+
customProviders: options.customProviders
|
|
529
|
+
});
|
|
530
|
+
if ("response" in ctx) return ctx.response;
|
|
458
531
|
const id = c.req.param("id");
|
|
459
532
|
try {
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
saveSettings(settings);
|
|
533
|
+
await ctx.storage.delete({ orgId: ctx.orgId, providerId: id });
|
|
534
|
+
onCustomProvidersChanged({ orgId: ctx.orgId });
|
|
463
535
|
return c.json({ ok: true });
|
|
464
536
|
} catch (error) {
|
|
465
537
|
return c.json({ error: error instanceof Error ? error.message : String(error) }, 500);
|
|
@@ -488,8 +560,30 @@ var ConfigRoutes = class extends Route {
|
|
|
488
560
|
tenantCredentials
|
|
489
561
|
})
|
|
490
562
|
]);
|
|
563
|
+
const catalog = models.filter((m) => canUseModelProvider(access, m.provider) && typeof m.id === "string").map((m) => ({ id: m.id, provider: m.provider, modelName: m.modelName, hasApiKey: true }));
|
|
564
|
+
if (options.customProviders) {
|
|
565
|
+
try {
|
|
566
|
+
const ctx = await resolveCustomProvidersContext({
|
|
567
|
+
c: loose(c),
|
|
568
|
+
auth,
|
|
569
|
+
customProviders: options.customProviders
|
|
570
|
+
});
|
|
571
|
+
if (!("response" in ctx)) {
|
|
572
|
+
const known = new Set(catalog.map((m) => m.id));
|
|
573
|
+
for (const record of await ctx.storage.list({ orgId: ctx.orgId })) {
|
|
574
|
+
for (const model of record.models) {
|
|
575
|
+
const id = `${record.providerId}/${model}`;
|
|
576
|
+
if (known.has(id)) continue;
|
|
577
|
+
known.add(id);
|
|
578
|
+
catalog.push({ id, provider: record.providerId, modelName: model, hasApiKey: true });
|
|
579
|
+
}
|
|
580
|
+
}
|
|
581
|
+
}
|
|
582
|
+
} catch {
|
|
583
|
+
}
|
|
584
|
+
}
|
|
491
585
|
return c.json({
|
|
492
|
-
models:
|
|
586
|
+
models: catalog.sort(
|
|
493
587
|
(a, b) => a.provider === b.provider ? a.id.localeCompare(b.id) : a.provider.localeCompare(b.provider)
|
|
494
588
|
)
|
|
495
589
|
});
|
|
@@ -499,10 +593,10 @@ var ConfigRoutes = class extends Route {
|
|
|
499
593
|
}
|
|
500
594
|
}),
|
|
501
595
|
// ── Model packs ─────────────────────────────────────────────────────────
|
|
502
|
-
// Mirrors the TUI's /models-pack command. Custom-pack CRUD
|
|
503
|
-
//
|
|
504
|
-
//
|
|
505
|
-
// the controller registry by resourceId.
|
|
596
|
+
// Mirrors the TUI's /models-pack command. Custom-pack CRUD lives in the
|
|
597
|
+
// model-packs storage domain (org-scoped, sentinel `local` org in no-auth
|
|
598
|
+
// mode — never settings.json); activation is session-scoped and resolves
|
|
599
|
+
// the session from the controller registry by resourceId.
|
|
506
600
|
registerApiRoute("/web/config/model-packs", {
|
|
507
601
|
method: "GET",
|
|
508
602
|
requiresAuth: false,
|
|
@@ -556,21 +650,12 @@ var ConfigRoutes = class extends Route {
|
|
|
556
650
|
return c.json({ error: "models.build, models.plan and models.fast are required" }, 400);
|
|
557
651
|
}
|
|
558
652
|
try {
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
return c.json({ ok: true, pack: recordToModePack(record) });
|
|
566
|
-
}
|
|
567
|
-
const settings = loadSettings();
|
|
568
|
-
const entry = { name, models: { build, plan, fast }, createdAt: (/* @__PURE__ */ new Date()).toISOString() };
|
|
569
|
-
const idx = settings.customModelPacks.findIndex((p) => p.name === name);
|
|
570
|
-
if (idx >= 0) settings.customModelPacks[idx] = entry;
|
|
571
|
-
else settings.customModelPacks.push(entry);
|
|
572
|
-
saveSettings(settings);
|
|
573
|
-
return c.json({ ok: true, pack: { id: `custom:${name}`, name, models: { build, plan, fast } } });
|
|
653
|
+
const record = await packContext.storage.upsert({
|
|
654
|
+
orgId: packContext.orgId,
|
|
655
|
+
userId: packContext.userId,
|
|
656
|
+
input: { name, models: { build, plan, fast } }
|
|
657
|
+
});
|
|
658
|
+
return c.json({ ok: true, pack: recordToModePack(record) });
|
|
574
659
|
} catch (error) {
|
|
575
660
|
return c.json({ error: error instanceof Error ? error.message : String(error) }, 500);
|
|
576
661
|
}
|
|
@@ -584,15 +669,9 @@ var ConfigRoutes = class extends Route {
|
|
|
584
669
|
if ("response" in packContext) return packContext.response;
|
|
585
670
|
const id = decodeURIComponent(c.req.param("id"));
|
|
586
671
|
try {
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
return deleted ? c.json({ ok: true }) : c.json({ error: `Unknown pack "${id}"` }, 404);
|
|
591
|
-
}
|
|
592
|
-
const settings = loadSettings();
|
|
593
|
-
removeCustomPackFromSettings(settings, id);
|
|
594
|
-
saveSettings(settings);
|
|
595
|
-
return c.json({ ok: true });
|
|
672
|
+
const recordId = id.startsWith("custom:") ? id.slice("custom:".length) : id;
|
|
673
|
+
const deleted = await packContext.storage.delete({ orgId: packContext.orgId, id: recordId });
|
|
674
|
+
return deleted ? c.json({ ok: true }) : c.json({ error: `Unknown pack "${id}"` }, 404);
|
|
596
675
|
} catch (error) {
|
|
597
676
|
return c.json({ error: error instanceof Error ? error.message : String(error) }, 500);
|
|
598
677
|
}
|
|
@@ -639,8 +718,10 @@ var ConfigRoutes = class extends Route {
|
|
|
639
718
|
}),
|
|
640
719
|
// ── Observational memory ──────────────────────────────────────────────────
|
|
641
720
|
// Mirrors the TUI's /om command. All five knobs are session-scoped (resolved
|
|
642
|
-
// from the session, persisted to its state + thread setting)
|
|
643
|
-
//
|
|
721
|
+
// from the session, persisted to its state + thread setting) and durably
|
|
722
|
+
// stored in the per-(org, user) `memory-settings` app table — never
|
|
723
|
+
// settings.json. GET hydrates the session from the stored row first so the
|
|
724
|
+
// DB, not the SDK's boot-time seed, is the source of truth.
|
|
644
725
|
registerApiRoute("/web/config/om", {
|
|
645
726
|
method: "GET",
|
|
646
727
|
requiresAuth: false,
|
|
@@ -648,9 +729,17 @@ var ConfigRoutes = class extends Route {
|
|
|
648
729
|
const resourceId = c.req.query("resourceId");
|
|
649
730
|
const scope = c.req.query("scope") || void 0;
|
|
650
731
|
if (!resourceId) return c.json({ error: "Missing required query param: resourceId" }, 400);
|
|
732
|
+
const context = await resolveMemorySettingsContext({
|
|
733
|
+
c: loose(c),
|
|
734
|
+
auth,
|
|
735
|
+
memorySettings: options.memorySettings
|
|
736
|
+
});
|
|
737
|
+
if ("response" in context) return context.response;
|
|
651
738
|
try {
|
|
652
739
|
const session = await controller.getSessionByResource?.(resourceId, scope);
|
|
653
740
|
if (!session) return c.json({ error: `No session for resourceId "${resourceId}"` }, 404);
|
|
741
|
+
const record = await context.storage.get({ orgId: context.orgId, userId: context.userId });
|
|
742
|
+
await hydrateSessionMemorySettings(session, record);
|
|
654
743
|
return c.json({ config: readOMConfig(session) });
|
|
655
744
|
} catch (error) {
|
|
656
745
|
return c.json({ error: error instanceof Error ? error.message : String(error) }, 500);
|
|
@@ -676,13 +765,24 @@ var ConfigRoutes = class extends Route {
|
|
|
676
765
|
const modelId = typeof body.modelId === "string" ? body.modelId.trim() : "";
|
|
677
766
|
if (!resourceId) return c.json({ error: "Missing required field: resourceId" }, 400);
|
|
678
767
|
if (!modelId) return c.json({ error: "Missing required field: modelId" }, 400);
|
|
768
|
+
const context = await resolveMemorySettingsContext({
|
|
769
|
+
c: loose(c),
|
|
770
|
+
auth,
|
|
771
|
+
memorySettings: options.memorySettings
|
|
772
|
+
});
|
|
773
|
+
if ("response" in context) return context.response;
|
|
679
774
|
try {
|
|
680
775
|
const session = await controller.getSessionByResource?.(resourceId, scope);
|
|
681
776
|
if (!session) return c.json({ error: `No session for resourceId "${resourceId}"` }, 404);
|
|
682
777
|
const otherRole = role === "observer" ? session.om.reflector : session.om.observer;
|
|
683
778
|
const otherRoleCurrentModelId = otherRole.modelId() ?? null;
|
|
684
779
|
await session.om[role].switchModel({ modelId });
|
|
685
|
-
|
|
780
|
+
const otherKey = role === "observer" ? "reflectorModelId" : "observerModelId";
|
|
781
|
+
await persistMemorySettings(
|
|
782
|
+
context,
|
|
783
|
+
{ [role === "observer" ? "observerModelId" : "reflectorModelId"]: modelId },
|
|
784
|
+
otherRoleCurrentModelId ? { [otherKey]: otherRoleCurrentModelId } : void 0
|
|
785
|
+
);
|
|
686
786
|
return c.json({ ok: true, config: readOMConfig(session) });
|
|
687
787
|
} catch (error) {
|
|
688
788
|
return c.json({ error: error instanceof Error ? error.message : String(error) }, 500);
|
|
@@ -707,19 +807,27 @@ var ConfigRoutes = class extends Route {
|
|
|
707
807
|
if (observation === void 0 && reflection === void 0) {
|
|
708
808
|
return c.json({ error: "Provide observationThreshold and/or reflectionThreshold (positive numbers)" }, 400);
|
|
709
809
|
}
|
|
810
|
+
const context = await resolveMemorySettingsContext({
|
|
811
|
+
c: loose(c),
|
|
812
|
+
auth,
|
|
813
|
+
memorySettings: options.memorySettings
|
|
814
|
+
});
|
|
815
|
+
if ("response" in context) return context.response;
|
|
710
816
|
try {
|
|
711
817
|
const session = await controller.getSessionByResource?.(resourceId, scope);
|
|
712
818
|
if (!session) return c.json({ error: `No session for resourceId "${resourceId}"` }, 404);
|
|
713
819
|
if (observation !== void 0) {
|
|
714
820
|
await session.state.set({ observationThreshold: observation });
|
|
715
821
|
await session.thread.setSetting({ key: "observationThreshold", value: observation });
|
|
716
|
-
persistOmThreshold({ role: "observation", value: observation });
|
|
717
822
|
}
|
|
718
823
|
if (reflection !== void 0) {
|
|
719
824
|
await session.state.set({ reflectionThreshold: reflection });
|
|
720
825
|
await session.thread.setSetting({ key: "reflectionThreshold", value: reflection });
|
|
721
|
-
persistOmThreshold({ role: "reflection", value: reflection });
|
|
722
826
|
}
|
|
827
|
+
await persistMemorySettings(context, {
|
|
828
|
+
...observation !== void 0 ? { observationThreshold: observation } : {},
|
|
829
|
+
...reflection !== void 0 ? { reflectionThreshold: reflection } : {}
|
|
830
|
+
});
|
|
723
831
|
return c.json({ ok: true, config: readOMConfig(session) });
|
|
724
832
|
} catch (error) {
|
|
725
833
|
return c.json({ error: error instanceof Error ? error.message : String(error) }, 500);
|
|
@@ -744,12 +852,18 @@ var ConfigRoutes = class extends Route {
|
|
|
744
852
|
if (raw !== "auto" && raw !== true && raw !== false) {
|
|
745
853
|
return c.json({ error: "value must be 'auto', true, or false" }, 400);
|
|
746
854
|
}
|
|
855
|
+
const context = await resolveMemorySettingsContext({
|
|
856
|
+
c: loose(c),
|
|
857
|
+
auth,
|
|
858
|
+
memorySettings: options.memorySettings
|
|
859
|
+
});
|
|
860
|
+
if ("response" in context) return context.response;
|
|
747
861
|
try {
|
|
748
862
|
const session = await controller.getSessionByResource?.(resourceId, scope);
|
|
749
863
|
if (!session) return c.json({ error: `No session for resourceId "${resourceId}"` }, 404);
|
|
750
864
|
await session.state.set({ observeAttachments: value });
|
|
751
865
|
await session.thread.setSetting({ key: "observeAttachments", value });
|
|
752
|
-
|
|
866
|
+
await persistMemorySettings(context, { observeAttachments: value });
|
|
753
867
|
return c.json({ ok: true, config: readOMConfig(session) });
|
|
754
868
|
} catch (error) {
|
|
755
869
|
return c.json({ error: error instanceof Error ? error.message : String(error) }, 500);
|
|
@@ -762,7 +876,6 @@ var ConfigRoutes = class extends Route {
|
|
|
762
876
|
export {
|
|
763
877
|
ConfigRoutes,
|
|
764
878
|
buildProviderAccess,
|
|
765
|
-
listCustomProviders,
|
|
766
879
|
listModelPacks,
|
|
767
880
|
listProviders,
|
|
768
881
|
readOMConfig
|