@engenty/wizards-runtime 0.11.1 → 0.11.3

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 (147) hide show
  1. package/README.md +25 -6
  2. package/apps/runtime/dist/agents/studio-assistant.js +2 -2
  3. package/apps/runtime/dist/app.js +9 -0
  4. package/apps/runtime/dist/assistant/primer.js +2 -2
  5. package/apps/runtime/dist/auth/index.js +32 -7
  6. package/apps/runtime/dist/authoring/guide.js +19 -19
  7. package/apps/runtime/dist/docs/dev/index.md +1 -0
  8. package/apps/runtime/dist/docs/dev/licensing.md +85 -0
  9. package/apps/runtime/dist/docs/dev/meta.json +2 -1
  10. package/apps/runtime/dist/docs/dev/plugins/events.md +1 -1
  11. package/apps/runtime/dist/docs/dev/plugins/index.md +1 -1
  12. package/apps/runtime/dist/docs/dev/plugins/runners.md +2 -2
  13. package/apps/runtime/dist/docs/dev/plugins/space.md +1 -1
  14. package/apps/runtime/dist/docs/dev/plugins/studio.md +5 -4
  15. package/apps/runtime/dist/docs/dev/wizard-format/index.md +5 -5
  16. package/apps/runtime/dist/docs/dev/wizard-format/meta.json +1 -1
  17. package/apps/runtime/dist/docs/dev/wizard-format/motion-graphics-steps.md +55 -0
  18. package/apps/runtime/dist/docs/dev/wizard-format/review-and-result.md +2 -2
  19. package/apps/runtime/dist/docs/dev/wizard-format/themes.md +1 -1
  20. package/apps/runtime/dist/docs/dev/wizard-format/views-and-widgets.md +2 -2
  21. package/apps/runtime/dist/docs/dev/wizard-format/wizard-file.md +4 -4
  22. package/apps/runtime/dist/docs/user-guide/create-account.md +11 -4
  23. package/apps/runtime/dist/docs/user-guide/first-start.md +10 -2
  24. package/apps/runtime/dist/docs/user-guide/plugins.md +1 -1
  25. package/apps/runtime/dist/docs/user-guide/space.md +15 -7
  26. package/apps/runtime/dist/docs/user-guide/steps.md +17 -16
  27. package/apps/runtime/dist/docs/user-guide/troubleshooting.md +3 -3
  28. package/apps/runtime/dist/engine/requirements.js +7 -7
  29. package/apps/runtime/dist/engine/runner.js +8 -1
  30. package/apps/runtime/dist/engine/steps.js +3 -3
  31. package/apps/runtime/dist/files/storage.js +3 -3
  32. package/apps/runtime/dist/index.js +3 -0
  33. package/apps/runtime/dist/limits.js +16 -0
  34. package/apps/runtime/dist/manage.js +79 -2
  35. package/apps/runtime/dist/models.js +8 -8
  36. package/apps/runtime/dist/{film → motion-graphics}/project.js +54 -54
  37. package/apps/runtime/dist/{film → motion-graphics}/sounds.js +3 -3
  38. package/apps/runtime/dist/{film → motion-graphics}/step.js +37 -37
  39. package/apps/runtime/dist/{film → motion-graphics}/tools.js +1 -1
  40. package/apps/runtime/dist/render/downloads.js +2 -2
  41. package/apps/runtime/dist/render/guard.js +1 -1
  42. package/apps/runtime/dist/routes/delivery.js +1 -1
  43. package/apps/runtime/dist/routes/internal.js +1 -1
  44. package/apps/runtime/dist/routes/marketplace.js +29 -4
  45. package/apps/runtime/dist/routes/organization.js +114 -0
  46. package/apps/runtime/dist/routes/person.js +45 -0
  47. package/apps/runtime/dist/routes/reports.js +80 -0
  48. package/apps/runtime/dist/routes/runs.js +25 -1
  49. package/apps/runtime/dist/routes/studio.js +63 -7
  50. package/apps/runtime/dist/services/brand.js +1 -1
  51. package/apps/runtime/dist/services/manage-reports.js +190 -0
  52. package/apps/runtime/dist/services/marketplace.js +33 -1
  53. package/apps/runtime/dist/services/onboarding-find.js +123 -0
  54. package/apps/runtime/dist/services/onboarding.js +77 -16
  55. package/apps/runtime/dist/services/organization-context.js +40 -0
  56. package/apps/runtime/dist/services/pages.js +1 -1
  57. package/apps/runtime/dist/services/shipped-fonts.js +2 -1
  58. package/apps/runtime/dist/services/wizards.js +7 -0
  59. package/apps/runtime/dist/texts.js +12 -1
  60. package/apps/runtime/dist/widgets/render.js +9 -9
  61. package/apps/runtime/dist/widgets/runtime.js +3 -3
  62. package/apps/runtime/dist/widgets/step.js +20 -20
  63. package/apps/web/dist/assets/{AboutDialog-D2r8kBfV.js → AboutDialog-DlbfynVv.js} +1 -1
  64. package/apps/web/dist/assets/{ChangelogDialog-j7Z1YhNv.js → ChangelogDialog-DciD55wO.js} +1 -1
  65. package/apps/web/dist/assets/{CodeEditor-BTCMfVFJ.js → CodeEditor-9kXX-juf.js} +1 -1
  66. package/apps/web/dist/assets/EditorPage-ovstPrvJ.js +3 -0
  67. package/apps/web/dist/assets/{FlowPreview-BtVgtW7P.js → FlowPreview-BY3kJO9l.js} +1 -1
  68. package/apps/web/dist/assets/{Harness-H4Ue1HOd.js → Harness-BqcSaPmJ.js} +2 -2
  69. package/apps/web/dist/assets/Marketplace-DxcNtFdJ.js +2 -0
  70. package/apps/web/dist/assets/{NewWizardChannels-K1HOzkXf.js → NewWizardChannels-CmeAOy0q.js} +1 -1
  71. package/apps/web/dist/assets/NewWizardPage-C2Ne-QFZ.js +7 -0
  72. package/apps/web/dist/assets/OnboardingPage-CGEgLpx0.js +1 -0
  73. package/apps/web/dist/assets/PreviewPane-VnxYvrbF.js +10 -0
  74. package/apps/web/dist/assets/ProjectPage-CGpsFPJ4.js +1 -0
  75. package/apps/web/dist/assets/PublicRunner-b4vSNmVB.js +1 -0
  76. package/apps/web/dist/assets/{ReadOnly-Duk1YpNM.js → ReadOnly-C7Kk-1Vg.js} +1 -1
  77. package/apps/web/dist/assets/SettingsPage-Cgt3zVu5.js +2 -0
  78. package/apps/web/dist/assets/SetupPage-DmYnhiMq.js +1 -0
  79. package/apps/web/dist/assets/{SharePage-DvAUwrOl.js → SharePage-DMgm31Y_.js} +1 -1
  80. package/apps/web/dist/assets/changelog-CJYpF3Mx.js +1 -0
  81. package/apps/web/dist/assets/{coins-DSvwvqtQ.js → coins-Dd9IUAaR.js} +1 -1
  82. package/apps/web/dist/assets/i18n-QZC6TtrB.js +55 -0
  83. package/apps/web/dist/assets/index-Cfn8Jnfl.js +34 -0
  84. package/apps/web/dist/assets/index-DQc1EITf.css +1 -0
  85. package/apps/web/dist/assets/{oss-credits-BLVLXRzs.js → oss-credits-C6bPkfSE.js} +1 -1
  86. package/apps/web/dist/assets/{phone-xIUU1ZFn.js → phone-DKeaGjd9.js} +1 -1
  87. package/apps/web/dist/assets/runners-D2_oJdgS.js +1 -0
  88. package/apps/web/dist/assets/session-DBNhp6sF.js +2 -0
  89. package/apps/web/dist/assets/settings-menu-B09fSEin.js +1 -0
  90. package/apps/web/dist/assets/theme-CdWeSjNs.js +11 -0
  91. package/apps/web/dist/assets/{ui-6AgUKJhQ.js → ui-BPfapiMz.js} +6 -6
  92. package/apps/web/dist/assets/{upload-C8WgcG1g.js → upload-DCYRRi4d.js} +1 -1
  93. package/apps/web/dist/assets/{useMutation-BdCg6qrc.js → useMutation-BGqWiJkl.js} +1 -1
  94. package/apps/web/dist/assets/{volume-2-jlgQapiz.js → volume-2-D_FTVDPk.js} +1 -1
  95. package/apps/web/dist/assets/{wrench-Ca_TrBQk.js → wrench-BYwez0dN.js} +1 -1
  96. package/apps/web/dist/index.html +9 -9
  97. package/apps/web/dist/mcp/flow.html +32 -32
  98. package/node_modules/@engenty/wizards/dist/plugin/index.d.ts +2 -2
  99. package/node_modules/@engenty/wizards/dist/plugin/studio.d.ts +5 -5
  100. package/node_modules/@engenty/wizards-shared/dist/addresses.d.ts +17 -0
  101. package/node_modules/@engenty/wizards-shared/dist/addresses.js +97 -0
  102. package/node_modules/@engenty/wizards-shared/dist/definition.d.ts +11 -11
  103. package/node_modules/@engenty/wizards-shared/dist/definition.js +24 -23
  104. package/node_modules/@engenty/wizards-shared/dist/engenty/data-tables/columns-value.js +1 -0
  105. package/node_modules/@engenty/wizards-shared/dist/feature-flags.d.ts +9 -3
  106. package/node_modules/@engenty/wizards-shared/dist/feature-flags.js +9 -3
  107. package/node_modules/@engenty/wizards-shared/dist/fit.d.ts +7 -2
  108. package/node_modules/@engenty/wizards-shared/dist/fit.js +23 -6
  109. package/node_modules/@engenty/wizards-shared/dist/marketplace-entry.d.ts +1 -1
  110. package/node_modules/@engenty/wizards-shared/dist/marketplace-entry.js +1 -1
  111. package/node_modules/@engenty/wizards-shared/dist/marketplace.d.ts +16 -7
  112. package/node_modules/@engenty/wizards-shared/dist/marketplace.js +7 -23
  113. package/node_modules/@engenty/wizards-shared/dist/run.d.ts +15 -14
  114. package/node_modules/@engenty/wizards-shared/dist/run.js +30 -28
  115. package/node_modules/@engenty/wizards-shared/dist/runners.d.ts +1 -1
  116. package/node_modules/@engenty/wizards-shared/dist/runners.js +5 -5
  117. package/node_modules/@engenty/wizards-shared/dist/sectors.d.ts +24 -0
  118. package/node_modules/@engenty/wizards-shared/dist/sectors.js +319 -0
  119. package/node_modules/@engenty/wizards-shared/dist/store.d.ts +1 -1
  120. package/node_modules/@engenty/wizards-shared/dist/store.js +1 -2
  121. package/node_modules/@engenty/wizards-shared/dist/theme-look.d.ts +39 -0
  122. package/node_modules/@engenty/wizards-shared/dist/theme-look.js +112 -0
  123. package/node_modules/@engenty/wizards-shared/dist/theme.d.ts +0 -38
  124. package/node_modules/@engenty/wizards-shared/dist/theme.js +1 -108
  125. package/node_modules/@engenty/wizards-shared/dist/wizard-package.js +1 -0
  126. package/package.json +1 -1
  127. package/plugin/.claude-plugin/plugin.json +1 -1
  128. package/plugin/plugin.json +1 -1
  129. package/apps/runtime/dist/docs/dev/wizard-format/film-steps.md +0 -47
  130. package/apps/web/dist/assets/EditorPage-mx6XuEIw.js +0 -3
  131. package/apps/web/dist/assets/Marketplace-YEZDpGm9.js +0 -2
  132. package/apps/web/dist/assets/NewWizardPage-DSHVwwnU.js +0 -7
  133. package/apps/web/dist/assets/OnboardingPage-CoBNtV_1.js +0 -1
  134. package/apps/web/dist/assets/PreviewPane-z0-Glj7p.js +0 -10
  135. package/apps/web/dist/assets/ProjectPage-DFaPSeda.js +0 -1
  136. package/apps/web/dist/assets/PublicRunner-DgT4CApp.js +0 -1
  137. package/apps/web/dist/assets/SettingsPage-FimvOhQq.js +0 -2
  138. package/apps/web/dist/assets/SetupPage-BxEMrMtA.js +0 -1
  139. package/apps/web/dist/assets/changelog-CS9GmnXd.js +0 -1
  140. package/apps/web/dist/assets/i18n-UTsgNY5M.js +0 -55
  141. package/apps/web/dist/assets/index-DHIXX69l.js +0 -20
  142. package/apps/web/dist/assets/index-Mt1sNdPx.css +0 -1
  143. package/apps/web/dist/assets/runners-CrSLA6HI.js +0 -1
  144. package/apps/web/dist/assets/session-CbWzkHl0.js +0 -2
  145. package/apps/web/dist/assets/settings-menu-DoRItnPf.js +0 -1
  146. package/apps/web/dist/assets/theme-znovbShL.js +0 -11
  147. /package/apps/runtime/dist/{film → motion-graphics}/skills.js +0 -0
