@engenty/wizards-runtime 0.11.8 → 0.11.9

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 (35) hide show
  1. package/apps/runtime/dist/app.js +22 -0
  2. package/apps/runtime/dist/db/client.js +32 -0
  3. package/apps/runtime/dist/db/control-schema.js +2 -0
  4. package/apps/runtime/dist/db/migrations/control/0012_runner_line.sql +1 -0
  5. package/apps/runtime/dist/db/migrations/control/meta/0012_snapshot.json +607 -0
  6. package/apps/runtime/dist/db/migrations/control/meta/_journal.json +7 -0
  7. package/apps/runtime/dist/engine/runner.js +37 -3
  8. package/apps/runtime/dist/env.js +10 -0
  9. package/apps/runtime/dist/files/objects.js +15 -2
  10. package/apps/runtime/dist/health.js +287 -0
  11. package/apps/runtime/dist/index.js +19 -0
  12. package/apps/runtime/dist/routes/internal.js +2 -0
  13. package/apps/runtime/dist/tenants/control.js +20 -0
  14. package/apps/web/dist/assets/{AboutDialog-BWc0zi6S.js → AboutDialog-CVr7-F9d.js} +1 -1
  15. package/apps/web/dist/assets/{ChangelogDialog-Ctkpgtt8.js → ChangelogDialog-BBrbTJvy.js} +1 -1
  16. package/apps/web/dist/assets/{EditorPage-C2lCK9wY.js → EditorPage-Dp9t6JBC.js} +1 -1
  17. package/apps/web/dist/assets/{Harness-CeEYZGHB.js → Harness-BnU7FnhV.js} +1 -1
  18. package/apps/web/dist/assets/{NewWizardChannels-Rq4Oc1OM.js → NewWizardChannels-GqURod9Z.js} +1 -1
  19. package/apps/web/dist/assets/{NewWizardPage-CCR_U2vH.js → NewWizardPage-f7aCNCQz.js} +1 -1
  20. package/apps/web/dist/assets/{OnboardingPage-CcaxqyzN.js → OnboardingPage-B0z2X_4h.js} +1 -1
  21. package/apps/web/dist/assets/{PreviewPane-By692ez7.js → PreviewPane-BC4zFl4u.js} +1 -1
  22. package/apps/web/dist/assets/{ProjectPage-ClMgq06-.js → ProjectPage-B33OxA3U.js} +1 -1
  23. package/apps/web/dist/assets/{PublicRunner-BtUu5LCy.js → PublicRunner-BvIMLJXn.js} +1 -1
  24. package/apps/web/dist/assets/{ReadOnly-B2BSJ7ms.js → ReadOnly-D8H4QIVD.js} +1 -1
  25. package/apps/web/dist/assets/{SettingsPage-DGHco15-.js → SettingsPage-cS2n5ThJ.js} +2 -2
  26. package/apps/web/dist/assets/{SetupPage-CNJY56MI.js → SetupPage-RemLlEon.js} +1 -1
  27. package/apps/web/dist/assets/{SharePage-ZolaYse9.js → SharePage-D4upbrdD.js} +1 -1
  28. package/apps/web/dist/assets/changelog-DicAdDi2.js +1 -0
  29. package/apps/web/dist/assets/{index-5U3h_chZ.js → index-EkjeX2z-.js} +3 -3
  30. package/apps/web/dist/assets/{theme-CnRjADMg.js → theme-s9XywvSy.js} +1 -1
  31. package/apps/web/dist/index.html +1 -1
  32. package/package.json +1 -1
  33. package/plugin/.claude-plugin/plugin.json +1 -1
  34. package/plugin/plugin.json +1 -1
  35. package/apps/web/dist/assets/changelog-CWPHX0Hf.js +0 -1
@@ -13,6 +13,7 @@ import { authRoutes, principalOf } from "./auth/index.js";
13
13
  import { db, schema, withTenant } from "./db/client.js";
14
14
  import { basePath, env } from "./env.js";
15
15
  import { features } from "./features.js";
16
+ import { health, httpStatus, publicHealth, requestStarted } from "./health.js";
16
17
  import { allowed, hashIp } from "./limits.js";
17
18
  import { linkPreview } from "./link-preview.js";
18
19
  import { nudge, signal } from "./live/hub.js";
@@ -46,6 +47,17 @@ const app = new Hono();
46
47
  // Which halves this process serves (RUNTIME_ROLE): the studio's routes, the doors' routes, or
47
48
  // both. What both need — health, config, the runs' API, the connect callback — is always there.
