@engenty/wizards-runtime 0.16.2 → 0.17.1

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 (156) hide show
  1. package/apps/runtime/dist/agents/studio-assistant.js +13 -6
  2. package/apps/runtime/dist/app.js +2 -0
  3. package/apps/runtime/dist/assistant/knows.js +15 -2
  4. package/apps/runtime/dist/broker/account.js +20 -1
  5. package/apps/runtime/dist/broker/call.js +131 -22
  6. package/apps/runtime/dist/broker/grant.js +25 -1
  7. package/apps/runtime/dist/broker/host.js +8 -2
  8. package/apps/runtime/dist/broker/index.js +5 -4
  9. package/apps/runtime/dist/broker/log.js +178 -24
  10. package/apps/runtime/dist/broker/over.js +38 -0
  11. package/apps/runtime/dist/broker/rights.js +192 -0
  12. package/apps/runtime/dist/broker/rwx.js +309 -53
  13. package/apps/runtime/dist/broker/send.js +109 -44
  14. package/apps/runtime/dist/bundles/fetch.js +119 -0
  15. package/apps/runtime/dist/bundles/index.js +621 -0
  16. package/apps/runtime/dist/bundles/read.js +607 -0
  17. package/apps/runtime/dist/connectors/external.js +532 -61
  18. package/apps/runtime/dist/connectors/person-sign-ins.js +1 -0
  19. package/apps/runtime/dist/connectors/reload.js +73 -0
  20. package/apps/runtime/dist/connectors/space-connections.js +118 -6
  21. package/apps/runtime/dist/db/migrations/tenant/0058_mcp_state_across_roles.sql +26 -0
  22. package/apps/runtime/dist/db/migrations/tenant/0059_space_connection_paused.sql +2 -0
  23. package/apps/runtime/dist/db/migrations/tenant/0060_space_bundle.sql +21 -0
  24. package/apps/runtime/dist/db/migrations/tenant/0061_space_connection_limits.sql +2 -0
  25. package/apps/runtime/dist/db/migrations/tenant/meta/0058_snapshot.json +6696 -0
  26. package/apps/runtime/dist/db/migrations/tenant/meta/0059_snapshot.json +6710 -0
  27. package/apps/runtime/dist/db/migrations/tenant/meta/0060_snapshot.json +6857 -0
  28. package/apps/runtime/dist/db/migrations/tenant/meta/0061_snapshot.json +6871 -0
  29. package/apps/runtime/dist/db/migrations/tenant/meta/_journal.json +28 -0
  30. package/apps/runtime/dist/db/schema.js +81 -3
  31. package/apps/runtime/dist/docs/dev/broker.md +316 -50
  32. package/apps/runtime/dist/docs/dev/plugins/space.md +13 -2
  33. package/apps/runtime/dist/docs/user-guide/capabilities.md +172 -10
  34. package/apps/runtime/dist/docs/user-guide/connectors.md +57 -7
  35. package/apps/runtime/dist/docs/user-guide/protocol.md +44 -7
  36. package/apps/runtime/dist/docs/user-guide/test-and-share.md +1 -1
  37. package/apps/runtime/dist/docs/user-guide/together.md +4 -4
  38. package/apps/runtime/dist/elements/caller.js +2 -2
  39. package/apps/runtime/dist/elements/knowledge.js +16 -12
  40. package/apps/runtime/dist/engenty/connections-external/build-connector.js +23 -8
  41. package/apps/runtime/dist/engenty/connections-external/import-service.js +18 -9
  42. package/apps/runtime/dist/engenty/connections-external/importer/classify.js +12 -0
  43. package/apps/runtime/dist/engenty/connections-external/invoke/http-invoker.js +1 -0
  44. package/apps/runtime/dist/engenty/connections-external/net/guarded-fetch.js +6 -3
  45. package/apps/runtime/dist/engenty/connections-sdk/oauth2.js +2 -2
  46. package/apps/runtime/dist/engenty/shims/web-ingest.js +64 -0
  47. package/apps/runtime/dist/engine/resources.js +15 -6
  48. package/apps/runtime/dist/engine/runner.js +2 -1
  49. package/apps/runtime/dist/engine/steps.js +3 -2
  50. package/apps/runtime/dist/env.js +2 -0
  51. package/apps/runtime/dist/index.js +19 -2
  52. package/apps/runtime/dist/live/hub.js +17 -3
  53. package/apps/runtime/dist/live/origin.js +6 -4
  54. package/apps/runtime/dist/live/views.js +38 -7
  55. package/apps/runtime/dist/mcp/handler.js +2 -2
  56. package/apps/runtime/dist/mcp/seen.js +71 -51
  57. package/apps/runtime/dist/mcp/tools.js +5 -1
  58. package/apps/runtime/dist/models.js +18 -0
  59. package/apps/runtime/dist/prompts/mcp.md +1 -1
  60. package/apps/runtime/dist/prompts/tools.md +17 -1
  61. package/apps/runtime/dist/routes/api.js +2 -2
  62. package/apps/runtime/dist/routes/broker.js +59 -20
  63. package/apps/runtime/dist/routes/bundles.js +91 -0
  64. package/apps/runtime/dist/routes/connections.js +14 -3
  65. package/apps/runtime/dist/routes/live.js +4 -2
  66. package/apps/runtime/dist/routes/rules.js +53 -9
  67. package/apps/runtime/dist/routes/studio.js +36 -20
  68. package/apps/runtime/dist/services/api.js +4 -2
  69. package/apps/runtime/dist/services/cloud.js +2 -0
  70. package/apps/runtime/dist/services/draft-events.js +79 -6
  71. package/apps/runtime/dist/services/errors.js +1 -0
  72. package/apps/runtime/dist/services/files.js +2 -2
  73. package/apps/runtime/dist/services/knowledge.js +93 -27
  74. package/apps/runtime/dist/services/members-studio.js +22 -2
  75. package/apps/runtime/dist/services/skills.js +61 -5
  76. package/apps/runtime/dist/services/space-categories.js +83 -5
  77. package/apps/runtime/dist/services/space-index.js +173 -25
  78. package/apps/runtime/dist/services/space-origin.js +28 -11
  79. package/apps/runtime/dist/services/synced-spaces.js +5 -1
  80. package/apps/runtime/dist/services/wizards.js +48 -2
  81. package/apps/runtime/dist/services/work-ai.js +15 -5
  82. package/apps/runtime/dist/sharing/jobs.js +8 -2
  83. package/apps/runtime/dist/sync/hub.js +17 -3
  84. package/apps/runtime/dist/sync/records.js +6 -1
  85. package/apps/runtime/dist/texts.js +42 -5
  86. package/apps/runtime/dist/tools/connections.js +8 -0
  87. package/apps/runtime/dist/tools/connector.js +13 -1
  88. package/apps/runtime/dist/tools/index.js +21 -10
  89. package/apps/runtime/dist/tools/skills.js +11 -1
  90. package/apps/runtime/dist/tools/web-search.js +36 -0
  91. package/apps/web/dist/assets/{AboutDialog-BCcD8hKm.js → AboutDialog-mZCBU7KF.js} +1 -1
  92. package/apps/web/dist/assets/{BlockEditor-DgaUm2pR.js → BlockEditor-Dk0QwLSU.js} +1 -1
  93. package/apps/web/dist/assets/CapabilitiesPage-GkpgF-wZ.js +2 -0
  94. package/apps/web/dist/assets/{ChangelogDialog-B08elwyr.js → ChangelogDialog-BhyilZWA.js} +1 -1
  95. package/apps/web/dist/assets/{CodeEditor-BiyOk_SC.js → CodeEditor-DULYZbuE.js} +1 -1
  96. package/apps/web/dist/assets/EditorPage-D_mCdYdZ.js +3 -0
  97. package/apps/web/dist/assets/{FlowPreview-DF_6TvZ0.js → FlowPreview-ykxZxWnk.js} +1 -1
  98. package/apps/web/dist/assets/{LangSwitch-Ba4OWLzJ.js → LangSwitch-iO54w9AP.js} +1 -1
  99. package/apps/web/dist/assets/{Marketplace-DqziLf66.js → Marketplace-C97fH7UC.js} +2 -2
  100. package/apps/web/dist/assets/{NewWizardChannels-CsIGp0nZ.js → NewWizardChannels-CsSV7sm2.js} +1 -1
  101. package/apps/web/dist/assets/{NewWizardPage-CzQAkKMy.js → NewWizardPage-Ebgw-Vf_.js} +1 -1
  102. package/apps/web/dist/assets/{OnboardingPage-B9gr2OX5.js → OnboardingPage-BZlloT7v.js} +1 -1
  103. package/apps/web/dist/assets/PreviewPane-CJuqY5uA.js +7 -0
  104. package/apps/web/dist/assets/ProtocolSection-CPaDKVpZ.js +1 -0
  105. package/apps/web/dist/assets/{PublicRunner-BVs8-Vu3.js → PublicRunner-4Lf4SnwB.js} +1 -1
  106. package/apps/web/dist/assets/{ReadOnly--4CIJCDD.js → ReadOnly-CXQ41R9Q.js} +1 -1
  107. package/apps/web/dist/assets/SettingsPage-C-8BgK9O.js +2 -0
  108. package/apps/web/dist/assets/{SetupPage-9Zk-KUGA.js → SetupPage-4_K083Wl.js} +1 -1
  109. package/apps/web/dist/assets/{SharePage-D_Ab0gjr.js → SharePage-CQjgMcDI.js} +1 -1
  110. package/apps/web/dist/assets/{SkillEditor-DvtameHg.js → SkillEditor-DT5hQwbg.js} +1 -1
  111. package/apps/web/dist/assets/{Skills-Cf1Kl4Fy.js → Skills-D7V_9_xo.js} +1 -1
  112. package/apps/web/dist/assets/SpacePage-D3rYS1bA.js +2 -0
  113. package/apps/web/dist/assets/{UpdateCheck-DweZBVP6.js → UpdateCheck-DVgAJmy8.js} +2 -2
  114. package/apps/web/dist/assets/changelog-DzQCUSsx.js +1 -0
  115. package/apps/web/dist/assets/{code-editor-B1RbFTAZ.js → code-editor-5T7ilBjd.js} +2 -2
  116. package/apps/web/dist/assets/{host-CKS5U5Vg.js → host-CCijW1hj.js} +6 -6
  117. package/apps/web/dist/assets/i18n-DCPDesT-.js +55 -0
  118. package/apps/web/dist/assets/{index-Ckcn5vy7.js → index-C_iWl8iS.js} +3 -3
  119. package/apps/web/dist/assets/index-zcPlodHx.css +1 -0
  120. package/apps/web/dist/assets/minus-BpYkOkYw.js +1 -0
  121. package/apps/web/dist/assets/{read-aloud-Bq88XUHC.js → read-aloud-Qb719not.js} +1 -1
  122. package/apps/web/dist/assets/{runners-DvYVe9Dt.js → runners-BeZ84YH_.js} +1 -1
  123. package/apps/web/dist/assets/{session-D2bjiA3P.js → session-CEJRkSP5.js} +1 -1
  124. package/apps/web/dist/assets/{theme-CNJIC2be.js → theme-y_owNosi.js} +1 -1
  125. package/apps/web/dist/assets/{ui-Mplfhz_Z.js → ui-BacfkQ7Q.js} +1 -1
  126. package/apps/web/dist/assets/{useMutation-8QRM-z4M.js → useMutation-CgzFr4qH.js} +1 -1
  127. package/apps/web/dist/assets/{viewers-CEocUV_2.js → viewers-CkyHAjnk.js} +2 -2
  128. package/apps/web/dist/index.html +12 -12
  129. package/apps/web/dist/mcp/flow.html +2 -2
  130. package/node_modules/@engenty/wizards/dist/plugin/index.d.ts +7 -2
  131. package/node_modules/@engenty/wizards-shared/dist/bundles.d.ts +219 -0
  132. package/node_modules/@engenty/wizards-shared/dist/bundles.js +19 -0
  133. package/node_modules/@engenty/wizards-shared/dist/connectors.d.ts +117 -4
  134. package/node_modules/@engenty/wizards-shared/dist/connectors.js +14 -0
  135. package/node_modules/@engenty/wizards-shared/dist/feature-flags.d.ts +12 -0
  136. package/node_modules/@engenty/wizards-shared/dist/feature-flags.js +12 -0
  137. package/node_modules/@engenty/wizards-shared/dist/run.d.ts +11 -0
  138. package/node_modules/@engenty/wizards-shared/dist/run.js +22 -0
  139. package/node_modules/@engenty/wizards-shared/dist/rwx.d.ts +84 -1
  140. package/node_modules/@engenty/wizards-shared/dist/rwx.js +69 -1
  141. package/node_modules/@engenty/wizards-shared/dist/skills.d.ts +20 -3
  142. package/node_modules/@engenty/wizards-shared/dist/skills.js +5 -2
  143. package/node_modules/@engenty/wizards-shared/dist/spaces.d.ts +3 -2
  144. package/node_modules/@engenty/wizards-shared/dist/spaces.js +12 -3
  145. package/package.json +1 -1
  146. package/plugin/.claude-plugin/plugin.json +1 -1
  147. package/plugin/plugin.json +1 -1
  148. package/apps/web/dist/assets/CapabilitiesPage-DuJJV1ll.js +0 -2
  149. package/apps/web/dist/assets/EditorPage-EMFTHEYD.js +0 -3
  150. package/apps/web/dist/assets/PreviewPane-DSOV3o-1.js +0 -7
  151. package/apps/web/dist/assets/SettingsPage-z2u8lSe2.js +0 -2
  152. package/apps/web/dist/assets/SpacePage-CyqVzX9b.js +0 -2
  153. package/apps/web/dist/assets/changelog-C85v9OWg.js +0 -1
  154. package/apps/web/dist/assets/connection-sign-in-CaVvh5GQ.js +0 -1
  155. package/apps/web/dist/assets/i18n-Bymk5Ev-.js +0 -55
  156. package/apps/web/dist/assets/index-w-3J3ZJ9.css +0 -1