@@ -0,0 +1,114 @@
1
+ import { Hono } from "hono";
2
+ import { z } from "zod";
3
+ import { addTenantDomain, cancelInvitation, changeTenantAddress, checkTenantAddress, createTenantKey, deleteTenantKey, inviteMember, ManageError, managed, removeMember, removeTenantDomain, setMemberRole, tenantAddress, tenantBilling, tenantBillingActivity, tenantInvoicePdf, tenantKeys, verifyTenantDomain, } from "../manage.js";
4
+ import { requestLang, say } from "./lang.js";
5
+ const role = z.enum(["owner", "admin", "member"]);
6
+ /** The Manage-App's answer, or its refusal with its status and code. */
7
+ async function answer(c, work) {
8
+ try {
9
+ return c.json(await work);
10
+ }
11
+ catch (err) {
12
+ if (err instanceof ManageError) {
13
+ return c.json({ error: err.message, code: err.code }, err.status);
14
+ }
15
+ throw err;
16
+ }
17
+ }
18
+ /**
19
+ * The organization's people, changed from the studio's settings: the runtime asks the Manage-App
20
+ * for the person signed in, and the Manage-App checks their role (docs/manage-contract.md). A
21
+ * refusal keeps its status and code; the studio says it in its own words.
22
+ */
23
+ export const organizationRoutes = new Hono()
24
+ .use(async (c, next) => {
25
+ if (!managed) {
26
+ return c.json({ error: say(c, "onlyAvailableCloud"), code: "not_managed" }, 404);
27
+ }
28
+ await next();
29
+ })
30
+ .post("/invitations", async (c) => {
31
+ const user = c.get("user");
32
+ const body = z
33
+ .object({ email: z.string().trim().email().max(254), role: role.default("member") })
34
+ .parse(await c.req.json());
35
+ const lang = requestLang(c) === "en" ? "en" : "de";
36
+ return answer(c, inviteMember(user.tenantId, { actorId: user.id, ...body, lang }));
37
+ })
38
+ .delete("/invitations/:id", async (c) => {
39
+ const user = c.get("user");
40
+ return answer(c, cancelInvitation(user.tenantId, user.id, c.req.param("id")));
41
+ })
42
+ .patch("/members/:userId", async (c) => {
43
+ const user = c.get("user");
44
+ const body = z.object({ role }).parse(await c.req.json());
45
+ return answer(c, setMemberRole(user.tenantId, user.id, c.req.param("userId"), body.role));
46
+ })
47
+ .delete("/members/:userId", async (c) => {
48
+ const user = c.get("user");
49
+ return answer(c, removeMember(user.tenantId, user.id, c.req.param("userId")));
50
+ })
51
+ .get("/address", async (c) => {
52
+ const user = c.get("user");
53
+ return answer(c, tenantAddress(user.tenantId, user.id));
54
+ })
55
+ .get("/address/check", async (c) => answer(c, checkTenantAddress(c.get("user").tenantId, c.req.query("slug") ?? "")))
56
+ .put("/address", async (c) => {
57
+ const user = c.get("user");
58
+ const { slug } = z.object({ slug: z.string().trim().max(64) }).parse(await c.req.json());
59
+ return answer(c, changeTenantAddress(user.tenantId, user.id, slug));
60
+ })
61
+ .post("/domains", async (c) => {
62
+ const user = c.get("user");
63
+ const { domain } = z.object({ domain: z.string().max(260) }).parse(await c.req.json());
64
+ return answer(c, addTenantDomain(user.tenantId, user.id, domain));
65
+ })
66
+ .post("/domains/:id/verify", async (c) => {
67
+ const user = c.get("user");
68
+ return answer(c, verifyTenantDomain(user.tenantId, user.id, c.req.param("id")));
69
+ })
70
+ .delete("/domains/:id", async (c) => {
71
+ const user = c.get("user");
72
+ return answer(c, removeTenantDomain(user.tenantId, user.id, c.req.param("id")));
73
+ })
74
+ .get("/keys", async (c) => {
75
+ const user = c.get("user");
76
+ return answer(c, tenantKeys(user.tenantId, user.id));
77
+ })
78
+ .post("/keys", async (c) => {
79
+ const user = c.get("user");
80
+ const { name } = z.object({ name: z.string().trim().min(1).max(32) }).parse(await c.req.json());
81
+ return answer(c, createTenantKey(user.tenantId, user.id, name));
82
+ })
83
+ .delete("/keys/:id", async (c) => {
84
+ const user = c.get("user");
85
+ return answer(c, deleteTenantKey(user.tenantId, user.id, c.req.param("id")));
86
+ })
87
+ .get("/billing", async (c) => {
88
+ const user = c.get("user");
89
+ return answer(c, tenantBilling(user.tenantId, user.id));
90
+ })
91
+ .get("/billing/activity", async (c) => {
92
+ const user = c.get("user");
93
+ const q = z
94
+ .object({
95
+ before: z.coerce.number().int().positive().optional(),
96
+ limit: z.coerce.number().int().min(1).max(100).optional(),
97
+ })
98
+ .parse(c.req.query());
99
+ return answer(c, tenantBillingActivity(user.tenantId, user.id, q));
100
+ })
101
+ // The invoice's PDF lies at Stripe: the studio's link goes there by way of this address.
102
+ .get("/invoices/:id/pdf", async (c) => {
103
+ const user = c.get("user");
104
+ try {
105
+ const { url } = await tenantInvoicePdf(user.tenantId, user.id, c.req.param("id"));
106
+ return c.redirect(url);
107
+ }
108
+ catch (err) {
109
+ if (err instanceof ManageError) {
110
+ return c.json({ error: err.message, code: err.code }, err.status);
111
+ }
112
+ throw err;
113
+ }
114
+ });
@@ -0,0 +1,45 @@
1
+ import { Hono } from "hono";
2
+ import { z } from "zod";
3
+ import { renameSessions } from "../auth/index.js";
4
+ import { disconnectPersonApp, ManageError, managed, personConnections, renamePerson, signOutPersonComputer, } from "../manage.js";
5
+ import { say } from "./lang.js";
6
+ async function answer(c, work) {
7
+ try {
8
+ return c.json(await work);
9
+ }
10
+ catch (err) {
11
+ if (err instanceof ManageError) {
12
+ return c.json({ error: err.message, code: err.code }, err.status);
13
+ }
14
+ throw err;
15
+ }
16
+ }
17
+ /**
18
+ * The person's Konto in the cloud studio, behind the avatar: their name and what holds a sign-in
19
+ * of theirs, kept at the Manage-App for every organization (docs/manage-contract.md).
20
+ */
21
+ export const personRoutes = new Hono()
22
+ .use(async (c, next) => {
23
+ if (!managed) {
24
+ return c.json({ error: say(c, "onlyAvailableCloud"), code: "not_managed" }, 404);
25
+ }
26
+ await next();
27
+ })
28
+ .put("/name", async (c) => {
29
+ const user = c.get("user");
30
+ const { name } = z.object({ name: z.string().trim().min(1).max(80) }).parse(await c.req.json());
31
+ try {
32
+ const done = await renamePerson(user.id, name);
33
+ await renameSessions(user.id, done.name);
34
+ return c.json(done);
35
+ }
36
+ catch (err) {
37
+ if (err instanceof ManageError) {
38
+ return c.json({ error: err.message, code: err.code }, err.status);
39
+ }
40
+ throw err;
41
+ }
42
+ })
43
+ .get("/connections", async (c) => answer(c, personConnections(c.get("user").id)))
44
+ .delete("/connections/:id", async (c) => answer(c, disconnectPersonApp(c.get("user").id, c.req.param("id"))))
45
+ .delete("/computers/:id", async (c) => answer(c, signOutPersonComputer(c.get("user").id, c.req.param("id"))));
@@ -0,0 +1,80 @@
1
+ import { eq } from "drizzle-orm";
2
+ import { Hono } from "hono";
3
+ import { bodyLimit } from "hono/body-limit";
4
+ import { z } from "zod";
5
+ import { principalOf } from "../auth/index.js";
6
+ import { db, schema, withTenant } from "../db/client.js";
7
+ import { allowed, hashIp } from "../limits.js";
8
+ import { managed, postBugReport } from "../manage.js";
9
+ import { tenantOfRun } from "../tenants/control.js";
10
+ import { clientIp } from "./runs.js";
11
+ /**
12
+ * "Report a problem" (docs/plans/wizards-admin.md in the Manage repository): what a person chose
13
+ * to send from the run page or the studio – their words, a screenshot with their marks, the
14
+ * error, the log lines – goes on to the Manage-App's bug reports. The dialog masked what was
15
+ * typed into the wizard before it left the browser. A runtime that runs alone has nobody to
16
+ * send it to: the report goes into its own log.
17
+ */
18
+ const SCREENSHOT = /^data:image\/(png|jpeg|webp);base64,[A-Za-z0-9+/=]+$/;
19
+ const line = (max) => z.string().trim().max(max);
20
+ export const bugReportBody = z.object({
21
+ where: z.enum(["run", "studio", "page"]),
22
+ url: z.string().url().max(2000),
23
+ runId: z
24
+ .string()
25
+ .regex(/^[A-Za-z0-9_-]{1,64}$/)
26
+ .nullable()
27
+ .optional(),
28
+ comment: line(4000).nullable().optional(),
29
+ error: z
30
+ .object({ message: line(2000), stack: line(8000).optional() })
31
+ .nullable()
32
+ .optional(),
33
+ logs: z.array(line(2000)).max(200).default([]),
34
+ screenshot: z.string().max(4_000_000).regex(SCREENSHOT).nullable().optional(),
35
+ contact: z.string().trim().email().max(200).nullable().optional(),
36
+ });
37
+ export const reportRoutes = new Hono().post("/bug-reports", bodyLimit({ maxSize: 4_500_000 }), async (c) => {
38
+ const ip = hashIp(clientIp(c));
39
+ if (!allowed(`bug:${ip ?? "?"}`, 10, 60 * 60 * 1000)) {
40
+ return c.json({ ok: false }, 429);
41
+ }
42
+ const parsed = bugReportBody.safeParse(await c.req.json().catch(() => null));
43
+ if (!parsed.success) {
44
+ return c.json({ ok: false, issues: parsed.error.issues.map((i) => i.path.join(".")) }, 400);
45
+ }
46
+ const body = parsed.data;
47
+ // The team and the wizard, as far as the run or the signed-in person tells them.
48
+ const who = await principalOf(c).catch(() => null);
49
+ let tenantId = who?.tenantId ?? null;
50
+ let wizardId = null;
51
+ if (body.runId) {
52
+ const runTenant = await tenantOfRun(body.runId);
53
+ if (runTenant && (!tenantId || tenantId === runTenant)) {
54
+ tenantId = runTenant;
55
+ const run = await withTenant(runTenant, () => db.query.run.findFirst({
56
+ where: eq(schema.run.id, body.runId),
57
+ columns: { wizardId: true },
58
+ }));
59
+ wizardId = run?.wizardId ?? null;
60
+ }
61
+ }
62
+ const report = {
63
+ ...body,
64
+ tenantId,
65
+ wizardId,
66
+ userAgent: c.req.header("user-agent")?.slice(0, 400) ?? null,
67
+ };
68
+ if (!managed) {
69
+ console.error(`[bug report ${tenantId ?? "visitor"}] at ${body.url}: ${body.comment ?? ""} ${body.error?.message ?? ""}`);
70
+ return c.json({ ok: true, sent: false });
71
+ }
72
+ try {
73
+ const { id } = await postBugReport(report);
74
+ return c.json({ ok: true, sent: true, id });
75
+ }
76
+ catch (err) {
77
+ console.error("[bug report] not sent:", err.message);
78
+ return c.json({ ok: false }, 502);
79
+ }
80
+ });
@@ -28,6 +28,7 @@ import { loadAsset, saveAsset } from "../files/storage.js";
28
28
  import { checkUpload } from "../files/upload-check.js";
