@engenty/wizards-runtime 0.14.1 → 0.15.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 (89) hide show
  1. package/apps/runtime/dist/agents/studio-assistant.js +50 -3
  2. package/apps/runtime/dist/app.js +9 -2
  3. package/apps/runtime/dist/broker/call.js +2 -0
  4. package/apps/runtime/dist/broker/host.js +1 -0
  5. package/apps/runtime/dist/broker/rwx.js +38 -4
  6. package/apps/runtime/dist/db/client.js +12 -1
  7. package/apps/runtime/dist/db/migrations/tenant/0040_rwx_elements.sql +21 -0
  8. package/apps/runtime/dist/db/migrations/tenant/0041_broker_log_client.sql +1 -0
  9. package/apps/runtime/dist/db/migrations/tenant/meta/0040_snapshot.json +5153 -0
  10. package/apps/runtime/dist/db/migrations/tenant/meta/0041_snapshot.json +5160 -0
  11. package/apps/runtime/dist/db/migrations/tenant/meta/_journal.json +14 -0
  12. package/apps/runtime/dist/db/schema.js +2 -0
  13. package/apps/runtime/dist/docs/dev/api.md +24 -2
  14. package/apps/runtime/dist/docs/dev/architecture.md +13 -2
  15. package/apps/runtime/dist/elements/caller.js +45 -0
  16. package/apps/runtime/dist/elements/catalogue.js +14 -0
  17. package/apps/runtime/dist/elements/connections.js +60 -0
  18. package/apps/runtime/dist/elements/gate.js +81 -0
  19. package/apps/runtime/dist/elements/knowledge.js +139 -0
  20. package/apps/runtime/dist/elements/outside.js +103 -0
  21. package/apps/runtime/dist/elements/specs.js +102 -0
  22. package/apps/runtime/dist/elements/wizards.js +59 -0
  23. package/apps/runtime/dist/env.js +5 -2
  24. package/apps/runtime/dist/health.js +50 -1
  25. package/apps/runtime/dist/mcp/elements.js +88 -0
  26. package/apps/runtime/dist/mcp/handler.js +2 -0
  27. package/apps/runtime/dist/mcp/scopes.js +5 -0
  28. package/apps/runtime/dist/prompts/authoring.md +2 -2
  29. package/apps/runtime/dist/prompts/tools.md +3 -0
  30. package/apps/runtime/dist/routes/api.js +2 -2
  31. package/apps/runtime/dist/routes/elements.js +76 -0
  32. package/apps/runtime/dist/services/work-ai.js +27 -19
  33. package/apps/runtime/dist/services/work-connections.js +2 -2
  34. package/apps/runtime/dist/tools/index.js +5 -4
  35. package/apps/runtime/dist/tools/skills.js +80 -54
  36. package/apps/runtime/dist/tools/space.js +8 -152
  37. package/apps/web/dist/assets/{AboutDialog-SpDcn8VZ.js → AboutDialog-DaWEIHFN.js} +1 -1
  38. package/apps/web/dist/assets/{CapabilitiesPage-Bgnm_3dk.js → CapabilitiesPage-Dt91U_sK.js} +2 -2
  39. package/apps/web/dist/assets/{ChangelogDialog-DAnjV6cZ.js → ChangelogDialog-Do7pwmFv.js} +1 -1
  40. package/apps/web/dist/assets/{CodeEditor-nxoOt8ge.js → CodeEditor-Cdox-51M.js} +1 -1
  41. package/apps/web/dist/assets/{EditorPage-B98C-9Nv.js → EditorPage-DS_a5K3s.js} +1 -1
  42. package/apps/web/dist/assets/{FlowPreview-aMfwcPul.js → FlowPreview-BPS86xzA.js} +1 -1
  43. package/apps/web/dist/assets/{LangSwitch-DpD0inR4.js → LangSwitch-BRHbi_Sd.js} +1 -1
  44. package/apps/web/dist/assets/{Marketplace-CpzD9pNQ.js → Marketplace-CS7JTgiv.js} +2 -2
  45. package/apps/web/dist/assets/{NewWizardChannels-D8IYLg_S.js → NewWizardChannels-D-OLsex6.js} +1 -1
  46. package/apps/web/dist/assets/{NewWizardPage-DlBt0Mfq.js → NewWizardPage-BM_pkk41.js} +1 -1
  47. package/apps/web/dist/assets/{OnboardingPage-ztHT01ah.js → OnboardingPage-Cpn5pubC.js} +1 -1
  48. package/apps/web/dist/assets/{PreviewPane-DC1kAi3x.js → PreviewPane-BOk1-yO4.js} +1 -1
  49. package/apps/web/dist/assets/{PublicRunner-D6lKP0j8.js → PublicRunner-CgzMZb0r.js} +1 -1
  50. package/apps/web/dist/assets/{ReadOnly-DFsuKPCw.js → ReadOnly-8DEx-ly3.js} +1 -1
  51. package/apps/web/dist/assets/{SettingsPage-DkHeCO2c.js → SettingsPage-CcrknFcI.js} +2 -2
  52. package/apps/web/dist/assets/{SetupPage-DZ8xRkfS.js → SetupPage-D5nzjgPU.js} +1 -1
  53. package/apps/web/dist/assets/{SharePage-494ZPsjQ.js → SharePage-PKHX8a8a.js} +1 -1
  54. package/apps/web/dist/assets/{SkillEditor-CqQMg2MC.js → SkillEditor-BsXTqNli.js} +1 -1
  55. package/apps/web/dist/assets/{Skills-CnhpgoOA.js → Skills-C_X1ZsKg.js} +1 -1
  56. package/apps/web/dist/assets/{SpacePage-CWlU_BZP.js → SpacePage-wZGqUoSQ.js} +2 -2
  57. package/apps/web/dist/assets/{UpdateCheck-BKNkNJyG.js → UpdateCheck-D6x7MqEl.js} +2 -2
  58. package/apps/web/dist/assets/changelog-M-eOBqgu.js +1 -0
  59. package/apps/web/dist/assets/{circle-alert-C8Ma-bPY.js → circle-alert-DJbCyxcg.js} +1 -1
  60. package/apps/web/dist/assets/{circle-check-Bu9Z3mlJ.js → circle-check-jqtsKi_b.js} +1 -1
  61. package/apps/web/dist/assets/{code-editor-CfTGqOpp.js → code-editor-BpCEnf8H.js} +2 -2
  62. package/apps/web/dist/assets/{code-xml-B4kLFZSj.js → code-xml-q88cSTV8.js} +1 -1
  63. package/apps/web/dist/assets/{connection-sign-in-Cngd_QDO.js → connection-sign-in-UJ6xk-TD.js} +1 -1
  64. package/apps/web/dist/assets/{eye-BpoKpIdt.js → eye-CgkvVlba.js} +1 -1
  65. package/apps/web/dist/assets/{host-C0WQlRKB.js → host-Bd_bon_c.js} +7 -7
  66. package/apps/web/dist/assets/{i18n-BJ7Ld6O6.js → i18n-0fUKyVRE.js} +1 -1
  67. package/apps/web/dist/assets/{index-ClVtdDUZ.js → index-DOgwxnto.js} +3 -3
  68. package/apps/web/dist/assets/{phone-Ctvf-Am-.js → phone-CjPvZ0nk.js} +1 -1
  69. package/apps/web/dist/assets/{read-aloud-Da_RSm2S.js → read-aloud-CLXo_asN.js} +1 -1
  70. package/apps/web/dist/assets/{runners-CyIvJIHr.js → runners-BoPaPsjN.js} +1 -1
  71. package/apps/web/dist/assets/{scroll-text-ChrjRu9Y.js → scroll-text-2BhJO_W7.js} +1 -1
  72. package/apps/web/dist/assets/{session-SXPtTWRK.js → session-CpYa5hwd.js} +1 -1
  73. package/apps/web/dist/assets/{theme-BCau3f6O.js → theme-Bj3wNQR0.js} +1 -1
  74. package/apps/web/dist/assets/{ui-Uqnx1UpK.js → ui-CktezodE.js} +1 -1
  75. package/apps/web/dist/assets/{upload-BchUnQGV.js → upload-CHGCFVZK.js} +1 -1
  76. package/apps/web/dist/assets/{useMutation-DEkZhp5c.js → useMutation-7_FOHoEl.js} +1 -1
  77. package/apps/web/dist/assets/{volume-2-CU_oy81Z.js → volume-2-Bw5KASy8.js} +1 -1
  78. package/apps/web/dist/index.html +13 -13
  79. package/apps/web/dist/mcp/flow.html +1 -1
  80. package/node_modules/@engenty/wizards-shared/dist/run.d.ts +3 -0
  81. package/node_modules/@engenty/wizards-shared/dist/run.js +6 -0
  82. package/node_modules/@engenty/wizards-shared/dist/rwx.d.ts +1 -1
  83. package/node_modules/@engenty/wizards-shared/dist/rwx.js +3 -0
  84. package/package.json +1 -1
  85. package/plugin/.claude-plugin/plugin.json +1 -1
  86. package/plugin/README.md +3 -0
  87. package/plugin/plugin.json +1 -1
  88. package/plugin/skills/work-in-space/SKILL.md +16 -0
  89. package/apps/web/dist/assets/changelog-BhMZS-rs.js +0 -1
