@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.
- package/apps/runtime/dist/agents/studio-assistant.js +13 -6
- package/apps/runtime/dist/app.js +2 -0
- package/apps/runtime/dist/assistant/knows.js +15 -2
- package/apps/runtime/dist/broker/account.js +20 -1
- package/apps/runtime/dist/broker/call.js +131 -22
- package/apps/runtime/dist/broker/grant.js +25 -1
- package/apps/runtime/dist/broker/host.js +8 -2
- package/apps/runtime/dist/broker/index.js +5 -4
- package/apps/runtime/dist/broker/log.js +178 -24
- package/apps/runtime/dist/broker/over.js +38 -0
- package/apps/runtime/dist/broker/rights.js +192 -0
- package/apps/runtime/dist/broker/rwx.js +309 -53
- package/apps/runtime/dist/broker/send.js +109 -44
- package/apps/runtime/dist/bundles/fetch.js +119 -0
- package/apps/runtime/dist/bundles/index.js +621 -0
- package/apps/runtime/dist/bundles/read.js +607 -0
- package/apps/runtime/dist/connectors/external.js +532 -61
- package/apps/runtime/dist/connectors/person-sign-ins.js +1 -0
- package/apps/runtime/dist/connectors/reload.js +73 -0
- package/apps/runtime/dist/connectors/space-connections.js +118 -6
- package/apps/runtime/dist/db/migrations/tenant/0058_mcp_state_across_roles.sql +26 -0
- package/apps/runtime/dist/db/migrations/tenant/0059_space_connection_paused.sql +2 -0
- package/apps/runtime/dist/db/migrations/tenant/0060_space_bundle.sql +21 -0
- package/apps/runtime/dist/db/migrations/tenant/0061_space_connection_limits.sql +2 -0
- package/apps/runtime/dist/db/migrations/tenant/meta/0058_snapshot.json +6696 -0
- package/apps/runtime/dist/db/migrations/tenant/meta/0059_snapshot.json +6710 -0
- package/apps/runtime/dist/db/migrations/tenant/meta/0060_snapshot.json +6857 -0
- package/apps/runtime/dist/db/migrations/tenant/meta/0061_snapshot.json +6871 -0
- package/apps/runtime/dist/db/migrations/tenant/meta/_journal.json +28 -0
- package/apps/runtime/dist/db/schema.js +81 -3
- package/apps/runtime/dist/docs/dev/broker.md +316 -50
- package/apps/runtime/dist/docs/dev/plugins/space.md +13 -2
- package/apps/runtime/dist/docs/user-guide/capabilities.md +172 -10
- package/apps/runtime/dist/docs/user-guide/connectors.md +57 -7
- package/apps/runtime/dist/docs/user-guide/protocol.md +44 -7
- package/apps/runtime/dist/docs/user-guide/test-and-share.md +1 -1
- package/apps/runtime/dist/docs/user-guide/together.md +4 -4
- package/apps/runtime/dist/elements/caller.js +2 -2
- package/apps/runtime/dist/elements/knowledge.js +16 -12
- package/apps/runtime/dist/engenty/connections-external/build-connector.js +23 -8
- package/apps/runtime/dist/engenty/connections-external/import-service.js +18 -9
- package/apps/runtime/dist/engenty/connections-external/importer/classify.js +12 -0
- package/apps/runtime/dist/engenty/connections-external/invoke/http-invoker.js +1 -0
- package/apps/runtime/dist/engenty/connections-external/net/guarded-fetch.js +6 -3
- package/apps/runtime/dist/engenty/connections-sdk/oauth2.js +2 -2
- package/apps/runtime/dist/engenty/shims/web-ingest.js +64 -0
- package/apps/runtime/dist/engine/resources.js +15 -6
- package/apps/runtime/dist/engine/runner.js +2 -1
- package/apps/runtime/dist/engine/steps.js +3 -2
- package/apps/runtime/dist/env.js +2 -0
- package/apps/runtime/dist/index.js +19 -2
- package/apps/runtime/dist/live/hub.js +17 -3
- package/apps/runtime/dist/live/origin.js +6 -4
- package/apps/runtime/dist/live/views.js +38 -7
- package/apps/runtime/dist/mcp/handler.js +2 -2
- package/apps/runtime/dist/mcp/seen.js +71 -51
- package/apps/runtime/dist/mcp/tools.js +5 -1
- package/apps/runtime/dist/models.js +18 -0
- package/apps/runtime/dist/prompts/mcp.md +1 -1
- package/apps/runtime/dist/prompts/tools.md +17 -1
- package/apps/runtime/dist/routes/api.js +2 -2
- package/apps/runtime/dist/routes/broker.js +59 -20
- package/apps/runtime/dist/routes/bundles.js +91 -0
- package/apps/runtime/dist/routes/connections.js +14 -3
- package/apps/runtime/dist/routes/live.js +4 -2
- package/apps/runtime/dist/routes/rules.js +53 -9
- package/apps/runtime/dist/routes/studio.js +36 -20
- package/apps/runtime/dist/services/api.js +4 -2
- package/apps/runtime/dist/services/cloud.js +2 -0
- package/apps/runtime/dist/services/draft-events.js +79 -6
- package/apps/runtime/dist/services/errors.js +1 -0
- package/apps/runtime/dist/services/files.js +2 -2
- package/apps/runtime/dist/services/knowledge.js +93 -27
- package/apps/runtime/dist/services/members-studio.js +22 -2
- package/apps/runtime/dist/services/skills.js +61 -5
- package/apps/runtime/dist/services/space-categories.js +83 -5
- package/apps/runtime/dist/services/space-index.js +173 -25
- package/apps/runtime/dist/services/space-origin.js +28 -11
- package/apps/runtime/dist/services/synced-spaces.js +5 -1
- package/apps/runtime/dist/services/wizards.js +48 -2
- package/apps/runtime/dist/services/work-ai.js +15 -5
- package/apps/runtime/dist/sharing/jobs.js +8 -2
- package/apps/runtime/dist/sync/hub.js +17 -3
- package/apps/runtime/dist/sync/records.js +6 -1
- package/apps/runtime/dist/texts.js +42 -5
- package/apps/runtime/dist/tools/connections.js +8 -0
- package/apps/runtime/dist/tools/connector.js +13 -1
- package/apps/runtime/dist/tools/index.js +21 -10
- package/apps/runtime/dist/tools/skills.js +11 -1
- package/apps/runtime/dist/tools/web-search.js +36 -0
- package/apps/web/dist/assets/{AboutDialog-BCcD8hKm.js → AboutDialog-mZCBU7KF.js} +1 -1
- package/apps/web/dist/assets/{BlockEditor-DgaUm2pR.js → BlockEditor-Dk0QwLSU.js} +1 -1
- package/apps/web/dist/assets/CapabilitiesPage-GkpgF-wZ.js +2 -0
- package/apps/web/dist/assets/{ChangelogDialog-B08elwyr.js → ChangelogDialog-BhyilZWA.js} +1 -1
- package/apps/web/dist/assets/{CodeEditor-BiyOk_SC.js → CodeEditor-DULYZbuE.js} +1 -1
- package/apps/web/dist/assets/EditorPage-D_mCdYdZ.js +3 -0
- package/apps/web/dist/assets/{FlowPreview-DF_6TvZ0.js → FlowPreview-ykxZxWnk.js} +1 -1
- package/apps/web/dist/assets/{LangSwitch-Ba4OWLzJ.js → LangSwitch-iO54w9AP.js} +1 -1
- package/apps/web/dist/assets/{Marketplace-DqziLf66.js → Marketplace-C97fH7UC.js} +2 -2
- package/apps/web/dist/assets/{NewWizardChannels-CsIGp0nZ.js → NewWizardChannels-CsSV7sm2.js} +1 -1
- package/apps/web/dist/assets/{NewWizardPage-CzQAkKMy.js → NewWizardPage-Ebgw-Vf_.js} +1 -1
- package/apps/web/dist/assets/{OnboardingPage-B9gr2OX5.js → OnboardingPage-BZlloT7v.js} +1 -1
- package/apps/web/dist/assets/PreviewPane-CJuqY5uA.js +7 -0
- package/apps/web/dist/assets/ProtocolSection-CPaDKVpZ.js +1 -0
- package/apps/web/dist/assets/{PublicRunner-BVs8-Vu3.js → PublicRunner-4Lf4SnwB.js} +1 -1
- package/apps/web/dist/assets/{ReadOnly--4CIJCDD.js → ReadOnly-CXQ41R9Q.js} +1 -1
- package/apps/web/dist/assets/SettingsPage-C-8BgK9O.js +2 -0
- package/apps/web/dist/assets/{SetupPage-9Zk-KUGA.js → SetupPage-4_K083Wl.js} +1 -1
- package/apps/web/dist/assets/{SharePage-D_Ab0gjr.js → SharePage-CQjgMcDI.js} +1 -1
- package/apps/web/dist/assets/{SkillEditor-DvtameHg.js → SkillEditor-DT5hQwbg.js} +1 -1
- package/apps/web/dist/assets/{Skills-Cf1Kl4Fy.js → Skills-D7V_9_xo.js} +1 -1
- package/apps/web/dist/assets/SpacePage-D3rYS1bA.js +2 -0
- package/apps/web/dist/assets/{UpdateCheck-DweZBVP6.js → UpdateCheck-DVgAJmy8.js} +2 -2
- package/apps/web/dist/assets/changelog-DzQCUSsx.js +1 -0
- package/apps/web/dist/assets/{code-editor-B1RbFTAZ.js → code-editor-5T7ilBjd.js} +2 -2
- package/apps/web/dist/assets/{host-CKS5U5Vg.js → host-CCijW1hj.js} +6 -6
- package/apps/web/dist/assets/i18n-DCPDesT-.js +55 -0
- package/apps/web/dist/assets/{index-Ckcn5vy7.js → index-C_iWl8iS.js} +3 -3
- package/apps/web/dist/assets/index-zcPlodHx.css +1 -0
- package/apps/web/dist/assets/minus-BpYkOkYw.js +1 -0
- package/apps/web/dist/assets/{read-aloud-Bq88XUHC.js → read-aloud-Qb719not.js} +1 -1
- package/apps/web/dist/assets/{runners-DvYVe9Dt.js → runners-BeZ84YH_.js} +1 -1
- package/apps/web/dist/assets/{session-D2bjiA3P.js → session-CEJRkSP5.js} +1 -1
- package/apps/web/dist/assets/{theme-CNJIC2be.js → theme-y_owNosi.js} +1 -1
- package/apps/web/dist/assets/{ui-Mplfhz_Z.js → ui-BacfkQ7Q.js} +1 -1
- package/apps/web/dist/assets/{useMutation-8QRM-z4M.js → useMutation-CgzFr4qH.js} +1 -1
- package/apps/web/dist/assets/{viewers-CEocUV_2.js → viewers-CkyHAjnk.js} +2 -2
- package/apps/web/dist/index.html +12 -12
- package/apps/web/dist/mcp/flow.html +2 -2
- package/node_modules/@engenty/wizards/dist/plugin/index.d.ts +7 -2
- package/node_modules/@engenty/wizards-shared/dist/bundles.d.ts +219 -0
- package/node_modules/@engenty/wizards-shared/dist/bundles.js +19 -0
- package/node_modules/@engenty/wizards-shared/dist/connectors.d.ts +117 -4
- package/node_modules/@engenty/wizards-shared/dist/connectors.js +14 -0
- package/node_modules/@engenty/wizards-shared/dist/feature-flags.d.ts +12 -0
- package/node_modules/@engenty/wizards-shared/dist/feature-flags.js +12 -0
- package/node_modules/@engenty/wizards-shared/dist/run.d.ts +11 -0
- package/node_modules/@engenty/wizards-shared/dist/run.js +22 -0
- package/node_modules/@engenty/wizards-shared/dist/rwx.d.ts +84 -1
- package/node_modules/@engenty/wizards-shared/dist/rwx.js +69 -1
- package/node_modules/@engenty/wizards-shared/dist/skills.d.ts +20 -3
- package/node_modules/@engenty/wizards-shared/dist/skills.js +5 -2
- package/node_modules/@engenty/wizards-shared/dist/spaces.d.ts +3 -2
- package/node_modules/@engenty/wizards-shared/dist/spaces.js +12 -3
- package/package.json +1 -1
- package/plugin/.claude-plugin/plugin.json +1 -1
- package/plugin/plugin.json +1 -1
- package/apps/web/dist/assets/CapabilitiesPage-DuJJV1ll.js +0 -2
- package/apps/web/dist/assets/EditorPage-EMFTHEYD.js +0 -3
- package/apps/web/dist/assets/PreviewPane-DSOV3o-1.js +0 -7
- package/apps/web/dist/assets/SettingsPage-z2u8lSe2.js +0 -2
- package/apps/web/dist/assets/SpacePage-CyqVzX9b.js +0 -2
- package/apps/web/dist/assets/changelog-C85v9OWg.js +0 -1
- package/apps/web/dist/assets/connection-sign-in-CaVvh5GQ.js +0 -1
- package/apps/web/dist/assets/i18n-Bymk5Ev-.js +0 -55
- package/apps/web/dist/assets/index-w-3J3ZJ9.css +0 -1
|
@@ -1,24 +1,68 @@
|
|
|
1
|
-
import { RWX_FLAGS, RWX_LIMITS, RWX_RESOURCE_KINDS, RWX_SUBJECT_KINDS, } from "@engenty/wizards-shared/rwx";
|
|
1
|
+
import { RWX_ASK_KINDS, RWX_ASK_WHO, RWX_FLAGS, RWX_LIMITS, RWX_PERMS, RWX_RESOURCE_KINDS, RWX_SUBJECT_KINDS, } from "@engenty/wizards-shared/rwx";
|
|
2
2
|
import { Hono } from "hono";
|
|
3
3
|
import { z } from "zod";
|
|
4
|
-
import {
|
|
4
|
+
import { describeRules, ruleChoices } from "../broker/rights.js";
|
|
5
|
+
import { addRule, askRule, changeRule, deleteRule, listRules, rulesSpace } from "../broker/rwx.js";
|
|
6
|
+
import { peopleOf } from "./broker.js";
|
|
5
7
|
const flag = z.enum(RWX_FLAGS).nullable();
|
|
6
8
|
const ruleSchema = z.object({
|
|
7
9
|
subjectKind: z.enum(RWX_SUBJECT_KINDS),
|
|
8
|
-
subjectId: z.string().min(1).max(RWX_LIMITS.id).nullable(),
|
|
10
|
+
subjectId: z.string().min(1).max(RWX_LIMITS.id).nullable().default(null),
|
|
9
11
|
resourceKind: z.enum(RWX_RESOURCE_KINDS),
|
|
10
12
|
resourceId: z.string().min(1).max(RWX_LIMITS.id),
|
|
11
13
|
r: flag.default(null),
|
|
12
14
|
w: flag.default(null),
|
|
13
15
|
x: flag.default(null),
|
|
14
16
|
});
|
|
17
|
+
/** The flags to set; one left out stays as it is. */
|
|
18
|
+
const flagsSchema = z
|
|
19
|
+
.object({ r: flag.optional(), w: flag.optional(), x: flag.optional() })
|
|
20
|
+
.refine((f) => RWX_PERMS.some((p) => f[p] !== undefined), "Name at least one of r, w and x.");
|
|
21
|
+
const askSchema = z.object({
|
|
22
|
+
who: z.enum(RWX_ASK_WHO),
|
|
23
|
+
/** A person's id (a person, Goose or an AI for them), a wizard's, a plugin's. */
|
|
24
|
+
id: z.string().min(1).max(RWX_LIMITS.id).optional(),
|
|
25
|
+
/** A wizard's run: the person it is held for; left out, a guest. */
|
|
26
|
+
for: z.string().min(1).max(RWX_LIMITS.id).optional(),
|
|
27
|
+
resource: z.enum(RWX_ASK_KINDS),
|
|
28
|
+
resourceId: z.string().min(1).max(RWX_LIMITS.id).optional(),
|
|
29
|
+
perm: z.enum(RWX_PERMS),
|
|
30
|
+
});
|
|
15
31
|
export const ruleRoutes = new Hono()
|
|
16
|
-
.get("/spaces/:id/rules", async (c) =>
|
|
17
|
-
.
|
|
18
|
-
const
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
32
|
+
.get("/spaces/:id/rules", async (c) => {
|
|
33
|
+
const user = c.get("user");
|
|
34
|
+
const space = await rulesSpace(user.id, c.req.param("id"));
|
|
35
|
+
const rules = await listRules(user.id, space.id);
|
|
36
|
+
return c.json({ rules: await describeRules(space.id, rules, await peopleOf(user)) });
|
|
37
|
+
})
|
|
38
|
+
// What a rule and the question pick from. Before `:ruleId`, which would take it for a rule.
|
|
39
|
+
.get("/spaces/:id/rules/choices", async (c) => {
|
|
40
|
+
const user = c.get("user");
|
|
41
|
+
const space = await rulesSpace(user.id, c.req.param("id"));
|
|
42
|
+
return c.json(await ruleChoices(space.id, await peopleOf(user)));
|
|
43
|
+
})
|
|
44
|
+
.get("/spaces/:id/rules/ask", async (c) => {
|
|
45
|
+
const user = c.get("user");
|
|
46
|
+
const space = await rulesSpace(user.id, c.req.param("id"));
|
|
47
|
+
const { decision, rule } = await askRule(user.id, space.id, askSchema.parse(c.req.query()));
|
|
48
|
+
const [described] = rule ? await describeRules(space.id, [rule], await peopleOf(user)) : [];
|
|
49
|
+
const answer = { ok: decision.ok, rule: described ?? null, reason: decision.reason };
|
|
50
|
+
return c.json(answer);
|
|
51
|
+
})
|
|
52
|
+
.post("/spaces/:id/rules", async (c) => {
|
|
53
|
+
const user = c.get("user");
|
|
54
|
+
const space = await rulesSpace(user.id, c.req.param("id"));
|
|
55
|
+
const rule = await addRule(user.id, space.id, ruleSchema.parse(await c.req.json()));
|
|
56
|
+
const [described] = await describeRules(space.id, [rule], await peopleOf(user));
|
|
57
|
+
return c.json({ rule: described });
|
|
58
|
+
})
|
|
59
|
+
.patch("/spaces/:id/rules/:ruleId", async (c) => {
|
|
60
|
+
const user = c.get("user");
|
|
61
|
+
const space = await rulesSpace(user.id, c.req.param("id"));
|
|
62
|
+
const flags = flagsSchema.parse(await c.req.json());
|
|
63
|
+
const rule = await changeRule(user.id, space.id, c.req.param("ruleId"), flags);
|
|
64
|
+
const [described] = await describeRules(space.id, [rule], await peopleOf(user));
|
|
65
|
+
return c.json({ rule: described });
|
|
22
66
|
})
|
|
23
67
|
.delete("/spaces/:id/rules/:ruleId", async (c) => {
|
|
24
68
|
await deleteRule(c.get("user").id, c.req.param("id"), c.req.param("ruleId"));
|
|
@@ -25,7 +25,8 @@ import { createLocalKey, deleteLocalKey, listLocalKeys } from "../auth/keys.js";
|
|
|
25
25
|
import { assertRwx, folderAudience, setFolderAudience, subjectsOfPerson } from "../broker/rwx.js";
|
|
26
26
|
import { appStates, connectApps } from "../cli/connect.js";
|
|
27
27
|
import { layout } from "../cli/home.js";
|
|
28
|
-
import { connectorImportSchema, importConnector, previewSource,
|
|
28
|
+
import { actionKindsPatchSchema, connectorImportSchema, connectorPreviewSchema, importConnector, previewSource, registryService, removeConnector, searchRegistry, setActionKinds, } from "../connectors/external.js";
|
|
29
|
+
import { reloadConnector } from "../connectors/reload.js";
|
|
29
30
|
import { balanceCredits, canSpend } from "../credits/credits.js";
|
|
30
31
|
import { estimateRun } from "../credits/estimate.js";
|
|
31
32
|
import { missingModels, stepsWithoutModel } from "../engine/requirements.js";
|
|
@@ -55,7 +56,7 @@ import { notFound, ServiceError } from "../services/errors.js";
|
|
|
55
56
|
import { deleteFile, listFiles, readFile, writeFile } from "../services/files.js";
|
|
56
57
|
import { categoryContents, listKnowledge, resolvePath, valueContents, } from "../services/knowledge.js";
|
|
57
58
|
import { writeSummary } from "../services/knowledge-model.js";
|
|
58
|
-
import { closedToMe } from "../services/members-studio.js";
|
|
59
|
+
import { closedToMe, spaceOfItem, studioSpaces } from "../services/members-studio.js";
|
|
59
60
|
import { applyAddresses, finishOnboarding, onboardingFor, startingName, } from "../services/onboarding.js";
|
|
60
61
|
import { findAddresses, siteOfEmail } from "../services/onboarding-find.js";
|
|
61
62
|
import { setOrganizationContext } from "../services/organization-context.js";
|
|
@@ -833,15 +834,10 @@ export const studio = new Hono()
|
|
|
833
834
|
return c.json(await searchRegistry(query));
|
|
834
835
|
})
|
|
835
836
|
.get("/connectors/registry/:domain", async (c) => c.json(await registryService(c.req.param("domain"))))
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
sourceKind: z.enum(["openapi", "mcp"]),
|
|
841
|
-
sourceUrl: z.string().url(),
|
|
842
|
-
})
|
|
843
|
-
.parse(await c.req.json());
|
|
844
|
-
return c.json(await previewSource(body));
|
|
837
|
+
// Reads an address before it is imported: for admins of a space that can be changed here.
|
|
838
|
+
.post("/spaces/:id/connectors/preview", async (c) => {
|
|
839
|
+
const space = await ownedSpace(c.get("user").id, c.req.param("id"));
|
|
840
|
+
return c.json(await previewSource(space.id, connectorPreviewSchema.parse(await c.req.json())));
|
|
845
841
|
})
|
|
846
842
|
.get("/spaces/:id/connectors", async (c) => c.json(await connectorsView(reader(c), c.req.param("id"))))
|
|
847
843
|
.post("/spaces/:id/connectors", async (c) => {
|
|
@@ -850,8 +846,16 @@ export const studio = new Hono()
|
|
|
850
846
|
return c.json(await importConnector(user.id, space.id, connectorImportSchema.parse(await c.req.json())));
|
|
851
847
|
})
|
|
852
848
|
.post("/spaces/:id/connectors/:connectorId/refresh", async (c) => {
|
|
853
|
-
const
|
|
854
|
-
|
|
849
|
+
const user = c.get("user");
|
|
850
|
+
const space = await ownedSpace(user.id, c.req.param("id"));
|
|
851
|
+
return c.json(await reloadConnector(user.id, space.id, c.req.param("connectorId")));
|
|
852
|
+
})
|
|
853
|
+
// What single actions of an imported connector do, as an admin says it.
|
|
854
|
+
.patch("/spaces/:id/connectors/:connectorId/actions", async (c) => {
|
|
855
|
+
const user = c.get("user");
|
|
856
|
+
const space = await ownedSpace(user.id, c.req.param("id"));
|
|
857
|
+
const { actions } = actionKindsPatchSchema.parse(await c.req.json());
|
|
858
|
+
return c.json(await setActionKinds(user.id, space.id, c.req.param("connectorId"), actions));
|
|
855
859
|
})
|
|
856
860
|
.delete("/spaces/:id/connectors/:connectorId", async (c) => {
|
|
857
861
|
const space = await ownedSpace(c.get("user").id, c.req.param("id"));
|
|
@@ -1258,8 +1262,8 @@ export const studio = new Hono()
|
|
|
1258
1262
|
const body = z
|
|
1259
1263
|
.object({ definition: z.unknown(), baseRevision: z.number().int().min(0) })
|
|
1260
1264
|
.parse(await c.req.json());
|
|
1261
|
-
const { revision, issues } = await writeDraft(c.get("user").id, c.req.param("id"), body);
|
|
1262
|
-
return c.json({ ok: true, revision, issues });
|
|
1265
|
+
const { revision, issues, warnings } = await writeDraft(c.get("user").id, c.req.param("id"), body);
|
|
1266
|
+
return c.json({ ok: true, revision, issues, warnings });
|
|
1263
1267
|
})
|
|
1264
1268
|
.patch("/wizards/:id", async (c) => {
|
|
1265
1269
|
const patch = z
|
|
@@ -1276,6 +1280,7 @@ export const studio = new Hono()
|
|
|
1276
1280
|
// The copy in the cloud of a linked account is shared the same way.
|
|
1277
1281
|
if (patch.shareEnabled !== undefined ||
|
|
1278
1282
|
patch.dailyRunLimit !== undefined ||
|
|
1283
|
+
patch.dailyMailLimit !== undefined ||
|
|
1279
1284
|
patch.runners !== undefined ||
|
|
1280
1285
|
patch.translate !== undefined) {
|
|
1281
1286
|
await pushSharing(c.get("user").id, c.req.param("id"));
|
|
@@ -1379,7 +1384,18 @@ export const studio = new Hono()
|
|
|
1379
1384
|
})
|
|
1380
1385
|
// --- the two-way sync of the spaces with the account's organization (sync/client.ts) ---
|
|
1381
1386
|
// --- who is in a wizard, page or table: a signal, never a lock (docs/plans/live-changes.md, 8) ---
|
|
1382
|
-
.get("/presence/:kind", async (c) =>
|
|
1387
|
+
.get("/presence/:kind", async (c) => {
|
|
1388
|
+
const kind = z.enum(PRESENCE_KINDS).parse(c.req.param("kind"));
|
|
1389
|
+
const present = await presentByItem(kind);
|
|
1390
|
+
// A member sees who is in the items of the spaces whose Studio is open to them.
|
|
1391
|
+
const open = await studioSpaces();
|
|
1392
|
+
for (const item of open ? Object.keys(present) : []) {
|
|
1393
|
+
if (!open?.has((await spaceOfItem("presence", kind, item)) ?? "")) {
|
|
1394
|
+
delete present[item];
|
|
1395
|
+
}
|
|
1396
|
+
}
|
|
1397
|
+
return c.json(present);
|
|
1398
|
+
})
|
|
1383
1399
|
.get("/presence/:kind/:item", async (c) => c.json(await presentIn(z.enum(PRESENCE_KINDS).parse(c.req.param("kind")), c.req.param("item"))))
|
|
1384
1400
|
.put("/presence", async (c) => {
|
|
1385
1401
|
const user = c.get("user");
|
|
@@ -1591,16 +1607,16 @@ export const studio = new Hono()
|
|
|
1591
1607
|
// Not done is an answer too: the app's file is no plain JSON, here is what to paste.
|
|
1592
1608
|
return c.json(done.outcome);
|
|
1593
1609
|
})
|
|
1594
|
-
// What each AI client did with the MCP server
|
|
1595
|
-
.get("/integrations/seen", (c) => c.json(seenApps(c.get("user").tenantId)))
|
|
1610
|
+
// What each AI client did with the MCP server: the test on "Integrate".
|
|
1611
|
+
.get("/integrations/seen", async (c) => c.json(await seenApps(c.get("user").tenantId)))
|
|
1596
1612
|
// The apps members used on the spaces, allowed or refused by the organization's model policy.
|
|
1597
1613
|
// Who used which app is for the organization's owners and admins.
|
|
1598
|
-
.get("/model-policy/apps", (c) => {
|
|
1614
|
+
.get("/model-policy/apps", async (c) => {
|
|
1599
1615
|
const user = c.get("user");
|
|
1600
1616
|
if (!mayChangeModels(user)) {
|
|
1601
1617
|
return c.json({ error: say(c, "onlyOrganizationAdminsChange"), code: "forbidden" }, 403);
|
|
1602
1618
|
}
|
|
1603
|
-
return c.json({ apps: checkedApps(user.tenantId) });
|
|
1619
|
+
return c.json({ apps: await checkedApps(user.tenantId) });
|
|
1604
1620
|
})
|
|
1605
1621
|
.get("/local/models", (c) => (managed ? c.notFound() : c.json(localModelSettings())))
|
|
1606
1622
|
.put("/local/models", async (c) => {
|
|
@@ -3,6 +3,7 @@ import { standaloneEntry } from "@engenty/wizards-shared/fit";
|
|
|
3
3
|
import { pluginsOf } from "@engenty/wizards-shared/marketplace";
|
|
4
4
|
import { noteText } from "@engenty/wizards-shared/run";
|
|
5
5
|
import { and, count, desc, eq, gte, inArray, isNotNull, or, sql } from "drizzle-orm";
|
|
6
|
+
import { subjectsOfPerson } from "../broker/rwx.js";
|
|
6
7
|
import { MICROS_PER_CREDIT } from "../credits/credits.js";
|
|
7
8
|
import { db, schema } from "../db/client.js";
|
|
8
9
|
import { env } from "../env.js";
|
|
@@ -10,7 +11,7 @@ import { wizardUnavailable } from "../limits.js";
|
|
|
10
11
|
import { codeOf } from "../tenants/control.js";
|
|
11
12
|
import { currentTenant } from "../tenants/tenant.js";
|
|
12
13
|
import { serverText } from "../texts.js";
|
|
13
|
-
import { mayBuild, READ_ONLY_TENANT, spaceWritable } from "./access.js";
|
|
14
|
+
import { mayBuild, READ_ONLY_TENANT, roleOf, spaceWritable } from "./access.js";
|
|
14
15
|
import { mainLogoId } from "./brand.js";
|
|
15
16
|
import { notFound, ServiceError } from "./errors.js";
|
|
16
17
|
import { knowledgeCounts } from "./knowledge.js";
|
|
@@ -70,7 +71,8 @@ export async function apiSpaceDetails(userId, spaceId) {
|
|
|
70
71
|
colors: p.brand.colors ?? [],
|
|
71
72
|
facts: p.facts.map(({ label, value }) => ({ label, value })),
|
|
72
73
|
logoUrl: logo ? `${env.publicUrl}/api/public/logos/${logo}` : null,
|
|
73
|
-
|
|
74
|
+
// How much of it the caller may read.
|
|
75
|
+
knowledge: await knowledgeCounts(p.id, subjectsOfPerson(userId, await roleOf(userId))),
|
|
74
76
|
writable: await spaceWritable(p),
|
|
75
77
|
studioUrl: `${env.appUrl}/studio/space`,
|
|
76
78
|
};
|
|
@@ -255,6 +255,7 @@ export async function syncToCloud(userId, wizardId) {
|
|
|
255
255
|
files,
|
|
256
256
|
shareEnabled: w.shareEnabled,
|
|
257
257
|
dailyRunLimit: w.dailyRunLimit,
|
|
258
|
+
dailyMailLimit: w.dailyMailLimit,
|
|
258
259
|
themes: themesOf(version.definition.themes, (await ownedSpace(userId, w.spaceId)).themes),
|
|
259
260
|
}, 120_000);
|
|
260
261
|
if (!answer.ok || !answer.body.shareUrl) {
|
|
@@ -323,6 +324,7 @@ export async function pushSharing(userId, wizardId) {
|
|
|
323
324
|
await call("PATCH", `/spaces/${w.spaceId}/wizards/${w.id}`, {
|
|
324
325
|
shareEnabled: w.shareEnabled,
|
|
325
326
|
dailyRunLimit: w.dailyRunLimit,
|
|
327
|
+
dailyMailLimit: w.dailyMailLimit,
|
|
326
328
|
translate: w.translate,
|
|
327
329
|
...(w.runners ? { runners: w.runners } : {}),
|
|
328
330
|
}).catch((err) => console.error("[cloud] sharing not sent:", err.message));
|
|
@@ -1,12 +1,85 @@
|
|
|
1
|
+
import { AsyncResource } from "node:async_hooks";
|
|
1
2
|
import { EventEmitter } from "node:events";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
import { and, asc, eq, gt, lt, max } from "drizzle-orm";
|
|
4
|
+
import { db } from "../db/client.js";
|
|
5
|
+
import * as schema from "../db/schema.js";
|
|
6
|
+
/** How often a subscriber looks for what another process wrote. */
|
|
7
|
+
const LOOK_MS = 2000;
|
|
8
|
+
/** A subscriber reads a change within seconds; a reconnect catches up on the revision. */
|
|
9
|
+
const KEEP_MS = 3600_000;
|
|
10
|
+
/** Wakes this process's subscribers at once; those of another process find the row on their look. */
|
|
11
|
+
const wake = new EventEmitter();
|
|
12
|
+
wake.setMaxListeners(0);
|
|
13
|
+
/**
|
|
14
|
+
* In the tenant's database, so the studio hears what the process answering MCP wrote
|
|
15
|
+
* (RUNTIME_ROLE). A notice lost is a notice lost: the write it tells of stands.
|
|
16
|
+
*/
|
|
17
|
+
export async function emitDraftChanged(change) {
|
|
18
|
+
try {
|
|
19
|
+
await db.insert(schema.draftChange).values({ wizardId: change.wizardId, change });
|
|
20
|
+
wake.emit(change.wizardId);
|
|
21
|
+
}
|
|
22
|
+
catch (err) {
|
|
23
|
+
console.error("[draft-events]", err.message);
|
|
24
|
+
}
|
|
6
25
|
}
|
|
26
|
+
/** Hears the changes to a wizard from now on, in the current tenant's context. */
|
|
7
27
|
export function subscribeDraft(wizardId, listener) {
|
|
8
|
-
|
|
9
|
-
|
|
28
|
+
const t = schema.draftChange;
|
|
29
|
+
let stopped = false;
|
|
30
|
+
let reading = false;
|
|
31
|
+
let again = false;
|
|
32
|
+
let seen = null;
|
|
33
|
+
// The tenant's context stays with the reader, whoever wakes it: ids are unique per tenant only.
|
|
34
|
+
const read = AsyncResource.bind(async () => {
|
|
35
|
+
if (reading) {
|
|
36
|
+
again = true;
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
reading = true;
|
|
40
|
+
try {
|
|
41
|
+
if (seen === null) {
|
|
42
|
+
const [newest] = await db.select({ id: max(t.id) }).from(t);
|
|
43
|
+
seen = newest?.id ?? 0;
|
|
44
|
+
}
|
|
45
|
+
do {
|
|
46
|
+
again = false;
|
|
47
|
+
const after = seen ?? 0;
|
|
48
|
+
const rows = await db
|
|
49
|
+
.select()
|
|
50
|
+
.from(t)
|
|
51
|
+
.where(and(eq(t.wizardId, wizardId), gt(t.id, after)))
|
|
52
|
+
.orderBy(asc(t.id));
|
|
53
|
+
for (const row of rows) {
|
|
54
|
+
seen = row.id;
|
|
55
|
+
if (!stopped) {
|
|
56
|
+
listener(row.change);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
} while (again && !stopped);
|
|
60
|
+
}
|
|
61
|
+
catch (err) {
|
|
62
|
+
console.error("[draft-events]", err.message);
|
|
63
|
+
}
|
|
64
|
+
finally {
|
|
65
|
+
reading = false;
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
const timer = setInterval(() => void read(), LOOK_MS);
|
|
69
|
+
timer.unref();
|
|
70
|
+
wake.on(wizardId, read);
|
|
71
|
+
void read();
|
|
72
|
+
return () => {
|
|
73
|
+
stopped = true;
|
|
74
|
+
clearInterval(timer);
|
|
75
|
+
wake.off(wizardId, read);
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
/** Deletes notices nobody needs any more, in the current tenant's context. */
|
|
79
|
+
export async function pruneDraftChanges(now = Date.now()) {
|
|
80
|
+
await db
|
|
81
|
+
.delete(schema.draftChange)
|
|
82
|
+
.where(lt(schema.draftChange.createdAt, new Date(now - KEEP_MS)));
|
|
10
83
|
}
|
|
11
84
|
/** Steps that are new or differ in `after`. */
|
|
12
85
|
export function changedSteps(before, after) {
|
|
@@ -73,7 +73,7 @@ export async function writeFile(userId, wizardId, rawPath, content, mime) {
|
|
|
73
73
|
set: { hash: file.hash, mime: file.mime, size: file.size, updatedAt: new Date() },
|
|
74
74
|
});
|
|
75
75
|
await touch(w.id);
|
|
76
|
-
emitDraftChanged(filesChanged(w, path));
|
|
76
|
+
await emitDraftChanged(filesChanged(w, path));
|
|
77
77
|
return file;
|
|
78
78
|
}
|
|
79
79
|
/**
|
|
@@ -136,7 +136,7 @@ export async function deleteFile(userId, wizardId, rawPath) {
|
|
|
136
136
|
throw notFound();
|
|
137
137
|
}
|
|
138
138
|
await touch(w.id);
|
|
139
|
-
emitDraftChanged(filesChanged(w, path));
|
|
139
|
+
await emitDraftChanged(filesChanged(w, path));
|
|
140
140
|
}
|
|
141
141
|
/** Copies a workspace onto another wizard (duplicate). Blobs are shared, only rows are new. */
|
|
142
142
|
export async function copyFiles(fromWizardId, toWizardId) {
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { formatTableCell } from "@engenty/wizards-shared/engenty/data-tables";
|
|
2
2
|
import { slugOf, } from "@engenty/wizards-shared/knowledge";
|
|
3
3
|
import { and, asc, count, eq, inArray, isNotNull, isNull, sql } from "drizzle-orm";
|
|
4
|
-
import { assertRwx, pageResources, readable, tableResources } from "../broker/rwx.js";
|
|
4
|
+
import { assertRwx, brokerOn, pageResources, readable, readableMounts, tableResources, } from "../broker/rwx.js";
|
|
5
5
|
import { db, schema } from "../db/client.js";
|
|
6
6
|
import { embeddingModel, systemOneAccess } from "../models.js";
|
|
7
7
|
import { prompt } from "../prompts.js";
|
|
8
8
|
import { notFound, ServiceError } from "./errors.js";
|
|
9
|
-
import { categoryLines, categoryRows, dateOf, filterItems, itemCategoriesOf, listCategories, numberOf, } from "./space-categories.js";
|
|
9
|
+
import { categoriesOver, categoryLines, categoryRows, categoryUse, dateOf, filterItems, itemCategoriesOf, listCategories, numberOf, } from "./space-categories.js";
|
|
10
10
|
import { ownedSpace } from "./spaces.js";
|
|
11
11
|
/** Gives each item without a slug one, unique among its siblings, and keeps it. */
|
|
12
12
|
async function slugsFor(rows, siblingsOf, save) {
|
|
@@ -519,8 +519,11 @@ export async function readPage(spaceId, path, opts, who) {
|
|
|
519
519
|
const node = tree.get(page.id);
|
|
520
520
|
const categories = await categoryRows(spaceId);
|
|
521
521
|
const lines = categoryLines(categories, (await itemCategoriesOf([{ pageId: page.id }])).get(`p:${page.id}`));
|
|
522
|
-
|
|
523
|
-
|
|
522
|
+
// Its sub-pages, as far as `who` may read them: one closed to them is not named.
|
|
523
|
+
const under = [...tree.values()].filter((n) => n.parentId === page.id);
|
|
524
|
+
const okUnder = await readable(spaceId, who, await pageResources(under.map((n) => n.id)));
|
|
525
|
+
const children = under
|
|
526
|
+
.filter((n) => okUnder.has(n.id))
|
|
524
527
|
.sort((a, b) => a.position - b.position)
|
|
525
528
|
.map((n) => n.path);
|
|
526
529
|
const original = page.fileId ? (await filePaths(spaceId)).get(page.fileId) : undefined;
|
|
@@ -650,11 +653,10 @@ export async function readTable(spaceId, path, opts, who) {
|
|
|
650
653
|
* has; with one, the items it leaves that `who` may read, with their paths and categories.
|
|
651
654
|
*/
|
|
652
655
|
export async function listForStep(spaceId, where, who) {
|
|
653
|
-
const categories = await listCategories(spaceId);
|
|
654
|
-
const taken = categories.filter((c) => !c.proposed);
|
|
655
656
|
if (!Object.keys(where ?? {}).length) {
|
|
657
|
+
const categories = (await categoriesFor(spaceId, who)).filter((c) => !c.proposed);
|
|
656
658
|
return {
|
|
657
|
-
categories:
|
|
659
|
+
categories: categories.map((c) => ({
|
|
658
660
|
name: c.name,
|
|
659
661
|
type: c.type,
|
|
660
662
|
...(c.unit ? { unit: c.unit } : {}),
|
|
@@ -667,6 +669,7 @@ export async function listForStep(spaceId, where, who) {
|
|
|
667
669
|
hint: 'Pass `where` to list the items of values, e.g. { "Baustelle": "Graz Süd" }.',
|
|
668
670
|
};
|
|
669
671
|
}
|
|
672
|
+
const taken = (await categoryRows(spaceId)).filter((c) => !c.proposed);
|
|
670
673
|
const filtered = await filterItems(spaceId, where);
|
|
671
674
|
const [tree, tPaths, fPaths] = await Promise.all([
|
|
672
675
|
pageTree(spaceId),
|
|
@@ -729,34 +732,97 @@ export async function listForStep(spaceId, where, who) {
|
|
|
729
732
|
];
|
|
730
733
|
return { items: items.slice(0, 200), total: items.length };
|
|
731
734
|
}
|
|
732
|
-
/**
|
|
733
|
-
|
|
735
|
+
/**
|
|
736
|
+
* The space's categories as `who` sees them: how many items have each, a choice's values and the
|
|
737
|
+
* ranges, counted over the pages, tables, files and mounts they may read. Whoever may read all of
|
|
738
|
+
* it gets them as the space has them.
|
|
739
|
+
*/
|
|
740
|
+
export async function categoriesFor(spaceId, who) {
|
|
741
|
+
const all = await listCategories(spaceId);
|
|
742
|
+
if (!(all.length && (await brokerOn()))) {
|
|
743
|
+
return all;
|
|
744
|
+
}
|
|
745
|
+
const use = await categoryUse(spaceId);
|
|
746
|
+
const places = [...use.items, ...use.values];
|
|
747
|
+
const ids = (key) => [
|
|
748
|
+
...new Set(places.flatMap((p) => (p[key] ? [p[key]] : []))),
|
|
749
|
+
];
|
|
750
|
+
const pages = await readable(spaceId, who, await pageResources(ids("pageId")));
|
|
751
|
+
const tables = await readable(spaceId, who, await tableResources(ids("tableId")));
|
|
752
|
+
const files = await readable(spaceId, who, ids("fileId").map((id) => ({ kind: "document", id })));
|
|
753
|
+
const mounts = await readableMounts(spaceId, who, ids("mountId"));
|
|
754
|
+
const open = (p) => p.pageId
|
|
755
|
+
? pages.has(p.pageId)
|
|
756
|
+
: p.tableId
|
|
757
|
+
? tables.has(p.tableId)
|
|
758
|
+
: p.fileId
|
|
759
|
+
? files.has(p.fileId)
|
|
760
|
+
: p.mountId
|
|
761
|
+
? mounts.has(p.mountId)
|
|
762
|
+
: false;
|
|
763
|
+
if (places.every(open)) {
|
|
764
|
+
return all;
|
|
765
|
+
}
|
|
766
|
+
return categoriesOver(all, { items: use.items.filter(open), values: use.values.filter(open) });
|
|
767
|
+
}
|
|
768
|
+
/**
|
|
769
|
+
* Which kinds of Knowledge a space holds at all: which tools a caller is offered. It says nothing
|
|
770
|
+
* of what they may read: each read of a tool is the broker's, and a refusal names the item.
|
|
771
|
+
*/
|
|
772
|
+
export async function knowledgeKinds(spaceId) {
|
|
773
|
+
const [page, table, file] = await Promise.all([
|
|
774
|
+
db.query.spacePage.findFirst({
|
|
775
|
+
where: and(eq(schema.spacePage.spaceId, spaceId), isNull(schema.spacePage.wizardId)),
|
|
776
|
+
columns: { id: true },
|
|
777
|
+
}),
|
|
778
|
+
db.query.spaceTable.findFirst({
|
|
779
|
+
where: and(eq(schema.spaceTable.spaceId, spaceId), isNull(schema.spaceTable.wizardId)),
|
|
780
|
+
columns: { id: true },
|
|
781
|
+
}),
|
|
782
|
+
db.query.spaceFile.findFirst({
|
|
783
|
+
where: and(eq(schema.spaceFile.spaceId, spaceId), eq(schema.spaceFile.kind, "document")),
|
|
784
|
+
columns: { id: true },
|
|
785
|
+
}),
|
|
786
|
+
]);
|
|
787
|
+
return { pages: Boolean(page), tables: Boolean(table), files: Boolean(file) };
|
|
788
|
+
}
|
|
789
|
+
/**
|
|
790
|
+
* How much Knowledge a space holds for `who`: the pages, tables and documents they may read. What
|
|
791
|
+
* a step's instructions, Goose and the space's details say counts nothing else.
|
|
792
|
+
*/
|
|
793
|
+
export async function knowledgeCounts(spaceId, who) {
|
|
734
794
|
const [pages, tables, files] = await Promise.all([
|
|
735
|
-
db
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
db
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
db
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
795
|
+
db.query.spacePage.findMany({
|
|
796
|
+
where: and(eq(schema.spacePage.spaceId, spaceId), isNull(schema.spacePage.wizardId)),
|
|
797
|
+
columns: { id: true, fileId: true },
|
|
798
|
+
}),
|
|
799
|
+
db.query.spaceTable.findMany({
|
|
800
|
+
where: and(eq(schema.spaceTable.spaceId, spaceId), isNull(schema.spaceTable.wizardId)),
|
|
801
|
+
columns: { id: true, fileId: true },
|
|
802
|
+
}),
|
|
803
|
+
db.query.spaceFile.findMany({
|
|
804
|
+
where: and(eq(schema.spaceFile.spaceId, spaceId), eq(schema.spaceFile.kind, "document")),
|
|
805
|
+
columns: { id: true },
|
|
806
|
+
}),
|
|
807
|
+
]);
|
|
808
|
+
const ok = await readable(spaceId, who, [
|
|
809
|
+
...pages.map((p) => ({ kind: "page", id: p.id, fileId: p.fileId })),
|
|
810
|
+
...tables.map((t) => ({ kind: "table", id: t.id, fileId: t.fileId })),
|
|
811
|
+
...files.map((f) => ({ kind: "document", id: f.id })),
|
|
747
812
|
]);
|
|
748
|
-
|
|
813
|
+
const read = (rows) => rows.filter((r) => ok.has(r.id)).length;
|
|
814
|
+
return { pages: read(pages), tables: read(tables), files: read(files) };
|
|
749
815
|
}
|
|
750
816
|
/**
|
|
751
|
-
* What
|
|
752
|
-
* by, the tools to find and read. Empty when
|
|
817
|
+
* What a step of the space is told about Knowledge: how much of it `who` may read, the categories
|
|
818
|
+
* to filter by as they see them, the tools to find and read. Empty when that is nothing.
|
|
753
819
|
*/
|
|
754
|
-
export async function knowledgeBlock(spaceId) {
|
|
755
|
-
const counts = await knowledgeCounts(spaceId);
|
|
820
|
+
export async function knowledgeBlock(spaceId, who) {
|
|
821
|
+
const counts = await knowledgeCounts(spaceId, who);
|
|
756
822
|
if (!(counts.pages || counts.tables || counts.files)) {
|
|
757
823
|
return "";
|
|
758
824
|
}
|
|
759
|
-
const categories = (await
|
|
825
|
+
const categories = (await categoriesFor(spaceId, who)).filter((c) => !c.proposed && c.count);
|
|
760
826
|
const what = [
|
|
761
827
|
counts.pages ? `${counts.pages} pages` : "",
|
|
762
828
|
counts.tables ? `${counts.tables} tables` : "",
|
|
@@ -61,9 +61,10 @@ const PUBLISHING = [
|
|
|
61
61
|
];
|
|
62
62
|
/**
|
|
63
63
|
* The space of an item, by the kind and id the studio's addresses name it with
|
|
64
|
-
* (`/spaces/:id`, `/wizards/:id`, …; `runs` for a run's wizard), and what follows them.
|
|
64
|
+
* (`/spaces/:id`, `/wizards/:id`, …; `runs` for a run's wizard), and what follows them. `null`
|
|
65
|
+
* for what is in no space, or in none that is still there.
|
|
65
66
|
*/
|
|
66
|
-
async function spaceOfItem(kind, id, sub) {
|
|
67
|
+
export async function spaceOfItem(kind, id, sub) {
|
|
67
68
|
const one = async (found) => (await found)?.spaceId ?? null;
|
|
68
69
|
const tenant = currentTenant();
|
|
69
70
|
switch (kind) {
|
|
@@ -120,6 +121,9 @@ async function spaceOfItem(kind, id, sub) {
|
|
|
120
121
|
where: eq(schema.spaceConnection.id, id),
|
|
121
122
|
columns: { spaceId: true },
|
|
122
123
|
}));
|
|
124
|
+
case "presence":
|
|
125
|
+
// Who is in a wizard, page or table (`/presence/:kind/:item`) is in that item's space.
|
|
126
|
+
return sub ? spaceOfItem(`${id}s`, sub) : null;
|
|
123
127
|
default:
|
|
124
128
|
return null;
|
|
125
129
|
}
|
|
@@ -131,6 +135,22 @@ async function spaceOfItem(kind, id, sub) {
|
|
|
131
135
|
export async function closedToMe(spaceId) {
|
|
132
136
|
return (await ruledMember()) && !(await openToMembers(spaceId));
|
|
133
137
|
}
|
|
138
|
+
/**
|
|
139
|
+
* The spaces whose Studio the person at hand reaches, where the rule narrows them: the ones open
|
|
140
|
+
* to members. `null` for everyone the rule does not count for, who reaches every space. For what
|
|
141
|
+
* is sent unasked (the live stream, the sync's listing): a space that is not among them, closed
|
|
142
|
+
* or gone, is not named.
|
|
143
|
+
*/
|
|
144
|
+
export async function studioSpaces() {
|
|
145
|
+
if (!(await ruledMember())) {
|
|
146
|
+
return null;
|
|
147
|
+
}
|
|
148
|
+
const open = await db.query.space.findMany({
|
|
149
|
+
where: and(eq(schema.space.tenantId, currentTenant()), eq(schema.space.membersStudio, true)),
|
|
150
|
+
columns: { id: true },
|
|
151
|
+
});
|
|
152
|
+
return new Set(open.map((s) => s.id));
|
|
153
|
+
}
|
|
134
154
|
/**
|
|
135
155
|
* The studio's „closed“ answer for an item of a space closed to the person at hand: the same 403
|
|
136
156
|
* through every door (the studio API, MCP, `/api/v1`, Goose). `kind` as the studio's addresses
|