29
29
  import { reverseGeocode } from "../geocode.js";
30
30
  import { allowed, hashIp, verifyTurnstile, wizardUnavailable } from "../limits.js";
31
+ import { managed, postFeedback } from "../manage.js";
31
32
  import { mintConversation } from "../media/conversation.js";
32
33
  import { transcribeAudio } from "../media/transcribe.js";
33
34
  import { errorText, ModelUnavailableError, noteOf } from "../model-errors.js";
@@ -1375,6 +1376,29 @@ export const runRoutes = new Hono()
1375
1376
  }
1376
1377
  await unshareRun(run);
1377
1378
  return c.json({ ok: true });
1379
+ })
1380
+ // "How did it go?" at the end of a run: the answer goes on to the Manage-App's feedback.
1381
+ .post("/:id/feedback", async (c) => {
1382
+ const run = await accessibleRun(c, c.req.param("id"));
1383
+ if (!run) {
1384
+ return c.json(notFoundAnswer(c), 404);
1385
+ }
1386
+ if (run.status !== "done" && run.status !== "failed") {
1387
+ return c.json({ error: "The run is not over yet." }, 409);
1388
+ }
1389
+ const body = z
1390
+ .object({ good: z.boolean(), comment: z.string().trim().max(1000).optional() })
1391
+ .parse(await c.req.json());
1392
+ if (managed) {
1393
+ await postFeedback(run.tenantId, {
1394
+ runId: run.id,
1395
+ wizardId: run.wizardId,
1396
+ good: body.good,
1397
+ comment: body.comment || null,
1398
+ lang: run.lang ?? wizardLang(run.definition),
1399
+ }).catch((err) => console.warn(`[run ${run.id}] feedback not sent:`, err.message));
1400
+ }
1401
+ return c.json({ ok: true });
1378
1402
  })