@@ -8,6 +8,9 @@ import { nanoid } from "nanoid";
8
8
  import { z } from "zod";
9
9
  import { knowsTools } from "../assistant/knows.js";
10
10
  import { subjectsOfGoose } from "../broker/rwx.js";
11
+ import { gooseCaller } from "../elements/caller.js";
12
+ import { elementTools } from "../elements/catalogue.js";
13
+ import { brokered } from "../elements/gate.js";
11
14
  import { currentFeatures } from "../features.js";
12
15
  import { managed } from "../manage.js";
13
16
  import { chatModel, contextWindowOf, costOf, currentTier, gatewayTools, searchAllowed, textModel, totalUsage, usageOf, } from "../models.js";
@@ -23,7 +26,6 @@ import { currentTenant } from "../tenants/tenant.js";
23
26
  import { serverText } from "../texts.js";
24
27
  import { assistantPageOf, assistantToolsOf } from "../tools/plugin.js";
25
28
  import { attempt as attemptTool, imageOutput } from "../tools/shared.js";
26
- import { skillToolsOf } from "../tools/skills.js";
27
29
  import { gooseConnectionTools } from "./goose-connections.js";
28
30
  import { spaceAgent } from "./space-agent.js";
29
31
  import { chatTurnWay } from "./subscription.js";