48
49
  const { serves } = env;
50
+ // Every request is open until its handler returned: one that never returns shows in the health
51
+ // checks and in the log (health.ts).
52
+ app.use("*", async (c, next) => {
53
+ const done = requestStarted(c.req.method, c.req.path);
54
+ try {
55
+ await next();
56
+ }
57
+ finally {
58
+ done();
59
+ }
60
+ });
49
61
  app.onError((err, c) => {
50
62
  if (err instanceof ServiceError) {
51
63
  const body = err.toJSON(requestLang(c));
@@ -115,6 +127,11 @@ app.use("*", async (c, next) => {
115
127
  return next();
116
128
  });
117
129
  app.get("/api/health", (c) => c.json({ ok: true }));
130
+ /** Whether this process and what it depends on work: 503 when it can't serve (health.ts). */
131
+ app.get("/api/health/ready", async (c) => {
132
+ const h = await health();
133
+ return c.json(publicHealth(h), httpStatus(h));
134
+ });
118
135
  /**
119
136
  * A page in a browser (the studio, a wizard's own page) tells of an error it met: the line
120
137
  * goes into this process's log like the server's own, so a look from afar sees both sides
@@ -296,6 +313,11 @@ app.route("/api/internal", internalRoutes);
296
313
  if (serves.doors) {
297
314
  app.use("/api/public/*", answers);
298
315
  app.use("/api/shares/*", answers);
316
+ // The proxy sends `/api/public` to the doors: their readiness under their own prefix.
317
+ app.get("/api/public/health", async (c) => {
318
+ const h = await health();
319
+ return c.json(publicHealth(h), httpStatus(h));
320
+ });
299
321
  app.route("/api/public/plugins", publicPluginRoutes);
300
322
  app.route("/api/public", publicRoutes);
301
323
  app.route("/api/shares", shareRoutes);
@@ -42,6 +42,24 @@ const controlClient = open(controlUrl, env.databaseAuthToken);
42
42
  /** Links, the run index, sessions and settings: what is known before a tenant's database opens. */
43
43
  export const controlDb = drizzle(controlClient, { schema: control });
44
44
  export { control };
45
+ /**
46
+ * `SELECT 1` on the control database: through the client every request uses, or through a new
47
+ * one opened for this call alone. When the first fails and the second works, this process's
48
+ * client is stuck, not the database (health.ts).
49
+ */
50
+ export async function probeControl(fresh = false) {
51
+ if (!fresh) {
52
+ await controlClient.execute("SELECT 1");
53
+ return;
54
+ }
55
+ const client = open(controlUrl, env.databaseAuthToken);
56
+ try {
57
+ await client.execute("SELECT 1");
58
+ }
59
+ finally {
60
+ client.close();
61
+ }
62
+ }
45
63
  export async function migrateControlDb() {
46
64
  await prepare(controlClient, controlUrl);
47
65
  await migrate(controlDb, { migrationsFolder: migrationsFolder("control") });
@@ -84,7 +102,21 @@ async function whileBusy(fn) {
84
102
  }
85
103
  }
86
104
  }
105
+ /** Tenant databases still opening, and since when: one that takes minutes is stuck (health.ts). */
106
+ const opening = new Map();
107
+ export function openingTenants() {
108
+ return [...opening].map(([id, since]) => ({ id, since }));
109
+ }
87
110
  async function openTenant(id) {
111
+ opening.set(id, Date.now());
112
+ try {
113
+ return await openTenantNow(id);
114
+ }
115
+ finally {
116
+ opening.delete(id);
117
+ }
118
+ }
119
+ async function openTenantNow(id) {
88
120
  let row = await controlDb.query.tenant.findFirst({ where: eq(control.tenant.id, id) });
89
121
  if (!row) {
90
122
  await controlDb.insert(control.tenant).values({ id }).onConflictDoNothing();
@@ -60,6 +60,8 @@ export const runner = sqliteTable("runner", {
60
60
  id: text("id").primaryKey(),
61
61
  url: text("url"),
62
62
  seen: integer("seen", { mode: "timestamp_ms" }).notNull(),
63
+ /** When the runner last finished a look at the line: `seen` says it lives, this that the line moves. */
64
+ lineAt: integer("line_at", { mode: "timestamp_ms" }),
63
65
  });
64
66
  /** A studio session of someone signed in at the Manage-App. The refresh token is encrypted. */
65
67
  export const session = sqliteTable("session", {
@@ -0,0 +1 @@
1
+ ALTER TABLE `runner` ADD `line_at` integer;