1379
1403
  // --- sending the result on: by e-mail, into a folder, to a channel, onto a website ---------
1380
1404
  .get("/:id/share/targets", async (c) => {
@@ -1526,7 +1550,7 @@ async function serveAsset(c, run, assetId) {
1526
1550
  // A PDF is left to the browser's own viewer, which a sandbox would keep from starting.
1527
1551
  ...(mime === "application/pdf" ? {} : { "content-security-policy": "sandbox" }),
1528
1552
  };
1529
- // Foreign files are downloads, never pages of ours: only photos, sound, film and PDFs show in place.
1553
+ // Foreign files are downloads, never pages of ours: only photos, sound, video and PDFs show in place.
1530
1554
  if (foreign && !inlineSafe(mime)) {
1531
1555
  headers["content-disposition"] =
1532
1556
  `attachment; filename="${found.row.name.replace(/["\\\r\n]/g, "")}"`;
@@ -50,7 +50,9 @@ import { notFound, ServiceError } from "../services/errors.js";
50
50
  import { deleteFile, listFiles, readFile, writeFile } from "../services/files.js";
51
51
  import { categoryContents, listKnowledge, resolvePath, valueContents, } from "../services/knowledge.js";
52
52
  import { writeSummary } from "../services/knowledge-model.js";
53
- import { applyWebsite, finishOnboarding, needsOnboarding } from "../services/onboarding.js";
53
+ import { applyAddresses, finishOnboarding, onboardingFor, startingName, } from "../services/onboarding.js";
54
+ import { findAddresses, siteOfEmail } from "../services/onboarding-find.js";
55
+ import { setOrganizationContext } from "../services/organization-context.js";
54
56
  import { exportWizard, importWizard } from "../services/package.js";
55
57
  import { pagePreview } from "../services/pages.js";
56
58
  import { asAssistantIn, leave, markPresent, presentByItem, presentIn, } from "../services/presence.js";
@@ -260,6 +262,10 @@ export const studio = new Hono()
260
262
  tenant: {
261
263
  id: user.tenantId,
262
264
  role: user.role,
265
+ /** The organization's name as the Manage-App keeps it; alone, the linked account's, else null. */
266
+ name: (managed ? info?.name : overview?.tenant.name) ?? null,
267
+ /** The organization's address, `acme` in `/studio/acme/`; null alone, where the studio has none. */
268
+ slug: managed ? (info?.slug ?? null) : null,
263
269
  /** The plan the organization is on; null alone, or where the Manage-App names none. */
264
270
  plan: info?.plan ?? null,
265
271
  /** The organization's address for its public page (`acme.wizards.page`); null alone, or behind its switch. */
@@ -271,6 +277,10 @@ export const studio = new Hono()
271
277
  features: features(managed ? { ...info?.features, ...person?.features } : overview?.tenant.features),
272
278
  /** The studio assistant's developer mode may be switched on: ASSISTANT_DEV here, the platform's admins when managed. */
273
279
  assistantDev: await assistantDevFor(user),
280
+ /** The person's organizations, their own first: the switcher lists them. Empty alone. */
281
+ organizations: person?.tenants ?? [],
282
+ /** The person may make further organizations (the platform's admins), on the account page. */
283
+ mayCreateOrganization: person?.admin ?? false,
274
284
  mode: managed ? "managed" : "local",
275
285
  /** The tenant's balance; null where the runtime resolves models itself. */
276
286
  credits: managed ? await balanceCredits() : null,
@@ -299,8 +309,10 @@ export const studio = new Hono()
299
309
  subscriptions: managed ? [] : await subscriptionClients(),
300
310
  /** A runtime that runs alone keeps its setup in front until a test call has worked on the chosen source and the way is still open. */
301
311
  setupDone: managed ? true : await setupDone(),
302
- /** The cloud studio's first visit: the short wizard that names the organization and fills the space (services/onboarding.ts). */
303
- onboarding: await needsOnboarding(user),
312
+ /** The cloud studio's first visit, by what the studio knows of the person and the organization (services/onboarding.ts); null when done. */
313
+ onboarding: await onboardingFor(user, person?.tenants ?? []),
314
+ /** The organization still has the name the Manage-App gave it at sign-up: its first admin names it. */
315
+ startingName: managed ? startingName(info?.name) : false,
304
316
  /** What answers the studio's chats (Goose, the editor's chat): the text classes, a subscription, a key or the credits. */
305
317
  chatEngine: managed ? "models" : await chatEngine(await hasTextModel()),
306
318
  /** The ways that can answer the studio's chats now. */
@@ -1669,11 +1681,44 @@ export const studio = new Hono()
1669
1681
  legalName: field(200),
1670
1682
  phone: field(40),
1671
1683
  website: field(400),
1684
+ /** The addresses the person ticked or added. */
1685
+ links: z.array(z.string().trim().max(400)).max(10).optional(),
1686
+ /** “Wünsche oder Fragen”: a question reaches the team by mail. */
1687
+ questions: field(4000),
1672
1688
  })
1673
1689
  .parse(await c.req.json());
1674
1690
  const user = c.get("user");
1675
1691
  await saveOrganizationProfile(user.tenantId, user.id, requestLang(c) === "de" ? "de" : "en", profile);
1692
+ // The new-wizard page puts the templates that fit it first.
1693
+ await setOrganizationContext(user.tenantId, {
1694
+ sector: profile.sector ?? null,
1695
+ kind: profile.kind,
1696
+ size: profile.size ?? null,
1697
+ words: [profile.need, profile.questions].filter(Boolean).join(" "),
1698
+ });
1676
1699
  return c.json({ ok: true });
1700
+ })
1701
+ // The first visit: the name and site of the person's e-mail domain, where it is an organization's.
1702
+ .get("/onboarding/suggest", async (c) => {
1703
+ if (!managed) {
1704
+ return c.json({ error: say(c, "onlyAvailableCloud"), code: "not_managed" }, 404);
1705
+ }
1706
+ await requireAdmin();
1707
+ return c.json({ site: await siteOfEmail(c.get("user").email) });
1708
+ })
1709
+ // The organization's addresses to tick: its e-mail domain's site, then a web search for its name.
1710
+ .post("/onboarding/find", async (c) => {
1711
+ if (!managed) {
1712
+ return c.json({ error: say(c, "onlyAvailableCloud"), code: "not_managed" }, 404);
1713
+ }
1714
+ await requireAdmin();
1715
+ const { name, lang } = z
1716
+ .object({ name: z.string().trim().max(120), lang: z.enum(LANGS).optional() })
1717
+ .parse(await c.req.json());
1718
+ const user = c.get("user");
1719
+ return c.json({
1720
+ addresses: await findAddresses({ name, email: user.email, lang: lang ?? requestLang(c) }),
1721
+ });
1677
1722
  })
