mioku-service-webui 4.6.0 → 4.7.0

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.
Files changed (2) hide show
  1. package/package.json +4 -2
  2. package/routes/ai.ts +32 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mioku-service-webui",
3
- "version": "4.6.0",
3
+ "version": "4.7.0",
4
4
  "description": "Mioku WebUI 服务",
5
5
  "main": "index.ts",
6
6
  "type": "module",
@@ -25,10 +25,12 @@
25
25
  "hono": "4.12.14"
26
26
  },
27
27
  "peerDependencies": {
28
- "mioku-service-ai": "^0.2.0"
28
+ "mioku-service-ai": "^0.2.0",
29
+ "mioki": "^0.16.0"
29
30
  },
30
31
  "devDependencies": {
31
32
  "@types/bun": "^1.3.14",
33
+ "mioki": "^0.16.0",
32
34
  "mioku": "workspace:*",
33
35
  "mioku-service-ai": "workspace:*"
34
36
  }
package/routes/ai.ts CHANGED
@@ -354,6 +354,38 @@ export function createAIRoutes() {
354
354
  return c.json({ ok: true, data: api.getRoleBindings() });
355
355
  });
356
356
 
357
+ app.get("/fallback", (c) => {
358
+ const api = getAIApi();
359
+ const chain = api?.getMainFallbackChain?.() ?? [];
360
+ return c.json({
361
+ ok: true,
362
+ data: {
363
+ fallback: chain,
364
+ liveFallback: chain,
365
+ },
366
+ });
367
+ });
368
+
369
+ app.put("/fallback", async (c) => {
370
+ const api = getAIApi();
371
+ if (!api?.setMainFallbackChain) {
372
+ return c.json({ ok: false, error: "AI_SERVICE_UNAVAILABLE" }, 503);
373
+ }
374
+ const body = await c.req.json();
375
+ const raw = Array.isArray(body?.fallback) ? body.fallback : [];
376
+ const fallback = Array.from(
377
+ new Set(
378
+ raw
379
+ .map((id: unknown) => String(id || "").trim())
380
+ .filter((id: string) => id.includes("/") && id.length > 1),
381
+ ),
382
+ );
383
+ logger.info(`[webui-action] ai.fallback.update`, { count: fallback.length });
384
+ api.setMainFallbackChain(fallback);
385
+ const live = api.getMainFallbackChain?.() ?? fallback;
386
+ return c.json({ ok: true, data: { fallback: live, liveFallback: live } });
387
+ });
388
+
357
389
  app.put("/roles", async (c) => {
358
390
  const api = getAIApi();
359
391
  if (!api?.setRoleBinding) {