@@ -1,9 +1,10 @@
1
1
  import { decryptToken, defineConnector, } from "../shims/connections-sdk.js";
2
2
  import { z } from "zod";
3
3
  import { headersFromRequired } from "./import-service.js";
4
- import { groupOf } from "./importer/classify.js";
4
+ import { groupIn, recipientFieldIn } from "./importer/classify.js";
5
5
  import { executeHttpAction } from "./invoke/http-invoker.js";
6
6
  import { mcpCallTool } from "./invoke/mcp-client.js";
7
+ import { createGuardedFetch } from "./net/guarded-fetch.js";
7
8
  import { connectionsRedirectUri, registerDynamicClient } from "./oauth-dcr.js";
8
9
  /**
9
10
  * Materialize a stored import record into a live `ConnectorDefinition`. From
@@ -43,12 +44,13 @@ function inputSchemaToZod(action) {
43
44
  return null;
44
45
  }
45
46
  }
46
- function buildAction(record, action, live) {
47
+ function buildAction(record, action, live, allowPrivate) {
47
48
  const inputSchema = inputSchemaToZod(action);
48
49
  if (!inputSchema) {
49
50
  return null;
50
51
  }
51
- const group = groupOf(action);
52
+ const group = groupIn(record, action);
53
+ const recipientField = recipientFieldIn(record, action);
52
54
  return {
53
55
  description: action.description.slice(0, 1024),
54
56
  group,
@@ -61,6 +63,9 @@ function buildAction(record, action, live) {
61
63
  return mcpCallTool({
62
64
  args,
63
65
  endpoint: current.source_url,
66
+ ...(allowPrivate
67
+ ? { fetchImpl: createGuardedFetch({ allowPrivate: true }) }
68
+ : {}),
64
69
  headers: mcpHeaders(current, ctx.accessToken),
65
70
  toolName: action.invoke.tool_name,
66
71
  transport: current.mcp_transport,
@@ -68,7 +73,10 @@ function buildAction(record, action, live) {
68
73
  }
69
74
  return executeHttpAction({
70
75
  accessToken: ctx.accessToken,
71
- fetchImpl: ctx.fetchImpl,
76
+ // The context's fetch refuses private hosts itself; where they may be
77
+ // reached the guard is the invoker's own, with `allowPrivate`.
78
+ ...(allowPrivate ? { allowPrivate: true } : {}),
79
+ fetchImpl: allowPrivate ? fetch : ctx.fetchImpl,
72
80
  input: args,
73
81
  invoke: action.invoke,
74
82
  record: current,
@@ -76,10 +84,14 @@ function buildAction(record, action, live) {
76
84
  },
77
85
  id: action.id,
78
86
  inputSchema,
87
+ ...(recipientField ? { recipientField } : {}),
79
88
  summary: action.summary.slice(0, 256),
80
89
  };
81
90
  }
82
- function buildAuth(record, live, persistOAuthClient) {
91
+ function buildAuth(record, live, allowPrivate, persistOAuthClient) {
92
+ // The endpoints came from a registry or a pasted address: the token calls
93
+ // and the client registration go through the guard like every other call.
94
+ const guarded = createGuardedFetch(allowPrivate ? { allowPrivate: true } : {});
83
95
  const stored = record.auth_config;
84
96
  if (stored.kind === "oauth2") {
85
97
  const dcr = stored.dcr === true && Boolean(stored.registration_endpoint?.trim());
@@ -89,6 +101,7 @@ function buildAuth(record, live, persistOAuthClient) {
89
101
  authUrl: stored.auth_url,
90
102
  baseScopes: stored.scopes,
91
103
  dynamicClientRegistration: dcr,
104
+ fetchImpl: guarded,
92
105
  registerClient: dcr && persistOAuthClient
93
106
  ? async () => {
94
107
  const current = live();
@@ -104,6 +117,7 @@ function buildAuth(record, live, persistOAuthClient) {
104
117
  }
105
118
  const registered = await registerDynamicClient({
106
119
  clientName: current.name,
120
+ fetchImpl: guarded,
107
121
  redirectUri: connectionsRedirectUri(),
108
122
  registrationEndpoint: endpoint,
109
123
  scopes: current.auth_config.kind === "oauth2"
@@ -162,12 +176,13 @@ function buildAuth(record, live, persistOAuthClient) {
162
176
  kind: "api_key",
163
177
  };
164
178
  }
165
- export function buildImportedConnector(record, resolveLive, persistOAuthClient) {
179
+ export function buildImportedConnector(record, resolveLive, persistOAuthClient, options) {
166
180
  const live = () => resolveLive?.() ?? record;
181
+ const allowPrivate = options?.allowPrivate === true;
167
182
  const actions = [];
168
183
  const skippedActions = [];
169
184
  for (const normalized of record.actions) {
170
- const action = buildAction(record, normalized, live);
185
+ const action = buildAction(record, normalized, live, allowPrivate);
171
186
  if (action) {
172
187
  actions.push(action);
173
188
  }
@@ -177,7 +192,7 @@ export function buildImportedConnector(record, resolveLive, persistOAuthClient)
177
192
  }
178
193
  const connector = defineConnector({
179
194
  actions,
180
- auth: buildAuth(record, live, persistOAuthClient),
195
+ auth: buildAuth(record, live, allowPrivate, persistOAuthClient),
181
196
  description: `${record.name} — imported from ${record.domain} (${record.source_kind})`,
182
197
  icon: "plug",
183
198
  id: record.id,
@@ -190,16 +190,22 @@ export function assembleRecord(params) {
190
190
  assertNoRegistryVariables(surface);
191
191
  }
192
192
  const requiredHeaders = surface ? resolveRequiredHeaders(surface) : [];
193
- const mapped = mapAuth({
194
- discover: params.discover ?? null,
195
- securitySchemes: normalized.security_schemes,
196
- sourceKind: params.sourceKind,
197
- surface,
198
- });
199
- if (!mapped.ok) {
200
- throw new ImportValidationError(mapped.reason);
193
+ let auth;
194
+ if (params.auth) {
195
+ auth = params.auth;
196
+ }
197
+ else {
198
+ const mapped = mapAuth({
199
+ discover: params.discover ?? null,
200
+ securitySchemes: normalized.security_schemes,
201
+ sourceKind: params.sourceKind,
202
+ surface,
203
+ });
204
+ if (!mapped.ok) {
205
+ throw new ImportValidationError(mapped.reason);
206
+ }
207
+ auth = mapped.auth;
201
208
  }
202
- const auth = mapped.auth;
203
209
  if (auth.kind === "oauth2" && !params.oauthClient) {
204
210
  if (auth.dcr && auth.registration_endpoint) {
205
211
  warnings.push("oauth2 client will be registered on first authenticate (dynamic client registration)");
@@ -237,7 +243,10 @@ export function assembleRecord(params) {
237
243
  if (params.sourceKind === "openapi" && !baseUrl) {
238
244
  throw new ImportValidationError("spec declares no server URL — provide base_url explicitly");
239
245
  }
246
+ const known = new Set(actions.map((action) => action.id));
247
+ const actionKinds = Object.fromEntries(Object.entries(params.actionKinds ?? {}).filter(([id]) => known.has(id)));
240
248
  const record = {
249
+ ...(Object.keys(actionKinds).length ? { action_kinds: actionKinds } : {}),
241
250
  actions,
242
251
  auth_config: auth,
243
252
  base_url: baseUrl,
@@ -104,3 +104,15 @@ export function groupOf(action) {
104
104
  }
105
105
  return words.some((w) => SEND_WORDS.has(w)) ? "send" : action.classification;
106
106
  }
107
+ /**
108
+ * The group an action of a stored connector runs under: what an admin said it
109
+ * does (`action_kinds`) first, the guess by name (`groupOf`) else.
110
+ */
111
+ export function groupIn(record, action) {
112
+ return record.action_kinds?.[action.id]?.kind ?? groupOf(action);
113
+ }
114
+ /** The input field an admin named as a send's recipient, where one did. */
115
+ export function recipientFieldIn(record, action) {
116
+ const set = record.action_kinds?.[action.id];
117
+ return groupIn(record, action) === "send" ? set?.recipient_field : undefined;
118
+ }
@@ -102,6 +102,7 @@ export function buildHttpRequest(params) {
102
102
  export async function executeHttpAction(params) {
103
103
  const { accessToken, input, invoke, record } = params;
104
104
  const fetchImpl = createGuardedFetch({
105
+ ...(params.allowPrivate ? { allowPrivate: true } : {}),
105
106
  fetchImpl: params.fetchImpl,
106
107
  ...(params.lookupImpl ? { lookupImpl: params.lookupImpl } : {}),
107
108
  });
@@ -1,4 +1,4 @@
1
- import { assertPublicHttpHost } from "../../shims/web-ingest.js";
1
+ import { assertLocalOrPublicHttpHost, assertPublicHttpHost, } from "../../shims/web-ingest.js";
2
2
  /**
3
3
  * Every network call this module makes reaches a URL that came from the
4
4
  * registry, an admin-pasted field, or a stored import record — attacker
@@ -19,11 +19,14 @@ const DOWNGRADE_TO_GET = new Set([301, 302, 303]);
19
19
  export function createGuardedFetch(options) {
20
20
  const fetchImpl = options?.fetchImpl ?? fetch;
21
21
  const maxRedirects = options?.maxRedirects ?? DEFAULT_MAX_REDIRECTS;
22
+ const assertHost = options?.allowPrivate
23
+ ? assertLocalOrPublicHttpHost
24
+ : assertPublicHttpHost;
22
25
  return (async (input, init) => {
23
26
  let currentUrl = typeof input === "string" ? input : String(input);
24
27
  let currentInit = { ...init, redirect: "manual" };
25
28
  let hops = 0;
26
- await assertPublicHttpHost(currentUrl, options?.lookupImpl);
29
+ await assertHost(currentUrl, options?.lookupImpl);
27
30
  while (true) {
28
31
  const response = await fetchImpl(currentUrl, currentInit);
29
32
  if (!REDIRECT_STATUSES.has(response.status)) {
@@ -44,7 +47,7 @@ export function createGuardedFetch(options) {
44
47
  catch {
45
48
  throw new Error(`Malformed Location header in redirect: ${location}`);
46
49
  }
47
- await assertPublicHttpHost(nextUrl, options?.lookupImpl);
50
+ await assertHost(nextUrl, options?.lookupImpl);
48
51
  if (DOWNGRADE_TO_GET.has(response.status)) {
49
52
  currentInit = { ...currentInit, body: undefined, method: "GET" };
50
53
  }
@@ -140,11 +140,11 @@ export function exchangeAuthorizationCode(params) {
140
140
  if (params.codeVerifier) {
141
141
  body.code_verifier = params.codeVerifier;
142
142
  }
143
- return postTokenEndpoint(params.config, body, params.fetchImpl ?? fetch, params.resolveEnv);
143
+ return postTokenEndpoint(params.config, body, params.fetchImpl ?? params.config.fetchImpl ?? fetch, params.resolveEnv);
144
144
  }
145
145
  export function refreshAccessToken(params) {
146
146
  return postTokenEndpoint(params.config, {
147
147
  grant_type: "refresh_token",
148
148
  refresh_token: params.refreshToken,
149
- }, params.fetchImpl ?? fetch, params.resolveEnv);
149
+ }, params.fetchImpl ?? params.config.fetchImpl ?? fetch, params.resolveEnv);
150
150
  }
@@ -1,4 +1,5 @@
1
1
  /** Stand-in for `@engenty/web-ingest`: its host guard, and this product's HTML to Markdown. */
2
+ import { BlockList, isIP } from "node:net";
2
3
  import { isPublicAddress } from "../../tools/net-guard.js";
3
4
  import { assertPublicHttpHost as assertHost, isBlockedIp as blockedIp, } from "../web-ingest/ssrf.js";
4
5
  export { htmlToMarkdown } from "../../render/convert.js";
@@ -17,3 +18,66 @@ export async function assertPublicHttpHost(urlString, lookupImpl) {
17
18
  }
18
19
  return result;
19
20
  }
21
+ /** This computer and the networks of a home or an office: loopback, the private ranges, a tailnet. */
22
+ const local = new BlockList();
23
+ for (const [net, prefix] of [
24
+ ["127.0.0.0", 8],
25
+ ["10.0.0.0", 8],
26
+ ["172.16.0.0", 12],
27
+ ["192.168.0.0", 16],
28
+ ["100.64.0.0", 10],
29
+ ]) {
30
+ local.addSubnet(net, prefix, "ipv4");
31
+ }
32
+ local.addAddress("::1", "ipv6");
33
+ local.addSubnet("fc00::", 7, "ipv6");
34
+ /** Whether an address is this computer or one of its private networks. Link-local is neither. */
35
+ export function isLocalAddress(ip) {
36
+ const family = isIP(ip);
37
+ return family !== 0 && local.check(ip, family === 6 ? "ipv6" : "ipv4");
38
+ }
39
+ /**
40
+ * The guard for the one caller that may reach this computer and its private networks: a connector
41
+ * from a pasted address on a runtime that is a computer of one's own (`connectors/external.ts`).
42
+ * Public addresses pass as everywhere; loopback and private ones pass too. Link-local addresses
43
+ * (the cloud metadata service), multicast and the reserved ranges stay refused, and so does
44
+ * anything that is not http or https.
45
+ */
46
+ export async function assertLocalOrPublicHttpHost(urlString, lookupImpl) {
47
+ let url;
48
+ try {
49
+ url = new URL(urlString);
50
+ }
51
+ catch {
52
+ throw new Error(`Invalid URL: ${urlString}`);
53
+ }
54
+ if (url.protocol !== "http:" && url.protocol !== "https:") {
55
+ throw new Error("Only http and https URLs are allowed");
56
+ }
57
+ const host = url.hostname.replace(/^\[|\]$/g, "").toLowerCase();
58
+ if (host === "localhost" || host.endsWith(".localhost")) {
59
+ return { url, addresses: ["127.0.0.1"] };
60
+ }
61
+ const allowed = (ip) => isLocalAddress(ip) || isPublicAddress(ip);
62
+ let addresses;
63
+ if (isIP(host) !== 0) {
64
+ addresses = [host];
65
+ }
66
+ else {
67
+ const lookup = lookupImpl ?? (await import("node:dns/promises")).lookup;
68
+ try {
69
+ addresses = (await lookup(host, { all: true, verbatim: true })).map((e) => e.address);
70
+ }
71
+ catch (err) {
72
+ throw new Error(`DNS resolution failed for ${host}: ${err instanceof Error ? err.message : String(err)}`);
73
+ }
74
+ if (!addresses.length) {
75
+ throw new Error(`No DNS records found for ${host}`);
76
+ }
77
+ }
78
+ const bad = addresses.find((a) => !allowed(a));
79
+ if (bad) {
80
+ throw new Error(`URL host is not allowed for fetch: ${host} (${bad})`);
81
+ }
82
+ return { url, addresses };
83
+ }
@@ -33,6 +33,8 @@ export class RunResources {
33
33
  /** The engine this run's sandbox is made on; null until bound, or when the run has none. */
34
34
  engine = null;
35
35
  scope = null;
36
+ /** Bound for a share job: the one caller of a run that is done (broker/over.ts). */
37
+ share = false;
36
38
  /** Changes the person allowed for the rest of this run, as "<connection>:<action>". */
37
39
  allowed = new Set();
38
40
  watchers = new Set();
@@ -46,8 +48,9 @@ export class RunResources {
46
48
  this.runId = runId;
47
49
  }
48
50
  /** Whose store kept sign-ins are read from and written to, and whose run this is. */
49
- bind(scope, run) {
51
+ bind(scope, run, share = false) {
50
52
  this.scope = scope;
53
+ this.share = share;
51
54
  this.engine = runSandboxEngine(run);
52
55
  }
53
56
  /** What this run's sandbox runs, or null when the run has none (a guest's, or `SANDBOX=off`). */
@@ -57,17 +60,23 @@ export class RunResources {
57
60
  async browserContext() {
58
61
  if (!this.context) {
59
62
  const make = (kept) => webContext({ locale: "de-DE", ...(kept ? { storageState: kept } : {}) });
60
- // The kept sign-ins are read through the broker: only the browser context sees them.
63
+ // The kept sign-ins are read through the broker: only the browser context sees them. A run
64
+ // that is over gets none: its browser opens signed in nowhere.
61
65
  const scope = this.scope;
62
- this.context = scope
66
+ const kept = scope
63
67
  ? await brokerSecret({
64
68
  who: whoOf(scope.holder),
65
- where: { runId: this.runId, wizardId: scope.wizardId },
69
+ where: {
70
+ runId: this.runId,
71
+ wizardId: scope.wizardId,
72
+ ...(this.share ? { share: true } : {}),
73
+ },
66
74
  scope,
67
75
  slot: SESSION_SLOT,
68
76
  handler: make,
69
- }).catch(() => make(null))
70
- : await make(null);
77
+ }).catch(() => null)
78
+ : null;
79
+ this.context = kept?.ok ? kept.result : await make(null);
71
80
  }
72
81
  return this.context;
73
82
  }
@@ -572,7 +572,7 @@ async function storedLists(run, holder) {
572
572
  export async function makeContext(run, space, state, signal, own = {}) {
573
573
  const store = scopeOf(run);
574
574
  const resources = resourcesFor(run.id);
575
- resources.bind(store, run);
575
+ resources.bind(store, run, own.share);
576
576
  const stepId = own.stepId ?? run.cursor ?? "";
577
577
  const holder = await runHolder(run);
578
578
  return {
@@ -601,6 +601,7 @@ export async function makeContext(run, space, state, signal, own = {}) {
601
601
  ((ask) => run.unattended ? Promise.resolve(null) : askPerson(run.id, { ...ask, stepId }, signal)),
602
602
  emit: own.emit ?? ((type, message, asset) => emitEvent(run.id, run.cursor, type, message, asset)),
603
603
  call: { runId: run.id, stepId },
604
+ ...(own.share ? { share: true } : {}),
604
605
  chargeUsd: (usd) => addLocalCost(run.id, stepId, usd),
605
606
  saveAsset: (input) => saveAsset({
606
607
  ...input,
@@ -6,6 +6,7 @@ import { mainLogo, ruleLines, runTheme } from "@engenty/wizards-shared/spaces";
6
6
  import { validateSurface, } from "@engenty/wizards-shared/surface";
7
7
  import { Agent } from "@mastra/core/agent";
8
8
  import { generateText, jsonSchema, Output, parsePartialJson } from "ai";
9
+ import { subjectsOf } from "../broker/rwx.js";
9
10
  import { extFor, loadAsset, loadAssetText } from "../files/storage.js";
10
11
  import { snapshotHtmlImages } from "../files/web-images.js";
11
12
  import { generateImageMedia, generateSpeechMedia, generateVideoMedia, } from "../media/generate.js";
@@ -519,8 +520,8 @@ export async function runAgentStep(step, ctx) {
519
520
  instructions ?? "",
520
521
  `Today is ${today(ctx)}.`,
521
522
  brandBlock(ctx),
522
- // Knowledge: what the space holds for its wizards, and how to find and read it.
523
- await knowledgeBlock(ctx.dataSpace.id),
523
+ // Knowledge: what the space holds for the run's holder and its wizard, and how to read it.
524
+ await knowledgeBlock(ctx.dataSpace.id, subjectsOf(ctx)),
524
525
  // Skills: always on whole, on demand by name and description (docs/plans/skills.md).
525
526
  skillsBlock(await skillsOf(ctx), {
526
527
  tools: takesTools(resolved),
@@ -91,6 +91,8 @@ export const env = {
91
91
  doors: ["doors", "web", "runner", "all"].includes(role()),
92
92
  runner: ["runner", "all"].includes(role()),
93
93
  api: ["api", "studio", "web", "runner", "all"].includes(role()),
94
+ /** The index's sweeps, in one process of a runtime: a runner serves the studio's routes too. */
95
+ vectors: ["studio", "web", "all"].includes(role()),
94
96
  },
95
97
  runner: {
96
98
  /** This runner's name in the control database; a new one each start. */
@@ -10,12 +10,14 @@ import { basePath, env } from "./env.js";
10
10
  import { pruneLive } from "./live/feed.js";
11
11
  import { hookConsole } from "./log.js";
12
12
  import { managed } from "./manage.js";
13
+ import { pruneSeen } from "./mcp/seen.js";
13
14
  import { checkModelsAtStart, loadCatalog, loadLocalModels } from "./models.js";
14
15
  import { startJobs } from "./plugins/jobs.js";
15
16
  import { loadPlugins } from "./plugins/loader.js";
16
17
  import { loadEntitlement, startProChecks } from "./plugins/pro.js";
17
18
  import { closeBrowser } from "./render/chromium.js";
18
19
  import { clearRunning, writeRunning } from "./running.js";
20
+ import { pruneDraftChanges } from "./services/draft-events.js";
19
21
  import { reportAllWizards } from "./services/manage-reports.js";
20
22
  import { syncMarketplace } from "./services/marketplace.js";
21
23
  import { purgeExpiredRuns } from "./services/shares.js";
@@ -105,7 +107,14 @@ if (env.serves.runner) {
105
107
  async function purge() {
106
108
  await purgeSessions();
107
109
  for (const id of await knownTenants()) {
108
- await withTenant(id, () => Promise.all([purgeExpiredRuns(), purgeUnusedStores(), compactLog(), pruneLive()])).catch((err) => console.error(`[retention ${id}]`, err));
110
+ await withTenant(id, () => Promise.all([
111
+ purgeExpiredRuns(),
112
+ purgeUnusedStores(),
113
+ compactLog(),
114
+ pruneLive(),
115
+ pruneSeen(),
116
+ pruneDraftChanges(),
117
+ ])).catch((err) => console.error(`[retention ${id}]`, err));
109
118
  }
110
119
  }
111
120
  void purge().catch((err) => console.error("[retention]", err));
@@ -116,11 +125,19 @@ if (!managed && env.serves.studio) {
116
125
  void moveFilesAtStart().catch((err) => console.error("[move-files]", err));
117
126
  }
118
127
  // Assets came into the index later than documents: what is not there yet goes in once.
119
- if (env.serves.studio) {
128
+ if (env.serves.vectors) {
120
129
  const { indexMissingAssets } = await import("./services/space-index.js");
121
130
  for (const id of await knownTenants()) {
122
131
  void withTenant(id, () => indexMissingAssets()).catch((err) => console.error(`[space-index ${id}]`, err));
123
132
  }
133
+ // The embedding model can change at any time on a Manage-App: vectors of another don't compare.
134
+ const { queueVectors } = await import("./services/space-index.js");
135
+ const vectors = async () => {
136
+ for (const id of await knownTenants()) {
137
+ await withTenant(id, () => queueVectors());
138
+ }
139
+ };
140
+ setInterval(() => void vectors().catch((err) => console.error("[space-index]", err)), 600_000).unref();
124
141
  }
125
142
  // Dateien: the folders of this computer mounted in a space, watched and listed again.
126
143
  if (env.serves.studio) {
@@ -18,7 +18,7 @@ const feeds = new Map();
18
18
  * Starts sending the tenant's changes after `since` (null: from now on). Answers `hello`, or
19
19
  * `reset` when the changes after `since` are no longer kept or `since` is of another database.
20
20
  */
21
- export async function subscribe(tenantId, since, send, views) {
21
+ export async function subscribe(tenantId, since, send, views, hears) {
22
22
  const { newest, gap } = await withTenant(tenantId, async () => {
23
23
  const newest = await newestSeq();
24
24
  if (since === null || since === newest) {
@@ -30,7 +30,7 @@ export async function subscribe(tenantId, since, send, views) {
30
30
  const oldest = await oldestSeq();
31
31
  return { newest, gap: oldest === null || oldest > since + 1 };
32
32
  });
33
- const sub = { since: since === null || gap ? newest : since, send, views };
33
+ const sub = { since: since === null || gap ? newest : since, send, views, hears };
34
34
  send(gap ? { event: "reset", seq: newest } : { event: "hello", seq: newest });
35
35
  let feed = feeds.get(tenantId);
36
36
  if (!feed) {
@@ -137,9 +137,23 @@ async function read(feed) {
137
137
  if (!mine.length) {
138
138
  continue;
139
139
  }
140
+ let heard = mine;
141
+ if (sub.hears) {
142
+ try {
143
+ heard = await sub.hears(mine);
144
+ }
145
+ catch (err) {
146
+ // Not known what this reader may hear: nothing is sent, and the next tick asks again.
147
+ console.error(`[live ${feed.id}] what a reader hears:`, err);
148
+ continue;
149
+ }
150
+ }
140
151
  const seq = mine[mine.length - 1].seq;
141
152
  sub.since = seq;
142
- sub.send({ event: "changes", seq, items: await withViews(dedupe(mine), sub.views, read) });
153
+ if (heard.length) {
154
+ const items = await withViews(dedupe(heard), sub.views, read);
155
+ sub.send({ event: "changes", seq, items });
156
+ }
143
157
  }
144
158
  }
145
159
  if (Date.now() - feed.prunedAt > PRUNE_EVERY_MS) {
@@ -32,10 +32,11 @@ export function pushedBy(tenant, install, seq) {
32
32
  }
33
33
  /**
34
34
  * The cloud's live call for one install: the spaces with changes, without what the install
35
- * pushed itself. `hear` gets hello, reset and changes; the answer stops it.
35
+ * pushed itself, and without what `hears` leaves out for its caller. `hear` gets hello, reset and
36
+ * changes; the answer stops it.
36
37
  */
37
- export async function followFor(tenantId, install, since, hear) {
38
- return subscribe(tenantId, since, (e) => {
38
+ export async function followFor(tenantId, install, since, hear, hears) {
39
+ const send = (e) => {
39
40
  if (e.event === "changes") {
40
41
  const spaces = new Set();
41
42
  for (const x of e.items) {
@@ -49,5 +50,6 @@ export async function followFor(tenantId, install, since, hear) {
49
50
  else if (e.event === "hello" || e.event === "reset") {
50
51
  hear(e);
51
52
  }
52
- });
53
+ };
54
+ return subscribe(tenantId, since, send, undefined, hears);
53
55
  }
@@ -7,7 +7,7 @@ import { embeddingModel } from "../models.js";
7
7
  import { mayBuild, spaceWritable } from "../services/access.js";
8
8
  import { cloudLinked, cloudState } from "../services/cloud.js";
9
9
  import { ServiceError } from "../services/errors.js";
10
- import { closedToMe, studioOpen } from "../services/members-studio.js";
10
+ import { spaceOfItem, studioOpen, studioSpaces } from "../services/members-studio.js";
11
11
  import { presentIn } from "../services/presence.js";
12
12
  import { getPage, getRow, getTableHeader } from "../services/space-data.js";
13
13
  import { fileView, spaceFiles } from "../services/space-files.js";
@@ -137,27 +137,58 @@ const ITEM_VIEWS = {
137
137
  },
138
138
  };
139
139
  /**
140
- * What the Studio alone shows of a space: a member whose Studio the space is closed to gets no view
141
- * of these, and the browser asks the studio API, which refuses it (services/members-studio.ts).
142
- * The space itself, its files and connectors are what Work reads in every space.
140
+ * What the Studio alone shows of a space: its wizards with their translations and build chats,
141
+ * its pages, tables, rows and categories, its skills, and who is in an item. The space itself,
142
+ * its files and connectors are what Work reads in every space.
143
143
  */
144
144
  const STUDIO_KINDS = new Set([
145
145
  "wizard",
146
146
  "translation",
147
+ "message",
147
148
  "page",
148
149
  "table",
149
150
  "row",
151
+ "category",
152
+ "skill",
150
153
  "presence",
151
154
  ]);
155
+ /** The space a change is in. Who is in an item (`presence`) is in the item's space. */
156
+ async function spaceOfChange(x) {
157
+ if (x.spaceId || x.kind !== "presence" || !x.parent) {
158
+ return x.spaceId;
159
+ }
160
+ return spaceOfItem("presence", x.parent, x.item.slice(x.parent.length + 1));
161
+ }
162
+ /**
163
+ * What of the feed's changes the person at hand hears. A member hears nothing of what the Studio
164
+ * alone shows of a space closed to them (services/members-studio.ts): not that it changed, not
165
+ * its kind or id. A change that names no space still there (a row that went with its table)
166
+ * says nothing of whose it was, so a member does not hear it either; the item it went with says
167
+ * so in its own space.
168
+ */
169
+ export async function heardChanges(changes) {
170
+ if (!changes.some((x) => STUDIO_KINDS.has(x.kind))) {
171
+ return changes;
172
+ }
173
+ const open = await studioSpaces();
174
+ if (!open) {
175
+ return changes;
176
+ }
177
+ const heard = [];
178
+ for (const x of changes) {
179
+ if (!STUDIO_KINDS.has(x.kind) || open.has((await spaceOfChange(x)) ?? "")) {
180
+ heard.push(x);
181
+ }
182
+ }
183
+ return heard;
184
+ }
185
+ /** The view of a change the reader hears (`heardChanges` comes first, in the hub). */
152
186
  export async function itemView(r, x) {
153
187
  const read = ITEM_VIEWS[x.kind];
154
188
  if (!read) {
155
189
  return undefined;
156
190
  }
157
191
  try {
158
- if (x.spaceId && STUDIO_KINDS.has(x.kind) && (await closedToMe(x.spaceId))) {
159
- return undefined;
160
- }
161
192
  return await read(r, x);
162
193
  }
163
194
  catch (err) {
@@ -37,7 +37,7 @@ async function appRefusal(who, client, body) {
37
37
  ? policy.apps.local
38
38
  : policy.apps.subscriptions
39
39
  : false;
40
- noteChecked(who.tenantId, client, who.name ?? who.email ?? null, allowed, kind);
40
+ await noteChecked(who.tenantId, client, who.name ?? who.email ?? null, allowed, kind);
41
41
  if (allowed) {
42
42
  return null;
43
43
  }
@@ -99,7 +99,7 @@ export function mcpHandler() {
99
99
  .clone()
100
100
  .json()
101
101
  .catch(() => null);
102
- noteRequest(who.tenantId, authInfo.clientId, who.client, body);
102
+ await noteRequest(who.tenantId, authInfo.clientId, who.client, body);
103
103
  const refused = await appRefusal(who, clientNameOf(authInfo.clientId, who.client), body);
104
104
  if (refused) {
105
105
  return refused;