1678
1723
  .post("/onboarding/done", async (c) => {
1679
1724
  if (!managed) {
@@ -1682,16 +1727,27 @@ export const studio = new Hono()
1682
1727
  code: "not_managed",
1683
1728
  }, 404);
1684
1729
  }
1685
- await finishOnboarding(c.get("user").tenantId);
1730
+ const user = c.get("user");
1731
+ const person = await userInfo(user.id);
1732
+ const mode = await onboardingFor(user, person?.tenants ?? []);
1733
+ if (mode) {
1734
+ await finishOnboarding(user, mode);
1735
+ }
1686
1736
  return c.json({ ok: true });
1687
1737
  })
1688
1738
  .post("/projects/:id/website", async (c) => {
1689
1739
  const user = c.get("user");
1690
1740
  const project = await ownedProject(user.id, c.req.param("id"));
1691
- const { url, lang } = z
1692
- .object({ url: z.string().trim().min(3).max(400), lang: z.enum(LANGS).optional() })
1741
+ // One address (as before) or several: the first website is read, the others kept as facts.
1742
+ const { url, urls, lang } = z
1743
+ .object({
1744
+ url: z.string().trim().min(3).max(400).optional(),
1745
+ urls: z.array(z.string().trim().min(3).max(400)).max(10).optional(),
1746
+ lang: z.enum(LANGS).optional(),
1747
+ })
1693
1748
  .parse(await c.req.json());
1694
- return c.json(await applyWebsite(user.id, project.id, url, lang ?? requestLang(c)));
1749
+ const outcome = await applyAddresses(user.id, project.id, urls ?? (url ? [url] : []), lang ?? requestLang(c));
1750
+ return c.json(outcome);
1695
1751
  })
