@engenty/wizards-runtime 0.19.0 → 0.20.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 (166) hide show
  1. package/apps/runtime/dist/agents/architect.js +4 -4
  2. package/apps/runtime/dist/agents/studio-assistant.js +2 -31
  3. package/apps/runtime/dist/app.js +4 -4
  4. package/apps/runtime/dist/assistant/knows.js +2 -2
  5. package/apps/runtime/dist/auth/index.js +1 -1
  6. package/apps/runtime/dist/authoring/example.js +1 -1
  7. package/apps/runtime/dist/authoring/guide.js +35 -6
  8. package/apps/runtime/dist/broker/account.js +85 -16
  9. package/apps/runtime/dist/broker/call.js +137 -37
  10. package/apps/runtime/dist/broker/log.js +19 -5
  11. package/apps/runtime/dist/broker/rwx.js +12 -9
  12. package/apps/runtime/dist/connectors/index.js +52 -11
  13. package/apps/runtime/dist/connectors/person-connections.js +279 -0
  14. package/apps/runtime/dist/connectors/person-sign-ins.js +74 -3
  15. package/apps/runtime/dist/connectors/same-service.js +14 -0
  16. package/apps/runtime/dist/connectors/space-choice.js +116 -0
  17. package/apps/runtime/dist/connectors/space-connections.js +40 -2
  18. package/apps/runtime/dist/db/client.js +8 -0
  19. package/apps/runtime/dist/db/kept-accounts.js +88 -0
  20. package/apps/runtime/dist/db/migrations/tenant/0075_person_connection.sql +25 -0
  21. package/apps/runtime/dist/db/migrations/tenant/0076_clients_in_spaces.sql +28 -0
  22. package/apps/runtime/dist/db/migrations/tenant/0077_client_spaces_at_root.sql +21 -0
  23. package/apps/runtime/dist/db/migrations/tenant/meta/0075_snapshot.json +7859 -0
  24. package/apps/runtime/dist/db/migrations/tenant/meta/0076_snapshot.json +7859 -0
  25. package/apps/runtime/dist/db/migrations/tenant/meta/0077_snapshot.json +7859 -0
  26. package/apps/runtime/dist/db/migrations/tenant/meta/_journal.json +21 -0
  27. package/apps/runtime/dist/db/schema.js +67 -16
  28. package/apps/runtime/dist/docs/dev/api.md +8 -8
  29. package/apps/runtime/dist/docs/dev/wizard-format/index.md +3 -1
  30. package/apps/runtime/dist/elements/caller.js +1 -1
  31. package/apps/runtime/dist/elements/knowledge.js +5 -5
  32. package/apps/runtime/dist/elements/wizards.js +7 -11
  33. package/apps/runtime/dist/engine/notices.js +13 -1
  34. package/apps/runtime/dist/engine/requirements.js +116 -3
  35. package/apps/runtime/dist/engine/run-needs.js +58 -0
  36. package/apps/runtime/dist/engine/runner.js +229 -23
  37. package/apps/runtime/dist/engine/starts.js +9 -0
  38. package/apps/runtime/dist/engine/types.js +5 -1
  39. package/apps/runtime/dist/harness/claude.js +3 -1
  40. package/apps/runtime/dist/manage.js +1 -1
  41. package/apps/runtime/dist/mcp/tools.js +3 -3
  42. package/apps/runtime/dist/plugins/runs.js +2 -1
  43. package/apps/runtime/dist/prompts/architect.md +3 -3
  44. package/apps/runtime/dist/prompts/authoring.md +17 -6
  45. package/apps/runtime/dist/prompts/goose.md +0 -5
  46. package/apps/runtime/dist/routes/api.js +9 -4
  47. package/apps/runtime/dist/routes/client-contract.js +2 -2
  48. package/apps/runtime/dist/routes/client-spaces.js +1 -16
  49. package/apps/runtime/dist/routes/connections.js +6 -1
  50. package/apps/runtime/dist/routes/marketplace.js +27 -7
  51. package/apps/runtime/dist/routes/plugins.js +1 -1
  52. package/apps/runtime/dist/routes/runs.js +157 -11
  53. package/apps/runtime/dist/routes/studio.js +42 -5
  54. package/apps/runtime/dist/services/client-portal.js +58 -49
  55. package/apps/runtime/dist/services/client-spaces.js +57 -125
  56. package/apps/runtime/dist/services/links.js +3 -3
  57. package/apps/runtime/dist/services/marketplace.js +6 -2
  58. package/apps/runtime/dist/services/members-studio.js +1 -1
  59. package/apps/runtime/dist/services/query-vectors.js +1 -1
  60. package/apps/runtime/dist/services/runs.js +19 -20
  61. package/apps/runtime/dist/services/space-parent.js +4 -11
  62. package/apps/runtime/dist/services/spaces.js +56 -47
  63. package/apps/runtime/dist/services/work-ai.js +3 -3
  64. package/apps/runtime/dist/services/work-chats.js +14 -6
  65. package/apps/runtime/dist/sharing/state.js +7 -3
  66. package/apps/runtime/dist/store/index.js +28 -8
  67. package/apps/runtime/dist/store/shared-lists.js +2 -2
  68. package/apps/runtime/dist/sync/hub.js +9 -5
  69. package/apps/runtime/dist/tools/connector.js +4 -2
  70. package/apps/web/dist/assets/{AboutDialog-BxT7chz8.js → AboutDialog-QWzpEK8M.js} +1 -1
  71. package/apps/web/dist/assets/{BlockEditor-BX8ZxxIc.js → BlockEditor-C44bI_ih.js} +1 -1
  72. package/apps/web/dist/assets/{Bundle-Dkpi5E6W.js → Bundle-DZyQ1FP7.js} +1 -1
  73. package/apps/web/dist/assets/CapabilitiesPage-DAr0-gN1.js +2 -0
  74. package/apps/web/dist/assets/{ChangelogDialog-j-vHLy-V.js → ChangelogDialog-CdHqJV2P.js} +1 -1
  75. package/apps/web/dist/assets/{CodeEditor-CfM2A-yS.js → CodeEditor-BRufUwu0.js} +1 -1
  76. package/apps/web/dist/assets/ConnectorsSection-BO6jHrYU.js +1 -0
  77. package/apps/web/dist/assets/EditorPage-Bx-fKnsY.js +3 -0
  78. package/apps/web/dist/assets/{FlowPreview-E0kuvM5n.js → FlowPreview-aj58c-gH.js} +1 -1
  79. package/apps/web/dist/assets/{LangSwitch-DhQmCtyY.js → LangSwitch-BNkytlus.js} +1 -1
  80. package/apps/web/dist/assets/Marketplace-D3hdvrkz.js +2 -0
  81. package/apps/web/dist/assets/NewWizardChannels-fveQcQlY.js +1 -0
  82. package/apps/web/dist/assets/NewWizardPage-BTX1g2t1.js +7 -0
  83. package/apps/web/dist/assets/OnboardingPage-DwF6KdQy.js +1 -0
  84. package/apps/web/dist/assets/ProtocolSection-YnJcMN9E.js +1 -0
  85. package/apps/web/dist/assets/PublicRunner-Bp4DxTrD.js +1 -0
  86. package/apps/web/dist/assets/{ReadOnly-CkToYpY5.js → ReadOnly-C6qmTD35.js} +1 -1
  87. package/apps/web/dist/assets/{Results-C9qxCpUQ.js → Results-BNuuBiwU.js} +1 -1
  88. package/apps/web/dist/assets/{RunDrawer-BRXH71U8.js → RunDrawer-CMgN-XTB.js} +1 -1
  89. package/apps/web/dist/assets/SettingsPage-CuUB26YJ.js +2 -0
  90. package/apps/web/dist/assets/SetupPage-llGzMVeH.js +1 -0
  91. package/apps/web/dist/assets/{SharePage-Boj1R928.js → SharePage-CgQp_PT6.js} +1 -1
  92. package/apps/web/dist/assets/SkillEditor-ARx8QPGp.js +1 -0
  93. package/apps/web/dist/assets/Skills-frfXXEcF.js +9 -0
  94. package/apps/web/dist/assets/SpacePage-Dv6ocsc_.js +2 -0
  95. package/apps/web/dist/assets/StudioHome-B0bZRm1L.js +1 -0
  96. package/apps/web/dist/assets/TableEditor-CfzTLmJF.js +7 -0
  97. package/apps/web/dist/assets/{UpdateCheck-DFor0F9T.js → UpdateCheck-D3QhfI5c.js} +2 -2
  98. package/apps/web/dist/assets/{brand-Ij-I_Lms.js → brand-DKuVyYhH.js} +1 -1
  99. package/apps/web/dist/assets/changelog-Db3nvWao.js +1 -0
  100. package/apps/web/dist/assets/{code-editor-BVgSljQq.js → code-editor-BLwDuQLI.js} +2 -2
  101. package/apps/web/dist/assets/host-C-AAp8Bz.js +69 -0
  102. package/apps/web/dist/assets/i18n-Dyi0kvaA.js +55 -0
  103. package/apps/web/dist/assets/index-CduFlFCp.css +1 -0
  104. package/apps/web/dist/assets/index-CtE0rJEL.js +102 -0
  105. package/apps/web/dist/assets/{read-aloud-pd-PWi_5.js → read-aloud-DGS8mWgC.js} +1 -1
  106. package/apps/web/dist/assets/session-EIDP3Wzc.js +1 -0
  107. package/apps/web/dist/assets/theme-B46aPLtX.js +14 -0
  108. package/apps/web/dist/assets/ui-DSgksc1H.js +16 -0
  109. package/apps/web/dist/assets/{useMutation-CUZC19i3.js → useMutation-fT44ij_b.js} +1 -1
  110. package/apps/web/dist/assets/{viewers-D-8HZrcq.js → viewers-DvA5VsXw.js} +2 -2
  111. package/apps/web/dist/index.html +18 -13
  112. package/apps/web/dist/mcp/flow.html +62 -62
  113. package/node_modules/@engenty/wizards-shared/dist/catalog-prompt.js +2 -2
  114. package/node_modules/@engenty/wizards-shared/dist/connectors.d.ts +67 -0
  115. package/node_modules/@engenty/wizards-shared/dist/definition.d.ts +10324 -7
  116. package/node_modules/@engenty/wizards-shared/dist/definition.js +32 -6
  117. package/node_modules/@engenty/wizards-shared/dist/feature-flags.d.ts +17 -23
  118. package/node_modules/@engenty/wizards-shared/dist/feature-flags.js +17 -23
  119. package/node_modules/@engenty/wizards-shared/dist/json-schema.js +3 -3
  120. package/node_modules/@engenty/wizards-shared/dist/marketplace-search.js +7 -1
  121. package/node_modules/@engenty/wizards-shared/dist/marketplace.d.ts +9 -2
  122. package/node_modules/@engenty/wizards-shared/dist/page-data.d.ts +72 -0
  123. package/node_modules/@engenty/wizards-shared/dist/page-data.js +5 -0
  124. package/node_modules/@engenty/wizards-shared/dist/page-look.d.ts +17 -0
  125. package/node_modules/@engenty/wizards-shared/dist/page-look.js +118 -0
  126. package/node_modules/@engenty/wizards-shared/dist/page-styles.d.ts +6 -0
  127. package/node_modules/@engenty/wizards-shared/dist/page-styles.js +98 -0
  128. package/node_modules/@engenty/wizards-shared/dist/page-texts.d.ts +36 -0
  129. package/node_modules/@engenty/wizards-shared/dist/page-texts.js +119 -0
  130. package/node_modules/@engenty/wizards-shared/dist/requires.js +2 -0
  131. package/node_modules/@engenty/wizards-shared/dist/run.d.ts +56 -1
  132. package/node_modules/@engenty/wizards-shared/dist/run.js +25 -0
  133. package/node_modules/@engenty/wizards-shared/dist/runner-texts.d.ts +27 -1
  134. package/node_modules/@engenty/wizards-shared/dist/runner-texts.js +26 -0
  135. package/node_modules/@engenty/wizards-shared/dist/store.d.ts +24 -1
  136. package/node_modules/@engenty/wizards-shared/dist/transition.d.ts +2 -1
  137. package/node_modules/@engenty/wizards-shared/dist/transition.js +10 -2
  138. package/node_modules/@engenty/wizards-shared/dist/wizard-text.js +1 -1
  139. package/package.json +1 -1
  140. package/plugin/.claude-plugin/plugin.json +1 -1
  141. package/plugin/plugin.json +1 -1
  142. package/apps/web/dist/assets/CapabilitiesPage-CfSb23wy.js +0 -2
  143. package/apps/web/dist/assets/ConnectorsSection-fRBZYfZu.js +0 -1
  144. package/apps/web/dist/assets/EditorPage-CrFyN_Qn.js +0 -3
  145. package/apps/web/dist/assets/Marketplace-BdkNOARm.js +0 -2
  146. package/apps/web/dist/assets/NewWizardChannels-BATgI9GR.js +0 -1
  147. package/apps/web/dist/assets/NewWizardPage-B5V5ScKh.js +0 -7
  148. package/apps/web/dist/assets/OnboardingPage-DWpDqlCi.js +0 -1
  149. package/apps/web/dist/assets/PreviewPane-Br2w92Wh.js +0 -7
  150. package/apps/web/dist/assets/ProtocolSection-DMCojdZu.js +0 -1
  151. package/apps/web/dist/assets/PublicRunner-Cjhfeqi3.js +0 -1
  152. package/apps/web/dist/assets/SettingsPage-Dobd7tAA.js +0 -2
  153. package/apps/web/dist/assets/SetupPage-BkMjwBlV.js +0 -1
  154. package/apps/web/dist/assets/SkillEditor-DtVRUYqS.js +0 -1
  155. package/apps/web/dist/assets/Skills-DK1Pv-Xh.js +0 -9
  156. package/apps/web/dist/assets/SpacePage-CjgBRkkw.js +0 -2
  157. package/apps/web/dist/assets/StudioHome-B5HcJJ4Q.js +0 -1
  158. package/apps/web/dist/assets/changelog-n9RARUzp.js +0 -1
  159. package/apps/web/dist/assets/host-BELYIPMT.js +0 -69
  160. package/apps/web/dist/assets/i18n-DPqdH1PJ.js +0 -55
  161. package/apps/web/dist/assets/index-CVZlO0z3.css +0 -1
  162. package/apps/web/dist/assets/index-wJZVaKLg.js +0 -10
  163. package/apps/web/dist/assets/runners-D9DHhaD9.js +0 -1
  164. package/apps/web/dist/assets/session-Mt-n8MI0.js +0 -1
  165. package/apps/web/dist/assets/theme-BQhQx_UL.js +0 -14
  166. package/apps/web/dist/assets/ui-D4qQLcbs.js +0 -16
