|
2 | 2 |
|
3 | 3 | const { hydrateUsageIdentity } = require("./usage"); |
4 | 4 | const { hashPassword, verifyPassword, generateId, generateApiKey } = require("./password"); |
5 | | -const { detectAll, summarizeDetected } = require("./detect"); |
6 | 5 | const { startOAuth, completeOAuth, oauthStatus, clearPending } = require("./oauth"); |
7 | 6 | const { |
8 | 7 | canInvoke, |
@@ -54,7 +53,6 @@ function createControlPlane({ |
54 | 53 | throw new TypeError("Control plane requires the ReRouted runtime services"); |
55 | 54 | } |
56 | 55 |
|
57 | | - let detectedCache = []; |
58 | 56 | const handlers = new Map(); |
59 | 57 | const handle = (channel, handler) => { |
60 | 58 | if (handlers.has(channel)) throw new Error(`Duplicate control-plane handler: ${channel}`); |
@@ -173,9 +171,11 @@ function createControlPlane({ |
173 | 171 | }); |
174 | 172 |
|
175 | 173 | handle("app:set-onboarding-step", async (_e, step) => { |
| 174 | + if (!ONBOARDING_STEPS.includes(step) || step === "done") { |
| 175 | + return { ok: false, error: "Unknown onboarding step" }; |
| 176 | + } |
176 | 177 | store.update((cfg) => { |
177 | 178 | cfg.onboardingStep = step; |
178 | | - if (step === "done") cfg.onboardingComplete = true; |
179 | 179 | }); |
180 | 180 | return { ok: true }; |
181 | 181 | }); |
@@ -235,45 +235,6 @@ handle("app:change-admin-password", async (_e, { current, next }) => { |
235 | 235 | return { ok: true }; |
236 | 236 | }); |
237 | 237 |
|
238 | | -handle("app:detect-providers", async () => { |
239 | | - detectedCache = await detectAll(); |
240 | | - return { ok: true, found: summarizeDetected(detectedCache) }; |
241 | | -}); |
242 | | - |
243 | | -handle("app:import-detected", async (_e, ids) => { |
244 | | - const want = new Set(ids || []); |
245 | | - const toImport = detectedCache.filter((d) => want.has(d.id)); |
246 | | - store.update((cfg) => { |
247 | | - for (const d of toImport) { |
248 | | - // Avoid duplicate by type+email/source path |
249 | | - const exists = cfg.providers.some( |
250 | | - (p) => |
251 | | - p.type === d.type && |
252 | | - ((d.email && p.email === d.email) || (d.path && p.importPath === d.path)) |
253 | | - ); |
254 | | - if (exists) continue; |
255 | | - cfg.providers.push({ |
256 | | - id: d.id || generateId("prov"), |
257 | | - type: d.type, |
258 | | - name: d.name, |
259 | | - email: d.email, |
260 | | - accessToken: d.accessToken, |
261 | | - refreshToken: d.refreshToken, |
262 | | - accountId: d.accountId, |
263 | | - projectId: d.projectId, |
264 | | - clientId: d.clientId, |
265 | | - clientSecret: d.clientSecret, |
266 | | - models: d.models, |
267 | | - enabled: true, |
268 | | - importPath: d.path, |
269 | | - source: d.source, |
270 | | - createdAt: Date.now(), |
271 | | - }); |
272 | | - } |
273 | | - }); |
274 | | - return { ok: true }; |
275 | | -}); |
276 | | - |
277 | 238 | handle("app:oauth-start", async (_e, type) => { |
278 | 239 | try { |
279 | 240 | logger.oauth(`UI requested OAuth start for ${type}`); |
@@ -583,6 +544,21 @@ handle("app:set-model-enabled", async (_e, { providerId, modelId, enabled }) => |
583 | 544 | return { ok: true }; |
584 | 545 | }); |
585 | 546 |
|
| 547 | +handle("app:set-all-models-enabled", async (_e, { providerId, enabled }) => { |
| 548 | + let updated = 0; |
| 549 | + store.update((cfg) => { |
| 550 | + const provider = cfg.providers.find((item) => item.id === providerId); |
| 551 | + if (!provider || !Array.isArray(provider.models)) return; |
| 552 | + provider.models = provider.models.map((model) => { |
| 553 | + updated += 1; |
| 554 | + return typeof model === "string" |
| 555 | + ? { id: model, name: model, enabled: !!enabled } |
| 556 | + : { ...model, enabled: !!enabled }; |
| 557 | + }); |
| 558 | + }); |
| 559 | + return { ok: updated > 0, updated, enabled: !!enabled }; |
| 560 | +}); |
| 561 | + |
586 | 562 | handle("app:add-model", async (_e, { providerId, modelId }) => { |
587 | 563 | const mid = String(modelId || "").trim(); |
588 | 564 | if (!mid) return { ok: false, error: "Model name required" }; |
|
0 commit comments