1696
1752
  // The install command and the first steps, mailed to the signed-in person by the Manage-App.
1697
1753
  .post("/install-mail", async (c) => {
@@ -1,6 +1,6 @@
1
1
  import { GRADIENT_TYPES, gradientCss, mainLogo, runTheme, } from "@engenty/wizards-shared/projects";
2
2
  import { note } from "@engenty/wizards-shared/run";
3
- import { chosenTheme, lookColours, themedLook } from "@engenty/wizards-shared/theme";
3
+ import { chosenTheme, lookColours, themedLook } from "@engenty/wizards-shared/theme-look";
4
4
  import { generateText, Output } from "ai";
5
5
  import { and, asc, eq } from "drizzle-orm";
6
6
  import { z } from "zod";
@@ -0,0 +1,190 @@
1
+ import { capabilitiesOf, effortOf } from "@engenty/wizards-shared/marketplace";
2
+ import { resultsOf } from "@engenty/wizards-shared/marketplace-entry";
3
+ import { and, eq, inArray } from "drizzle-orm";
4
+ import { db, knownTenants, schema, withTenant } from "../db/client.js";
5
+ import { env } from "../env.js";
6
+ import { managed, postRunReport, putWizards } from "../manage.js";
7
+ import { currentTenant } from "../tenants/tenant.js";
8
+ import { pageLangOf, pageSteps } from "./pages.js";
9
+ /**
10
+ * What the Manage-App's admin app learns of a team (docs/plans/wizards-admin.md in the Manage
11
+ * repository): its wizards, whole, after every change that shows there, and each run's turns.
12
+ * Manage never reads a tenant's database. Only a managed runtime reports.
13
+ */
14
+ let last = Promise.resolve();
15
+ /** The team's wizards as the admin app lists them: the published version where there is one. */
16
+ export async function wizardsReport() {
17
+ const tenantId = currentTenant();
18
+ const [wizards, projects] = await Promise.all([
19
+ db.select().from(schema.wizard).where(eq(schema.wizard.tenantId, tenantId)),
20
+ db
21
+ .select({ id: schema.project.id, name: schema.project.name })
22
+ .from(schema.project)
23
+ .where(eq(schema.project.tenantId, tenantId)),
24
+ ]);
25
+ const published = wizards.filter((w) => w.publishedVersion !== null);
26
+ const versions = published.length
27
+ ? await db
28
+ .select({
29
+ wizardId: schema.wizardVersion.wizardId,
30
+ version: schema.wizardVersion.version,
31
+ definition: schema.wizardVersion.definition,
32
+ createdAt: schema.wizardVersion.createdAt,
33
+ })
34
+ .from(schema.wizardVersion)
35
+ .where(inArray(schema.wizardVersion.wizardId, published.map((w) => w.id)))
36
+ : [];
37
+ const spaces = new Map(projects.map((p) => [p.id, p.name]));
38
+ return {
39
+ wizards: wizards.map((w) => {
40
+ const live = versions.find((v) => v.wizardId === w.id && v.version === w.publishedVersion);
41
+ const def = live?.definition ?? w.draft;
42
+ return {
43
+ id: w.id,
44
+ title: (def.title || w.title).slice(0, 160),
45
+ description: (def.description ?? "").slice(0, 1000),
46
+ avatar: def.avatar ?? "round",
47
+ lang: (def.lang ?? "de").slice(0, 5),
48
+ space: spaces.has(w.projectId) ? { id: w.projectId, name: spaces.get(w.projectId) } : null,
49
+ published: Boolean(live),
50
+ publishedAt: live?.createdAt.toISOString() ?? null,
51
+ template: w.starter ? { id: w.starter, revision: w.starterRevision ?? null } : null,
52
+ runUrl: live && w.shareEnabled ? `${env.publicUrl}/w/${w.shareToken}` : null,
53
+ effort: effortSent(def),
54
+ results: [...new Set(resultsOf(def).map((r) => r.kind))],
55
+ // The overview the admin app shows: the intro, the way through as the page's teaser
56
+ // draws it (about five rows), and each result with its kind and files.
57
+ intro: (def.intro ?? "").slice(0, 1000),
58
+ outline: pageSteps(def, pageLangOf(def, "en")),
59
+ deliverables: resultsOf(def).slice(0, 12),
60
+ capabilities: capabilitiesOf(def),
61
+ steps: def.steps.length,
62
+ changedAt: w.updatedAt.toISOString(),
63
+ };
64
+ }),
65
+ };
66
+ }
67
+ /** Fields whose answer is a file the person brings. */
68
+ const UPLOAD_KINDS = new Set(["file", "image", "audio"]);
69
+ /** What a run asks of the person: fields, drafts to check, minutes, and whether files come along. */
70
+ function effortSent(def) {
71
+ const effort = effortOf(def);
72
+ return {
73
+ fields: effort.fields,
74
+ reviews: effort.reviews,
75
+ minutes: effort.minutes,
76
+ uploads: def.steps.some((s) => s.type === "page" && s.fields.some((f) => UPLOAD_KINDS.has(f.kind))),
77
+ };
78
+ }
79
+ /** Sends the team's wizards; one send after the other, a failure is only written down. */
80
+ export function pushWizards() {
81
+ if (!managed) {
82
+ return;
83
+ }
84
+ const tenantId = currentTenant();
85
+ const send = async () => {
86
+ await putWizards(tenantId, await withTenant(tenantId, () => wizardsReport()));
87
+ };
88
+ last = last.then(send, send).catch((err) => {
89
+ console.error("[reports] the wizards were not sent:", err.message);
90
+ });
91
+ }
92
+ export function wizardsSettled() {
93
+ return last;
94
+ }
95
+ /**
96
+ * Every team's wizards once, at the start: what changed while no report went out, and the wizards
97
+ * of teams from before this report existed. One team after the other.
98
+ */
99
+ export async function reportAllWizards() {
100
+ if (!managed) {
101
+ return;
102
+ }
103
+ for (const tenantId of await knownTenants()) {
104
+ await withTenant(tenantId, async () => {
105
+ pushWizards();
106
+ await wizardsSettled();
107
+ }).catch((err) => console.warn(`[reports] ${tenantId}:`, err.message));
108
+ }
109
+ }
110
+ const STATE = {
111
+ waiting_input: "waiting",
112
+ running: "running",
113
+ done: "finished",
114
+ failed: "failed",
115
+ cancelled: "cancelled",
116
+ };
117
+ /** A run at work says so again after this long, so the admin app can tell it from a stuck one. */
118
+ const AGAIN_MS = 2 * 60_000;
119
+ const said = new Map();
120
+ const OWN_CLIENTS = new Set(["web", "app"]);
121
+ /** Where the run came from, as the admin app sorts it. */
122
+ function viaOf(run) {
123
+ if (run.mode === "test") {
124
+ return "test";
125
+ }
126
+ // The run page names itself `web`, the mobile app `app`: any other client is the public API's.
127
+ if (run.client && !OWN_CLIENTS.has(run.client)) {
128
+ return "api";
129
+ }
130
+ if (run.origin) {
131
+ return "page";
132
+ }
133
+ return run.userId ? "studio" : "link";
134
+ }
135
+ /**
136
+ * Tells the admin app of a run's turn: a new state at once, the same state again only after a
137
+ * while (a long step at work is not stuck). Runs in the current tenant's context.
138
+ */
139
+ export function reportRun(runId, status) {
140
+ if (!managed) {
141
+ return;
142
+ }
143
+ const state = STATE[status];
144
+ const before = said.get(runId);
145
+ if (before && before.state === state && Date.now() - before.at < AGAIN_MS) {
146
+ return;
147
+ }
148
+ said.set(runId, { state, at: Date.now() });
149
+ if (state === "finished" || state === "failed" || state === "cancelled") {
150
+ // A run that ended says nothing more; the map forgets it.
151
+ setTimeout(() => said.delete(runId), AGAIN_MS).unref?.();
152
+ }
153
+ const tenantId = currentTenant();
154
+ void (async () => {
155
+ const run = await db.query.run.findFirst({
156
+ where: and(eq(schema.run.id, runId), eq(schema.run.tenantId, tenantId)),
157
+ columns: {
158
+ wizardId: true,
159
+ mode: true,
160
+ client: true,
161
+ origin: true,
162
+ userId: true,
163
+ cursor: true,
164
+ error: true,
165
+ definition: true,
166
+ createdAt: true,
167
+ },
168
+ });
169
+ if (!run) {
170
+ return;
171
+ }
172
+ const step = state === "failed" && run.cursor
173
+ ? run.definition.steps.find((s) => s.id === run.cursor)
174
+ : undefined;
175
+ await postRunReport(tenantId, {
176
+ runId,
177
+ wizardId: run.wizardId,
178
+ via: viaOf(run),
179
+ state,
180
+ startedAt: run.createdAt.toISOString(),
181
+ at: new Date().toISOString(),
182
+ ...(step
183
+ ? { step: { id: step.id, title: (step.title ?? step.id).slice(0, 160), kind: step.type } }
184
+ : {}),
185
+ ...(state === "failed" && run.error ? { error: run.error.slice(0, 2000) } : {}),
186
+ });
187
+ })().catch((err) => {
188
+ console.warn(`[reports] run ${runId}:`, err.message);
189
+ });
190
+ }
@@ -10,7 +10,7 @@ import { formulaEstimate } from "../credits/estimate.js";
10
10
  import { control, controlDb, db, schema, withTenant } from "../db/client.js";
11
11
  import { missingCapabilities, optionalCapabilities, stepsWithoutModel, } from "../engine/requirements.js";
12
12
  import { env } from "../env.js";
13
- import { managed } from "../manage.js";
13
+ import { managed, tenantInfo } from "../manage.js";
14
14
  import { classCatalog, imageCostUsd, tokenCostUsd, videoCostUsd, WEB_SEARCH_COST_USD, } from "../models.js";
15
15
  import { pluginIdsOf, pluginStartersOf } from "../plugins/registry.js";
16
16
  import { readSetting, writeSetting } from "../settings.js";
@@ -219,6 +219,38 @@ async function keptOptional(ids, lang, unavailable) {
219
219
  }
220
220
  return out;
221
221
  }
222
+ /** The team's level: the Manage-App's word on a managed runtime; elsewhere every level is open. */
223
+ async function teamLevel() {
224
+ if (!managed) {
225
+ return null;
226
+ }
227
+ const info = await tenantInfo(currentTenant()).catch(() => null);
228
+ return info?.level ?? null;
229
+ }
230
+ /**
231
+ * The catalog as the team's level leaves it (docs/plans/wizards-admin.md in the Manage
232
+ * repository): a template above the level is not shown, the featured ones come first – those of
233
+ * the team's own level before the rest – and the answer says the level.
234
+ */
235
+ export async function byLevel(page, opts) {
236
+ const level = await teamLevel();
237
+ const top = level?.level ?? Number.POSITIVE_INFINITY;
238
+ const shown = page.entries.filter((e) => (e.level ?? 1) <= top);
239
+ // A search keeps its order: the words found what fits best.
240
+ const rank = (e) => e.featured ? ((e.level ?? 1) === level?.level ? 0 : 1) : 2;
241
+ const entries = opts.q?.trim()
242
+ ? shown
243
+ : shown
244
+ .map((e, i) => ({ e, i }))
245
+ .sort((a, b) => rank(a.e) - rank(b.e) || a.i - b.i)
246
+ .map((x) => x.e);
247
+ return {
248
+ ...page,
249
+ entries,
250
+ total: Math.max(0, page.total - (page.entries.length - shown.length)),
251
+ level,
252
+ };
253
+ }
222
254
  /**
223
255
  * Searches the tenant's plugins' starters and the marketplace, in that order: a page holds the
224
256
  * plugins' starters the words and filters find, then the marketplace's entries.