@@ -601,8 +603,41 @@ export function gooseSpaceTools(input, space, wrote, on) {
601
603
  if (!on.typography) {
602
604
  delete tools.set_typography;
603
605
  }
606
+ // Every write to the space's setup is the broker's: `w` on it, for Goose for its person
607
+ // (docs/plans/modular.md, B4). An admin's deny for Goose stops it; each write is a log line.
608
+ const caller = gooseCaller({
609
+ space: { id: spaceId, name: space.name },
610
+ userId,
611
+ role: input.user.role,
612
+ signal: signal ?? new AbortController().signal,
613
+ chatId: input.chat?.id,
614
+ });
615
+ for (const name of SETUP_WRITES) {
616
+ if (tools[name]) {
617
+ tools[name] = brokered(tools[name], caller, (args) => ({
618
+ action: name,
619
+ resource: { kind: "setup", id: spaceId },
620
+ perm: "w",
621
+ input: args,
622
+ }));
623
+ }
624
+ }
604
625
  return tools;
605
626
  }
627
+ /** Goose's tools that write the space's setup: its profile, facts, brand, rules and files. */
628
+ const SETUP_WRITES = [
629
+ "set_profile",
630
+ "set_facts",
631
+ "remove_facts",
632
+ "set_colors",
633
+ "set_logo_sections",
634
+ "set_asset_sections",
635
+ "set_typography",
636
+ "set_gradients",
637
+ "set_rules",
638
+ "save_file",
639
+ "describe_file",
640
+ ];
606
641
  /** A browser tool as the model calls it: sent to the page, its answer awaited. */