@@ -526,6 +526,27 @@
526
526
  "when": 1794263818602,
527
527
  "tag": "0074_store_database",
528
528
  "breakpoints": true
529
+ },
530
+ {
531
+ "idx": 75,
532
+ "version": "6",
533
+ "when": 1794650059999,
534
+ "tag": "0075_person_connection",
535
+ "breakpoints": true
536
+ },
537
+ {
538
+ "idx": 76,
539
+ "version": "6",
540
+ "when": 1794661909758,
541
+ "tag": "0076_clients_in_spaces",
542
+ "breakpoints": true
543
+ },
544
+ {
545
+ "idx": 77,
546
+ "version": "6",
547
+ "when": 1794664300321,
548
+ "tag": "0077_client_spaces_at_root",
549
+ "breakpoints": true
529
550
  }
530
551
  ]
531
552
  }
@@ -1,5 +1,6 @@
1
1
  import { BUNDLE_FORMATS, } from "@engenty/wizards-shared/bundles";
2
2
  import { CONNECTION_AUDIENCES, CONNECTION_SIGN_INS, MAILBOX_ERRORS, } from "@engenty/wizards-shared/connectors";
3
+ import { inCurrentFormat } from "@engenty/wizards-shared/definition";
3
4
  import { withRequires } from "@engenty/wizards-shared/requires";