607
642
  function browserTool(input, spec) {
608
643
  let inputSchema;
@@ -779,8 +814,20 @@ export async function runStudioAssistant(input) {
779
814
  // The space's skills (docs/plans/skills.md): Goose reads them as a step does.
780
815
  const skills = space && switches.skills === true ? await activeSkills(space.id) : null;
781
816
  const allSkills = space && switches.skills === true ? await skillList(space.id) : [];
782
- if (skills) {
783
- Object.assign(tools, skillToolsOf(skills, (name) => input.onActivity?.(serverText(input.lang, "doingReadSkill", { name }))));
817
+ // The space's Knowledge and skills from the tool catalogue (elements/), as Goose for its person.
818
+ if (space) {
819
+ Object.assign(tools, await elementTools(gooseCaller({
820
+ space: { id: space.id, name: space.name },
821
+ userId: input.user.id,
822
+ role: input.user.role,
823
+ signal: input.signal ?? new AbortController().signal,
824
+ chatId: input.chat.id,
825
+ note: (note) => {
826
+ if (note.code === "readsSkill") {
827
+ input.onActivity?.(serverText(input.lang, "doingReadSkill", { name: String(note.params?.name ?? "") }));
828
+ }
829
+ },
830
+ }), { knowledge: true, skills }));
784
831
  }
785
832
  for (const spec of input.browserTools) {
786
833
  // The confirm card is the runtime's to show, never the model's to call.
@@ -29,6 +29,7 @@ import { brokerRoutes } from "./routes/broker.js";
29
29
  import { connectionRoutes } from "./routes/connections.js";
30
30
  import { browserReport, localDebugRoutes } from "./routes/debug.js";
31
31
  import { discoverRoutes } from "./routes/discover.js";
32
+ import { elementRoutes } from "./routes/elements.js";
32
33
  import { internalRoutes } from "./routes/internal.js";
33
34
  import { notFoundAnswer, requestLang, say, spelledFor } from "./routes/lang.js";
34
35
  import { liveRoutes } from "./routes/live.js";
@@ -188,7 +189,7 @@ app.get("/api/config", (c) => c.json({
188
189
  /** The run page asks for feedback at the end and sends bug reports: they reach the Manage-App. */
189
190
  reports: managed,
190
191
  }));
191
- if (serves.studio) {
192
+ if (serves.api) {
192
193
  // OAuth discovery for MCP clients (RFC 9728): the Manage-App is the authorization server.
193
194
  app.get("/.well-known/oauth-protected-resource/*", async (c) => {
194
195
  if (!managed) {
@@ -202,6 +203,8 @@ if (serves.studio) {
202
203
  bearer_methods_supported: ["header"],
203
204
  });
204
205
  });
206
+ }
207
+ if (serves.studio) {
205
208
  // OpenAI's plugin portal checks that the submitter controls the MCP server's host.
206
209
  app.get("/.well-known/openai-apps-challenge", (c) => env.openaiAppsChallenge ? c.text(env.openaiAppsChallenge) : c.notFound());
207
210
  }
@@ -291,8 +294,13 @@ if (serves.studio) {
291
294
  });
292
295
  // A member reaches a space's studio only where its admins opened it (behind `capabilities`).
293
296
  app.use("/api/studio/*", membersStudioGate);
297
+ }
298
+ if (serves.api) {
299
+ // Outside clients: MCP and the API (docs/plans/modular.md), the space's elements among them.
294
300
  const mcp = mcpHandler();
295
301
  app.on(["GET", "POST", "DELETE"], "/api/mcp", (c) => mcp(c.req.raw));
302
+ app.route("/api/v1", elementRoutes);
303
+ app.route("/api/v1", apiRoutes);
296
304
  }
297
305
  if (serves.runner) {
298
306
  // The tools of one model call, for the installed Claude Code while it answers that call: the
@@ -327,7 +335,6 @@ if (serves.studio) {
327
335
  app.route("/api/studio/runtime", runtimeSettingsRoutes);
328
336
  app.route("/api/studio/work", workRoutes);
329
337
  app.route("/api/studio", studio);
330
- app.route("/api/v1", apiRoutes);
331
338
  app.route("/api/local/debug", localDebugRoutes);
332
339
  }
333
340
  app.route("/api/internal", internalRoutes);
@@ -220,6 +220,7 @@ export async function brokerCall(call) {
220
220
  whoId: who.id ?? null,
221
221
  runId: where.runId ?? null,
222
222
  stepId: where.stepId ?? null,
223
+ client: where.client ?? null,
223
224
  chatId: where.chatId ?? null,
224
225
  wizardId: where.wizardId ?? null,
225
226
  spaceId: where.spaceId ?? null,
@@ -375,6 +376,7 @@ export async function brokerSecret(call) {
375
376
  whoId: call.who.id ?? null,
376
377
  runId: call.where.runId ?? null,
377
378
  stepId: call.where.stepId ?? null,
379
+ client: call.where.client ?? null,
378
380
  chatId: call.where.chatId ?? null,
379
381
  wizardId: call.where.wizardId ?? null,
380
382
  spaceId: call.where.spaceId ?? null,
@@ -12,6 +12,7 @@ export async function brokerHost(call) {
12
12
  whoId: who.id ?? null,
13
13
  runId: where.runId ?? null,
14
14
  stepId: where.stepId ?? null,
15
+ client: where.client ?? null,
15
16
  chatId: where.chatId ?? null,
16
17
  wizardId: where.wizardId ?? null,
17
18
  spaceId: where.spaceId ?? null,
@@ -11,8 +11,19 @@ import { notFound, ServiceError } from "../services/errors.js";
11
11
  import { ownedSpace } from "../services/spaces.js";
12
12
  import { currentTenant } from "../tenants/tenant.js";
13
13
  import { logRuleChange } from "./log.js";
14
- /** The resource kinds this runtime asks the broker about today; the others wait for their reader. */
15
- export const ENFORCED = ["document", "table", "page"];
14
+ /**
15
+ * The resource kinds this runtime asks the broker about today; the others wait for their reader.
16
+ * A wizard is run (`x`) and listed (`r`) through the tool catalogue (elements/), a skill read
17
+ * (`r`) and its scripts placed to run (`x`), a space's setup written (`w`) by Goose.
18
+ */
19
+ export const ENFORCED = [
20
+ "document",
21
+ "table",
22
+ "page",
23
+ "wizard",
24
+ "skill",
25
+ "setup",
26
+ ];
16
27
  export async function brokerOn() {
17
28
  return featureOn(await currentFeatures(), "broker");
18
29
  }
@@ -174,6 +185,9 @@ const WHAT = {
174
185
  mail: "rwxMail",
175
186
  host: "rwxHost",
176
187
  sandbox: "rwxSandbox",
188
+ wizard: "rwxWizard",
189
+ skill: "rwxSkill",
190
+ setup: "rwxSetup",
177
191
  };
178
192
  const VERB = { r: "rwxRead", w: "rwxWrite", x: "rwxRun" };
179
193
  /** The refusal: *verboten*, the resource's kind and id, nothing of its content. */
@@ -245,14 +259,34 @@ export async function seedRwx(spaceId) {
245
259
  for (const role of ["admin", "owner"]) {
246
260
  seeded.push(rule("role", role, kind, { r: "allow", w: "allow", x: "allow" }));
247
261
  }
248
- seeded.push(rule("role", "member", kind, { r: "allow", w: "allow", x: null }));
249
- seeded.push(rule("guest", null, kind, { r: "allow", w: null, x: null }));
262
+ seeded.push(rule("role", "member", kind, MEMBER_SEED[kind] ?? MEMBER_DATA));
263
+ const guest = GUEST_SEED[kind];
264
+ if (guest) {
265
+ seeded.push(rule("guest", null, kind, guest));
266
+ }
250
267
  }
251
268
  await db
252
269
  .insert(schema.rwxRule)
253
270
  .values(seeded.map((r) => row(spaceId, r, "seed")))
254
271
  .onConflictDoNothing();
255
272
  }
273
+ /**
274
+ * A member's seed: documents, tables and pages read and written; a wizard read and run (building
275
+ * it is the studio's, by the members' studio rule); a skill read and its scripts run; the space's
276
+ * setup read and written. The same as the migration 0040 writes for spaces seeded before.
277
+ */
278
+ const MEMBER_DATA = { r: "allow", w: "allow", x: null };
279
+ const MEMBER_SEED = {
280
+ wizard: { r: "allow", w: null, x: "allow" },
281
+ skill: { r: "allow", w: null, x: "allow" },
282
+ };
283
+ /** A guest's seed: data read, a skill read and run in its run; no wizard, no setup. */
284
+ const GUEST_SEED = {
285
+ document: { r: "allow", w: null, x: null },
286
+ table: { r: "allow", w: null, x: null },
287
+ page: { r: "allow", w: null, x: null },
288
+ skill: { r: "allow", w: null, x: "allow" },
289
+ };
256
290
  const rule = (subjectKind, subjectId, resourceKind, flags) => ({ subjectKind, subjectId, resourceKind, resourceId: RWX_ALL, ...flags });
257
291
  const row = (spaceId, r, createdBy) => ({
258
292
  id: nanoid(12),
@@ -107,10 +107,21 @@ const opening = new Map();
107
107
  export function openingTenants() {
108
108
  return [...opening].map(([id, since]) => ({ id, since }));
109
109
  }
110
+ /** Tenant databases whose last opening failed, with when and why; one that opens is forgotten. */
111
+ const failed = new Map();
112
+ export function failingTenants() {
113
+ return [...failed].map(([id, f]) => ({ id, ...f }));
114
+ }
110
115
  async function openTenant(id) {
111
116
  opening.set(id, Date.now());
112
117
  try {
113
- return await openTenantNow(id);
118
+ const db = await openTenantNow(id);
119
+ failed.delete(id);
120
+ return db;
121
+ }
122
+ catch (err) {
123
+ failed.set(id, { at: Date.now(), error: String(err?.message ?? err).slice(0, 300) });
124
+ throw err;
114
125
  }
115
126
  finally {
116
127
  opening.delete(id);
@@ -0,0 +1,21 @@
1
+ -- The broker decides wizards, skills and a space's setup too (docs/plans/modular.md, phase 1).
2
+ -- A space that has its rules already gets the seed for the new kinds, once; a space without
3
+ -- rules is seeded whole on its first decision (broker/rwx.ts `seedRwx`).
4
+ INSERT OR IGNORE INTO `rwx_rule` (`id`, `tenant_id`, `space_id`, `subject_kind`, `subject_id`, `resource_kind`, `resource_id`, `r`, `w`, `x`, `created_by`)
5
+ SELECT lower(hex(randomblob(6))), s.`tenant_id`, s.`space_id`, v.subject_kind, v.subject_id, v.resource_kind, '*', v.r, v.w, v.x, 'seed'
6
+ FROM (SELECT `space_id`, min(`tenant_id`) AS `tenant_id` FROM `rwx_rule` GROUP BY `space_id`) AS s
7
+ CROSS JOIN (
8
+ SELECT 'role' AS subject_kind, 'admin' AS subject_id, 'wizard' AS resource_kind, 'allow' AS r, 'allow' AS w, 'allow' AS x
9
+ UNION ALL SELECT 'role', 'owner', 'wizard', 'allow', 'allow', 'allow'
10
+ UNION ALL SELECT 'role', 'member', 'wizard', 'allow', NULL, 'allow'
11
+ UNION ALL SELECT 'role', 'admin', 'skill', 'allow', 'allow', 'allow'
12
+ UNION ALL SELECT 'role', 'owner', 'skill', 'allow', 'allow', 'allow'
13
+ UNION ALL SELECT 'role', 'member', 'skill', 'allow', NULL, 'allow'
14
+ UNION ALL SELECT 'guest', NULL, 'skill', 'allow', NULL, 'allow'
15
+ UNION ALL SELECT 'role', 'admin', 'setup', 'allow', 'allow', 'allow'
16
+ UNION ALL SELECT 'role', 'owner', 'setup', 'allow', 'allow', 'allow'
17
+ UNION ALL SELECT 'role', 'member', 'setup', 'allow', 'allow', NULL
18
+ ) AS v
19
+ WHERE NOT EXISTS (
20
+ SELECT 1 FROM `rwx_rule` AS e WHERE e.`space_id` = s.`space_id` AND e.`resource_kind` = v.resource_kind
21
+ );
@@ -0,0 +1 @@
1
+ ALTER TABLE `broker_log` ADD `client` text;