4
5
  import { RUN_EVENT_TYPES, } from "@engenty/wizards-shared/run";
5
6
  import { RWX_FLAGS, RWX_RESOURCE_KINDS, RWX_SUBJECT_KINDS } from "@engenty/wizards-shared/rwx";
@@ -16,7 +17,8 @@ const updatedAt = () => integer("updated_at", { mode: "timestamp_ms" }).notNull(
16
17
  const definitionColumn = customType({
17
18
  dataType: () => "text",
18
19
  toDriver: (value) => JSON.stringify(filledIn(value)),
19
- fromDriver: (value) => JSON.parse(value),
20
+ // A definition kept before its version was written as today reads as today's.
21
+ fromDriver: (value) => inCurrentFormat(JSON.parse(value)),
20
22
  });
21
23
  function filledIn(def) {
22
24
  try {
@@ -73,15 +75,18 @@ export const space = sqliteTable("space", {
73
75
  origin: text("origin", { enum: ["local"] }),
74
76
  syncedAt: integer("synced_at", { mode: "timestamp_ms" }),
75
77
  /**
76
- * `client`: a client space under `parentId` (docs/plans/client-spaces.md): one client's data,
77
- * results and chats, reading the parent's setup. `space`: a space of the organization.
78
- * `personal`: one person's own space, Mein Space (docs/plans/org-spaces.md): its one member
79
- * is that person, nobody else sees it.
78
+ * `space`: a team space of the organization, for its members only. `client`: a client space
79
+ * (docs/plans/org-spaces.md), one per client of the firm, beside the team spaces under the
80
+ * root: the client's people are in it (`space_member`, role `client`) and see it alone.
81
+ * `personal`: one person's own space, Mein Space: its one member is that person.
80
82
  */
81
83
  kind: text("kind", { enum: ["space", "client", "personal"] })
82
84
  .notNull()
83
85
  .default("space"),
84
- /** The space a client space belongs to; null for a space. Two levels, never more. */
86
+ /**
87
+ * The organization's own space, the root, for every other space; null for the root and for a
88
+ * space a local install synced. Two levels, never more.
89
+ */
85
90
  parentId: text("parent_id").references(() => space.id, {
86
91
  onDelete: "cascade",
87
92
  }),
@@ -89,10 +94,9 @@ export const space = sqliteTable("space", {
89
94
  updatedAt: updatedAt(),
90
95
  }, (t) => [index("space_tenant").on(t.tenantId), index("space_parent").on(t.parentId)]);
91
96
  /**
92
- * Who of the organization is in a client space (docs/plans/client-spaces.md): `client`, the
93
- * client's own people, who see only the client spaces they are in; `member`, the firm's people
94
- * assigned to it. The firm's members see every client space of their space all the same until a
95
- * space turns "assigned only" on.
97
+ * Who is in a space (docs/plans/org-spaces.md): `client`, one of a client's people, in their
98
+ * client space and seeing it alone; `member`, the organization's people chosen for a space shared
99
+ * with its members only (`space.access`), and the one person of a Mein Space.
96
100
  */
97
101
  export const spaceMember = sqliteTable("space_member", {
98
102
  id: text("id").primaryKey(),
@@ -287,9 +291,9 @@ export const run = sqliteTable("run", {
287
291
  deviceOffer: text("device_offer", { mode: "json" }).$type(),
288
292
  costMicros: integer("cost_micros").notNull().default(0),
289
293
  /**
290
- * The client space a run was started in (docs/plans/client-portal.md): the wizard is its
291
- * parent's, the run's data and results belong to the client space. Null: a run of its
292
- * wizard's space.
294
+ * The space a run is in where that is not plainly its wizard's (docs/plans/org-spaces.md): a
295
+ * run of the root's wizard started in a space under it, or a client's run in their client
296
+ * space. Its data and results belong to that space. Null: a run of its wizard's space.
293
297
  */
294
298
  clientSpaceId: text("client_space_id").references(() => space.id, {
295
299
  onDelete: "cascade",
@@ -300,7 +304,7 @@ export const run = sqliteTable("run", {
300
304
  */
301
305
  chatId: text("chat_id"),
302
306
  /**
303
- * When the firm shared the run with the client space's clients, on purpose; null: it stays
307
+ * When the firm shared the run with the clients of its client space, on purpose; null: it stays
304
308
  * the firm's. A client's own runs need none.
305
309
  */
306
310
  clientSharedAt: integer("client_shared_at", { mode: "timestamp_ms" }),
@@ -1249,14 +1253,17 @@ export const storeFile = sqliteTable("store_file", {
1249
1253
  source: text("source"),
1250
1254
  updatedAt: updatedAt(),
1251
1255
  }, (t) => [primaryKey({ columns: [t.wizardId, t.holder, t.path] })]);
1252
- /** A connected account or a kept browser session. `data` is encrypted. */
1256
+ /**
1257
+ * A kept browser session. `data` is encrypted. A wizard's connected accounts were kept here
1258
+ * until they became a person's connections (`person_connection`, `db/kept-accounts.ts`).
1259
+ */
1253
1260
  export const storeSecret = sqliteTable("store_secret", {
1254
1261
  id: text("id").primaryKey(),
1255
1262
  wizardId: text("wizard_id")
1256
1263
  .notNull()
1257
1264
  .references(() => wizard.id, { onDelete: "cascade" }),
1258
1265
  holder: text("holder").notNull(),
1259
- /** "connection:<id>" or "browser:<host>". */
1266
+ /** "browser". */
1260
1267
  slot: text("slot").notNull(),
1261
1268
  provider: text("provider").notNull(),
1262
1269
  /** Shown to the person: the account's address or the site's name. */
@@ -1369,6 +1376,50 @@ export const spaceConnectionSignIn = sqliteTable("space_connection_sign_in", {
1369
1376
  signedInAt: integer("signed_in_at", { mode: "timestamp_ms" }).notNull().default(now),
1370
1377
  updatedAt: updatedAt(),
1371
1378
  }, (t) => [primaryKey({ columns: [t.connectionId, t.userId] })]);
1379
+ /**
1380
+ * A person's own connection (docs/plans/run-connections.md): an account they signed in to from
1381
+ * a run, theirs in every space they are in. A guest's belongs to the visitor and goes with the
1382
+ * visitor's stores. One row per owner and address: kind `mail` and the connector of the same
1383
+ * service share it (`connectors/same-service.ts`). `secret` is sealed;
1384
+ * the broker alone unseals it.
1385
+ */
1386
+ export const personConnection = sqliteTable("person_connection", {
1387
+ id: text("id").primaryKey(),
1388
+ /** Whose: `u:<user>`, `v:<visitor>` for a guest, `r:<run>` for a run nobody ran (`holderOf`). */
1389
+ holder: text("holder").notNull(),
1390
+ /** The connector it was signed in with: a built-in's id or a `space_connector`. */
1391
+ connectorId: text("connector_id").notNull(),
1392
+ /** The account as the provider names it, mostly the address. */
1393
+ label: text("label").notNull(),
1394
+ secret: text("secret").notNull(),
1395
+ createdAt: createdAt(),
1396
+ updatedAt: updatedAt(),
1397
+ }, (t) => [uniqueIndex("person_connection_account").on(t.holder, t.connectorId, t.label)]);
1398
+ /**
1399
+ * Which connection a wizard uses for one of its needs (a `connections` entry of its definition,
1400
+ * or a share target's `share:<id>`), remembered for one person, one visitor, or a space for the
1401
+ * runs nobody watches. Points at a person's connection or at a connection of the space, never
1402
+ * both; it goes with the connection it points at.
1403
+ */
1404
+ export const connectionChoice = sqliteTable("connection_choice", {
1405
+ wizardId: text("wizard_id")
1406
+ .notNull()
1407
+ .references(() => wizard.id, { onDelete: "cascade" }),
1408
+ /** The need's id: the connection's id in the definition. */
1409
+ need: text("need").notNull(),
1410
+ /** For whom: a run's holder (`u:`, `v:`, `r:`), or `s:<space id>` for the runs nobody watches. */
1411
+ holder: text("holder").notNull(),
1412
+ personConnectionId: text("person_connection_id").references(() => personConnection.id, {
1413
+ onDelete: "cascade",
1414
+ }),
1415
+ spaceConnectionId: text("space_connection_id").references(() => spaceConnection.id, {
1416
+ onDelete: "cascade",
1417
+ }),
1418
+ chosenAt: integer("chosen_at", { mode: "timestamp_ms" }).notNull().default(now),
1419
+ }, (t) => [
1420
+ primaryKey({ columns: [t.wizardId, t.need, t.holder] }),
1421
+ index("connection_choice_person").on(t.personConnectionId),
1422
+ ]);
1372
1423
  /**
1373
1424
  * Every call that reaches outside through the broker (`broker/call.ts`): who called, where, which
1374
1425
  * connection and action, what was decided and how it went. A secret never goes in. Rows are only
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  title: The API
3
3
  description: What a program may rely on when it talks to a runtime, and what is private.
4
- version: 0.15.0
4
+ version: 0.19.1
5
5
  ---
6
6
 
7
7
  A runtime answers HTTP under `/api`. Three parts are a contract: they are versioned, documented
@@ -40,8 +40,8 @@ person’s yes.
40
40
 
41
41
  ## A client’s client spaces
42
42
 
43
- A firm works for its clients in client spaces under its space. A client of the organization signs
44
- in with an account of their own and reaches only the client spaces they are in. The client
43
+ A firm works for each client in a client space, beside its team spaces. A client of the
44
+ organization signs in with an account of their own and reaches only the client spaces they are in. The client
45
45
  portal (`<team>.wizards.page/portal`) is built on these calls alone, so another app can offer the
46
46
  same. `GET /api/v1/client` lists them with their inputs as JSON Schema. A call is
47
47
  `POST /api/v1/client/:name`, or `POST /api/v1/client/spaces/:spaceId/:name` for one client space,
@@ -49,18 +49,18 @@ with `{ "input": { … } }`; it answers `{ "result": … }`, or an error with wh
49
49
 
50
50
  | Call | Scope | Gives |
51
51
  |---|---|---|
52
- | `me`, `spaces` | `data:read` | Who you are, your organization, your client spaces with their address (`slug`) and the firm’s brand |
52
+ | `me`, `spaces` | `data:read` | Who you are, your organization, your client spaces with the organization’s name and the brand each wears |
53
53
  | `for_you` | `data:read` | Your runs waiting on a page or an answer, the results the firm shared, the wizards you can start |
54
- | `wizards`, `wizard_start` | `elements:read`, `elements:run` | The firm’s wizards opened to clients, each with its engenty (`avatar`) and its number of steps; a start runs it in your client space |
54
+ | `wizards`, `wizard_start` | `elements:read`, `elements:run` | The client space’s wizards and those the organization opened to clients, each with its engenty (`avatar`) and its number of steps; a start runs it in your client space |
55
55
  | `results`, `run_open` | `data:read` | Your finished runs and those the firm shared; a ticket for one run’s own routes (`/api/runs/:id/…?rt=…`) |
56
56
  | `chats`, `chat_messages` | `data:read` | Your chats in the client space and their messages: each message’s `parts` in the order they were written, its text and the views and runs of the firm’s AI as cards |
57
- | `chat_post` | `elements:run` | Writes in one of your chats, or starts one. The firm’s AI answers every message as you, with the client space’s Knowledge, the wizards opened to you and views; the firm’s people read the chat too |
57
+ | `chat_post` | `elements:run` | Writes in one of your chats, or starts one. The firm’s AI answers every message as you, with the client space’s Knowledge and what the organization opened to clients, the wizards and views; the firm’s people read the chat too |
58
58
  | `files` | `data:read` | The client space’s files. One file’s bytes: `GET /api/v1/client/spaces/:spaceId/files/:fileId` |
59
59
 
60
60
  Only a person with the role `client` gets an answer (`403 clients_only` otherwise). A space that is
61
61
  not one of yours answers `404`. The firm’s Knowledge and wizards reach you only where the firm
62
- opened them to clients, and a run the firm makes in your client space only once it is shared with
63
- you. The calls need the organization’s `clientSpaces` switch.
62
+ opened them to clients, and a run the firm makes in your client space only once it is shared with you.
63
+ The calls need the organization’s `clientSpaces` and `orgSpaces` switches.
64
64
 
65
65
  ## Private
66
66
 
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  title: The wizard format
3
3
  description: A wizard as one JSON document, what its keys mean, and where each part is described.
4
- version: 0.18.0
4
+ version: 0.19.1
5
5
  ---
6
6
 
7
7
  A wizard is one JSON document, its **definition**. The studio exports it as a `.wizard` file
@@ -147,6 +147,7 @@ written by hand: the studio, the architect and the AI clients’ tools write it
147
147
  "sandbox": "shell",
148
148
  "plugins": ["appointments"],
149
149
  "connections": ["mail"],
150
+ "connectors": ["hubspot"],
150
151
  "features": ["codeSteps", "durableRuns"],
151
152
  "data": "shared",
152
153
  "optional": { "models": ["image"] }
@@ -162,6 +163,7 @@ written by hand: the studio, the architect and the AI clients’ tools write it
162
163
  | `sandbox` | `shell` when a step works in a sandbox |
163
164
  | `plugins` | The plugins whose tools a step lists or a tool step calls |
164
165
  | `connections` | The kinds of the wizard’s connections |
166
+ | `connectors` | The connectors the wizard’s connections name |
165
167
  | `features` | The switches that must be on: `durableRuns` for a wait step, `codeSteps` for a code step or a function tool |
166
168
  | `data` | The wizard’s own database, `person` or `shared`, as `data.scope` says. See [A wizard’s own data](./data.md) |
167
169
  | `optional` | Classes only steps on some branches call: a run can go around them |
@@ -3,7 +3,7 @@ import { subjectsOf, subjectsOfAgent, subjectsOfGoose } from "../broker/rwx.js";
3
3
  /** A step of a run: its holder and its wizard, in the run. */
4
4
  export function stepCaller(ctx, sandbox = null) {
5
5
  return {
6
- // The run's data: a client space's Knowledge reaches through to its parent as the rules allow.
6
+ // The run's data: a space's Knowledge reaches through to the root as the rules allow.
7
7
  space: ctx.dataSpace,
8
8
  who: whoOf(ctx.store.holder, ctx.holder.kind === "person" ? ctx.holder.role : undefined),
9
9
  subjects: subjectsOf(ctx),
@@ -22,9 +22,9 @@ import { ELEMENT_SPECS } from "./specs.js";
22
22
  */
23
23
  export { pageReadInput } from "./specs.js";
24
24
  /**
25
- * Where the caller's Knowledge is read: the space, and for a client space its parent too
26
- * (docs/plans/client-spaces.md). The rules decide each item of the parent as for any reader: a
27
- * client reads only what the parent opened to clients, the firm reads all of it.
25
+ * Where the caller's Knowledge is read: the space, and for a space under the organization's root
26
+ * the root too (docs/plans/org-spaces.md). The rules decide each item as for any reader: a client
27
+ * reads only what was opened to clients, the firm reads all of it.
28
28
  */
29
29
  async function readsFrom(spaceId) {
30
30
  const space = await db.query.space.findFirst({
@@ -46,7 +46,7 @@ async function readsFrom(spaceId) {
46
46
  ...(parent ? [{ id: parent.id, name: parent.name, own: false }] : []),
47
47
  ];
48
48
  }
49
- /** The first space that has it: the client space before its parent. A refusal stands. */
49
+ /** The first space that has it: the space before the root. A refusal stands. */
50
50
  async function firstFound(spaces, read) {
51
51
  let missing = null;
52
52
  for (const space of spaces) {
@@ -290,7 +290,7 @@ async function writableMountIds(spaceId, ids) {
290
290
  });
291
291
  return rows.map((r) => r.id);
292
292
  }
293
- /** A search over the client space and its parent, the best of both by relevance. */
293
+ /** A search over the space and the root, the best of both by relevance. */
294
294
  async function searchAll(spaces, query, opts) {
295
295
  if (spaces.length === 1) {
296
296
  return searchKnowledge(spaces[0].id, query, opts);
@@ -1,5 +1,6 @@
1
1
  import { createTool } from "@mastra/core/tools";
2
2
  import { readableIds } from "../broker/rwx.js";
3
+ import { currentRole } from "../services/access.js";
3
4
  import { runReport, startRun } from "../services/runs.js";
4
5
  import { readsOf } from "../services/space-parent.js";
5
6
  import { listWizards } from "../services/wizards.js";
@@ -21,16 +22,10 @@ export async function wizardTools(caller) {
21
22
  if (!userId) {
22
23
  return {};
23
24
  }
24
- // A client space runs the wizards of its space (docs/plans/client-spaces.md): they are listed
25
- // from there and decided by the space's rules; a run started here belongs to the client space
26
- // (docs/plans/client-portal.md). With `orgSpaces` a space under the organization's root runs its
27
- // own wizards and the root's; a run of the root's belongs to the space (docs/plans/org-spaces.md).
25
+ // With `orgSpaces` a space under the organization's root runs its own wizards and the root's;
26
+ // a run of the root's belongs to the space (docs/plans/org-spaces.md).
28
27
  const reads = await readsOf(caller.space.id);
29
- const sources = reads?.as === "client"
30
- ? [reads.parentId]
31
- : reads?.as === "root"
32
- ? [caller.space.id, reads.parentId]
33
- : [caller.space.id];
28
+ const sources = reads ? [caller.space.id, reads.parentId] : [caller.space.id];
34
29
  /** The published wizards of a source the caller may read. */
35
30
  const readable = async (spaceId) => {
36
31
  const published = (await listWizards(userId, spaceId)).filter((w) => w.published);
@@ -80,8 +75,9 @@ export async function wizardTools(caller) {
80
75
  throw new Error(`No published wizard "${input.wizardId}" in this space.`);
81
76
  }
82
77
  const { runId, refused } = await startRun(userId, input.wizardId, input.answers, {
83
- // A wizard of the parent runs with its data here.
84
- clientSpaceId: from === caller.space.id ? null : caller.space.id,
78
+ // A wizard of the root runs with its data here; a client's run is kept in
79
+ // their client space, whichever wizard it is.
80
+ clientSpaceId: from === caller.space.id && currentRole() !== "client" ? null : caller.space.id,
85
81
  // Started in a Work chat: its folder lists the result.
86
82
  chatId: caller.where.chatId ?? null,
87
83
  });
@@ -289,6 +289,17 @@ function linkOf(row, run, wizard) {
289
289
  }
290
290
  /** The row asks someone other than the run's own person: one of those who answer for the team. */
291
291
  const askedOfAnother = (row, run) => Boolean(row.userId) && row.userId !== run.userId;
292
+ /** Whether the run is a client's: they started it in their client space. */
293
+ async function clientOf(run) {
294
+ if (!(run.userId && run.clientSpaceId)) {
295
+ return false;
296
+ }
297
+ const row = await db.query.spaceMember.findFirst({
298
+ columns: { id: true },
299
+ where: and(eq(schema.spaceMember.spaceId, run.clientSpaceId), eq(schema.spaceMember.userId, run.userId), eq(schema.spaceMember.role, "client")),
300
+ });
301
+ return Boolean(row);
302
+ }
292
303
  /** A refusal is an answer (over the limit, no such person, a Manage-App without the route): the bell has to do. */
293
304
  function afterFailure(err, channel, row) {
294
305
  if (err instanceof ManageError && err.status < 500) {
@@ -301,7 +312,8 @@ function afterFailure(err, channel, row) {
301
312
  async function mailOf(row, run) {
302
313
  // A test run stays in the studio; a client's run in their portal, whose link a mail cannot know
303
314
  // yet. Whoever answers for the team is of the firm: their link goes to the run in Work.
304
- if (run.mode !== "live" || (run.clientSpaceId && !askedOfAnother(row, run))) {
315
+ if (run.mode !== "live" ||
316
+ (run.clientSpaceId && !askedOfAnother(row, run) && (await clientOf(run)))) {
305
317
  return "dealt";
306
318
  }
307
319
  const address = row.visitor ? visitorAddress(run) : null;
@@ -4,6 +4,9 @@ import { CLASS_NAMES } from "@engenty/wizards-shared/providers";
4
4
  import { optionalStepClasses, stepClasses } from "@engenty/wizards-shared/requires";
5
5
  import { note, saidText } from "@engenty/wizards-shared/run";
6
6
  import { MAKER_COMPANIES, MAKER_FAMILIES, splitClassId, } from "@engenty/wizards-shared/tiers";
7
+ import { missingSetup, usable } from "../connectors/builtin.js";
8
+ import { candidates } from "../connectors/index.js";
9
+ import { connectionsFor, runConnectionsOn } from "../connectors/person-connections.js";
7
10
  import { classProblem, currentTier, motionClient, tierRefusal } from "../models.js";
8
11
  // The steps every run passes through, and the choices that lead around a missing model, are
9
12
  // pure and shared (packages/shared/src/fit.ts): the standalone check uses the same. So are the
@@ -343,10 +346,120 @@ export async function missingModelsSaid(def) {
343
346
  }
344
347
  return missing;
345
348
  }
349
+ /** The steps that use a connection: an agent step that lists it, a tool step that calls it, a page that connects it. */
350
+ export function stepsUsing(def, id) {
351
+ return def.steps.filter((s) => (s.type === "agent" && s.connections?.includes(id)) ||
352
+ (s.type === "tool" && s.call && "connection" in s.call && s.call.connection === id) ||
353
+ (s.type === "form" && s.fields.some((f) => f.kind === "connection" && f.connection === id)));
354
+ }
355
+ /**
356
+ * The connections this wizard needs where a connector can't connect here, in a language; empty =
357
+ * every connector can. `setup`: the reader may hear what the server's owner has to set.
358
+ */
359
+ export async function missingConnections(def, spaceId, lang = "en", setup = false) {
360
+ return (await missingConnectionsSaid(def, spaceId, setup)).map((m) => ({
361
+ ...m,
362
+ problem: saidText(m.problem, lang),
363
+ }));
364
+ }
365
+ /**
366
+ * The connections this wizard needs where a connector can't connect here (`usable`): one that
367
+ * names a connector, or a kind where some of its connectors can't. A need none of whose
368
+ * connectors connects blocks the start where a step every run passes through uses it; kind
369
+ * `mail` with one connector that connects only says which ones don't. A connection of the
370
+ * space is an account the space has already. `setup`: the problem names what the server's
371
+ * owner has to set (`missingSetup`), for an admin.
372
+ */
373
+ export async function missingConnectionsSaid(def, spaceId, setup = false) {
374
+ const unavoidable = unavoidableSteps(def);
375
+ const missing = [];
376
+ for (const connection of def.connections ?? []) {
377
+ if (connection.spaceConnection) {
378
+ continue;
379
+ }
380
+ const found = await candidates(connection, spaceId);
381
+ const can = [];
382
+ const cannot = [];
383
+ for (const c of found) {
384
+ ((await usable(c)) ? can : cannot).push(c);
385
+ }
386
+ if (found.length && !cannot.length) {
387
+ continue;
388
+ }
389
+ const said = [];
390
+ if (!found.length) {
391
+ said.push(note("connectorNotInSpace", { connector: connection.connector ?? connection.id }));
392
+ }
393
+ else {
394
+ const names = cannot.map((c) => c.name);
395
+ said.push(note("connectorsCantConnect", { connectors: names, count: names.length }));
396
+ for (const c of setup ? cannot : []) {
397
+ const settings = missingSetup(c);
398
+ if (settings) {
399
+ said.push(note("connectorNeedsSettings", { connector: c.name, settings }));
400
+ }
401
+ }
402
+ if (can.length) {
403
+ const instead = can.map((c) => c.name);
404
+ said.push(note("connectorsInstead", { connectors: instead, count: instead.length }));
405
+ }
406
+ }
407
+ const steps = stepsUsing(def, connection.id);
408
+ missing.push({
409
+ id: connection.id,
410
+ name: connection.title ??
411
+ (connection.connector ? (found[0]?.name ?? connection.connector) : null),
412
+ kind: connection.kind ?? null,
413
+ connectors: found.length ? cannot.map((c) => c.id) : [connection.connector ?? connection.id],
414
+ problem: said.reduce((first, second) => note("joined", { first, second })),
415
+ steps: steps.map((s) => ({ id: s.id, title: s.title })),
416
+ blocking: !can.length && steps.some((s) => unavoidable.has(s.id)),
417
+ });
418
+ }
419
+ return missing;
420
+ }
421
+ /**
422
+ * The needs a run nobody watches (`scope.unwatched`: a start's, a channel's) has no account for: one a step every run passes
423
+ * through uses, where the space's admins chose no connection for runs nobody watches
424
+ * (`spaceHolder`). Nobody is there to connect or choose one, so such a run does not start. With
425
+ * `runConnections` off the space's connections aren't offered, and nothing is said here. A need
426
+ * no connector of the space serves is `missingConnectionsSaid`'s; one that names a connection of
427
+ * the space has its account.
428
+ */
429
+ export async function unwatchedConnectionsSaid(def, scope, spaceId) {
430
+ if (!scope.unwatched || !def.connections?.length || !(await runConnectionsOn())) {
431
+ return [];
432
+ }
433
+ const unavoidable = unavoidableSteps(def);
434
+ const missing = [];
435
+ for (const need of def.connections) {
436
+ const steps = stepsUsing(def, need.id).filter((s) => unavoidable.has(s.id));
437
+ if (need.spaceConnection || !steps.length) {
438
+ continue;
439
+ }
440
+ const connectors = await candidates(need, spaceId);
441
+ if (!connectors.length || (await connectionsFor(scope, spaceId, need)).by === "choice") {
442
+ continue;
443
+ }
444
+ const name = need.title ?? (need.connector ? connectors[0].name : null);
445
+ missing.push({
446
+ id: need.id,
447
+ name,
448
+ kind: need.kind ?? null,
449
+ connectors: connectors.map((c) => c.id),
450
+ problem: note("unwatchedNeedsChoice", {
451
+ service: name ?? connectors.map((c) => c.name),
452
+ }),
453
+ steps: steps.map((s) => ({ id: s.id, title: s.title })),
454
+ blocking: true,
455
+ });
456
+ }
457
+ return missing;
458
+ }
346
459
  /**
347
- * The message a run that cannot start gives, naming the steps and why. Classes with the same
348
- * problem (a step that thinks and writes on one client that is not installed) say it once, and
349
- * name each of their steps once.
460
+ * The message a run that cannot start gives, naming the steps and why: missing models and
461
+ * connections alike. Needs with the same problem (a step that thinks and writes on one client
462
+ * that is not installed) say it once, and name each of their steps once.
350
463
  */
351
464
  export function blockingMessage(missing) {
352
465
  const byProblem = new Map();
@@ -0,0 +1,58 @@
1
+ import { candidates, open } from "../connectors/index.js";
2
+ import { connectionsFor } from "../connectors/person-connections.js";
3
+ import { unavoidableFrom } from "./requirements.js";
4
+ /*
5
+ * The accounts a run asks for before it goes on (docs/plans/run-connections.md, „One card, two
6
+ * moments“): at its start the needs of the steps every run passes, later the need of the step it
7
+ * stands at. A need the run already has an account for asks nothing.
8
+ */
9
+ /** The wizard's needs a step uses: an agent step lists them, a tool step calls one, a page connects one. */
10
+ export function needsOfStep(def, step) {
11
+ const ids = new Set();
12
+ if (step.type === "agent") {
13
+ for (const id of step.connections ?? []) {
14
+ ids.add(id);
15
+ }
16
+ }
17
+ else if (step.type === "tool" &&
18
+ step.call &&
19
+ "connection" in step.call &&
20
+ step.call.connection) {
21
+ ids.add(step.call.connection);
22
+ }
23
+ else if (step.type === "form") {
24
+ for (const field of step.fields) {
25
+ if (field.kind === "connection" && field.connection) {
26
+ ids.add(field.connection);
27
+ }
28
+ }
29
+ }
30
+ return (def.connections ?? []).filter((c) => ids.has(c.id));
31
+ }
32
+ /** The needs of the steps every path from `from` passes, with what is known of the answers. */
33
+ export function needsAhead(def, from, known) {
34
+ const ahead = unavoidableFrom(def, from, known);
35
+ const ids = new Set(def.steps.filter((s) => ahead.has(s.id)).flatMap((s) => needsOfStep(def, s).map((c) => c.id)));
36
+ return (def.connections ?? []).filter((c) => ids.has(c.id));
37
+ }
38
+ /**
39
+ * Of these needs, the ones the run has no account to use for: none, or several and none chosen.
40
+ * A connection the definition names (`spaceConnection`) is the space's and asks here never; its
41
+ * sign-in is the wait card's. Nor does a connector with nothing to connect.
42
+ */
43
+ export async function unconnected(scope, spaceId, needs) {
44
+ const out = [];
45
+ for (const need of needs) {
46
+ if (need.spaceConnection || need.target) {
47
+ continue;
48
+ }
49
+ const connectors = await candidates(need, spaceId);
50
+ if (connectors.length && connectors.every(open)) {
51
+ continue;
52
+ }
53
+ if (!(await connectionsFor(scope, spaceId, need)).chosen) {
54
+ out.push(need);
55
+ }
56
+ }
57
+ return out;
58
+ }