@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,8 +1,14 @@
|
|
|
1
|
+
import { desc, lt, sql } from "drizzle-orm";
|
|
2
|
+
import { db, withTenant } from "../db/client.js";
|
|
3
|
+
import * as schema from "../db/schema.js";
|
|
1
4
|
/**
|
|
2
|
-
* What each AI client did with the MCP server
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
+
* What each AI client did with the MCP server: the test on the "Integrate" page waits for a client
|
|
6
|
+
* to show up, call a tool and show the widget. In the tenant's database, as the process that
|
|
7
|
+
* answers MCP need not be the one that serves the studio (RUNTIME_ROLE). A note that can't be
|
|
8
|
+
* written is logged: the client's call goes on.
|
|
5
9
|
*/
|
|
10
|
+
/** How long an app stays known without a request. */
|
|
11
|
+
const KEEP_MS = 30 * 24 * 3600_000;
|
|
6
12
|
/** The ids the studio lists the AI apps by, and the names they give themselves (`clientInfo`). */
|
|
7
13
|
const CLIENT_NAMES = [
|
|
8
14
|
// Claude Desktop calls itself claude-ai, as claude.ai does.
|
|
@@ -24,44 +30,45 @@ const CLIENT_NAMES = [
|
|
|
24
30
|
export function appIdsOf(client) {
|
|
25
31
|
return CLIENT_NAMES.filter(([, name]) => name.test(client)).map(([id]) => id);
|
|
26
32
|
}
|
|
27
|
-
const seen = new Map();
|
|
28
33
|
/** The name a client gave on `initialize`, by its sign-in: later requests do not repeat it. */
|
|
29
34
|
const names = new Map();
|
|
30
35
|
/** Notes one MCP request: its JSON-RPC messages, from the client signed in as `signIn`. */
|
|
31
|
-
export function noteRequest(tenantId, signIn, client, body) {
|
|
36
|
+
export async function noteRequest(tenantId, signIn, client, body) {
|
|
32
37
|
const messages = (Array.isArray(body) ? body : [body]).filter((m) => Boolean(m) && typeof m === "object");
|
|
33
38
|
const info = messages.find((m) => m.method === "initialize")?.params?.clientInfo;
|
|
34
39
|
const given = info?.title || info?.name;
|
|
35
40
|
if (given) {
|
|
36
41
|
names.set(signIn, given);
|
|
37
42
|
}
|
|
38
|
-
const
|
|
43
|
+
const apps = appIdsOf(names.get(signIn) ?? client);
|
|
44
|
+
if (!apps.length) {
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
39
47
|
const now = Date.now();
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
48
|
+
const toolAt = messages.some((m) => m.method === "tools/call") ? now : null;
|
|
49
|
+
const widgetAt = messages.some((m) => m.method === "resources/read" && String(m.params?.uri ?? "").startsWith("ui://"))
|
|
50
|
+
? now
|
|
51
|
+
: null;
|
|
52
|
+
await withTenant(tenantId, async () => {
|
|
53
|
+
for (const app of apps) {
|
|
54
|
+
await db
|
|
55
|
+
.insert(schema.mcpAppSeen)
|
|
56
|
+
.values({ app, at: now, toolAt, widgetAt })
|
|
57
|
+
.onConflictDoUpdate({
|
|
58
|
+
target: schema.mcpAppSeen.app,
|
|
59
|
+
set: {
|
|
60
|
+
at: now,
|
|
61
|
+
toolAt: sql `coalesce(excluded.tool_at, ${schema.mcpAppSeen.toolAt})`,
|
|
62
|
+
widgetAt: sql `coalesce(excluded.widget_at, ${schema.mcpAppSeen.widgetAt})`,
|
|
63
|
+
},
|
|
64
|
+
});
|
|
51
65
|
}
|
|
52
|
-
|
|
53
|
-
}
|
|
66
|
+
}).catch((err) => console.error("[mcp] noting a client:", err.message));
|
|
54
67
|
}
|
|
55
68
|
/** What the tenant's clients did, by app id. */
|
|
56
|
-
export function seenApps(tenantId) {
|
|
57
|
-
const
|
|
58
|
-
|
|
59
|
-
const [tenant, id] = key.split("\n");
|
|
60
|
-
if (tenant === tenantId) {
|
|
61
|
-
out[id] = value;
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
return out;
|
|
69
|
+
export async function seenApps(tenantId) {
|
|
70
|
+
const rows = await withTenant(tenantId, () => db.select().from(schema.mcpAppSeen));
|
|
71
|
+
return Object.fromEntries(rows.map((r) => [r.app, { at: r.at, toolAt: r.toolAt, widgetAt: r.widgetAt }]));
|
|
65
72
|
}
|
|
66
73
|
/** The name a sign-in's client gave on `initialize`, else the one its sign-in carries. */
|
|
67
74
|
export function clientNameOf(signIn, client) {
|
|
@@ -82,31 +89,44 @@ export function appKind(...names) {
|
|
|
82
89
|
const ids = names.flatMap(appIdsOf);
|
|
83
90
|
return ids.length && ids.every((id) => LOCAL_APPS.has(id)) ? "local" : "subscription";
|
|
84
91
|
}
|
|
85
|
-
const checked = new Map();
|
|
86
92
|
/** Counts one tool call of an app the policy allowed or refused. */
|
|
87
|
-
export function noteChecked(tenantId, app, person, allowed, kind) {
|
|
88
|
-
const
|
|
89
|
-
const
|
|
93
|
+
export async function noteChecked(tenantId, app, person, allowed, kind) {
|
|
94
|
+
const now = Date.now();
|
|
95
|
+
const t = schema.mcpAppCheck;
|
|
96
|
+
await withTenant(tenantId, () => db
|
|
97
|
+
.insert(t)
|
|
98
|
+
.values({
|
|
90
99
|
app,
|
|
100
|
+
person: person ?? "",
|
|
91
101
|
kind,
|
|
92
|
-
|
|
93
|
-
allowed:
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
102
|
+
allowed: allowed ? 1 : 0,
|
|
103
|
+
refused: allowed ? 0 : 1,
|
|
104
|
+
at: now,
|
|
105
|
+
})
|
|
106
|
+
.onConflictDoUpdate({
|
|
107
|
+
target: [t.app, t.person],
|
|
108
|
+
set: {
|
|
109
|
+
kind,
|
|
110
|
+
at: now,
|
|
111
|
+
allowed: sql `${t.allowed} + excluded.allowed`,
|
|
112
|
+
refused: sql `${t.refused} + excluded.refused`,
|
|
113
|
+
},
|
|
114
|
+
})).catch((err) => console.error("[mcp] noting an app's check:", err.message));
|
|
115
|
+
}
|
|
116
|
+
/** The apps the tenant's members used on its spaces, latest first. */
|
|
117
|
+
export async function checkedApps(tenantId) {
|
|
118
|
+
const rows = await withTenant(tenantId, () => db.select().from(schema.mcpAppCheck).orderBy(desc(schema.mcpAppCheck.at)));
|
|
119
|
+
return rows.map((r) => ({
|
|
120
|
+
app: r.app,
|
|
121
|
+
kind: r.kind,
|
|
122
|
+
person: r.person || null,
|
|
123
|
+
allowed: r.allowed,
|
|
124
|
+
refused: r.refused,
|
|
125
|
+
at: r.at,
|
|
126
|
+
}));
|
|
105
127
|
}
|
|
106
|
-
/**
|
|
107
|
-
export function
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
.map(([, value]) => value)
|
|
111
|
-
.sort((a, b) => b.at - a.at);
|
|
128
|
+
/** Forgets what is older than `KEEP_MS`, in the current tenant's context: names of people among it. */
|
|
129
|
+
export async function pruneSeen(now = Date.now()) {
|
|
130
|
+
await db.delete(schema.mcpAppSeen).where(lt(schema.mcpAppSeen.at, now - KEEP_MS));
|
|
131
|
+
await db.delete(schema.mcpAppCheck).where(lt(schema.mcpAppCheck.at, now - KEEP_MS));
|
|
112
132
|
}
|
|
@@ -312,6 +312,7 @@ export function registerTools(server, who) {
|
|
|
312
312
|
dirty: s.dirty,
|
|
313
313
|
shareEnabled: s.shareEnabled,
|
|
314
314
|
dailyRunLimit: s.dailyRunLimit,
|
|
315
|
+
dailyMailLimit: s.dailyMailLimit,
|
|
315
316
|
shareUrl: s.shareUrl,
|
|
316
317
|
studioUrl: s.studioUrl,
|
|
317
318
|
};
|
|
@@ -398,19 +399,22 @@ export function registerTools(server, who) {
|
|
|
398
399
|
wizardId: z.string(),
|
|
399
400
|
enabled: z.boolean().optional(),
|
|
400
401
|
dailyRunLimit: z.number().int().min(1).max(10_000).optional(),
|
|
402
|
+
dailyMailLimit: z.number().int().min(0).max(10_000).optional(),
|
|
401
403
|
}),
|
|
402
404
|
destructive: true,
|
|
403
405
|
openWorld: true,
|
|
404
406
|
studio: true,
|
|
405
|
-
}, async ({ wizardId, enabled, dailyRunLimit }) => {
|
|
407
|
+
}, async ({ wizardId, enabled, dailyRunLimit, dailyMailLimit }) => {
|
|
406
408
|
const w = await updateWizardSettings(who.userId, wizardId, {
|
|
407
409
|
shareEnabled: enabled,
|
|
408
410
|
dailyRunLimit,
|
|
411
|
+
dailyMailLimit,
|
|
409
412
|
});
|
|
410
413
|
await pushSharing(who.userId, wizardId);
|
|
411
414
|
return {
|
|
412
415
|
shareEnabled: w.shareEnabled,
|
|
413
416
|
dailyRunLimit: w.dailyRunLimit,
|
|
417
|
+
dailyMailLimit: w.dailyMailLimit,
|
|
414
418
|
shareUrl: shareUrl(w.shareToken),
|
|
415
419
|
};
|
|
416
420
|
});
|
|
@@ -367,6 +367,24 @@ async function creditAccess(cfg, chosen) {
|
|
|
367
367
|
}
|
|
368
368
|
return { baseUrl: env.local.gatewayUrl, token, tenant: null };
|
|
369
369
|
}
|
|
370
|
+
/**
|
|
371
|
+
* Where the gateway's own tools (web search) are reached, behind `gatewaySearch`: a Manage-App's
|
|
372
|
+
* runtime always; alone, through the linked account. None: the model's own search, where it has one.
|
|
373
|
+
*/
|
|
374
|
+
export async function toolAccess() {
|
|
375
|
+
if (!feature("gatewaySearch", await remoteFeatures().catch(() => null))) {
|
|
376
|
+
return null;
|
|
377
|
+
}
|
|
378
|
+
if (managed) {
|
|
379
|
+
return {
|
|
380
|
+
baseUrl: env.manage.gatewayUrl,
|
|
381
|
+
token: env.manage.serviceKey,
|
|
382
|
+
tenant: currentTenantOrNull(),
|
|
383
|
+
};
|
|
384
|
+
}
|
|
385
|
+
const token = (await linkedAccount()) ? await accountToken() : null;
|
|
386
|
+
return token ? { baseUrl: env.local.gatewayUrl, token, tenant: null } : null;
|
|
387
|
+
}
|
|
370
388
|
/** A class goes to the credits on purpose: text on the account, or a binding that says so. */
|
|
371
389
|
function creditsChosen(cfg, cls) {
|
|
372
390
|
return (isCreditsRef(cfg.settings.bindings[cls]) ||
|
|
@@ -70,7 +70,7 @@ Replace the whole draft: for a new wizard, a rewrite, or anything edit_wizard ca
|
|
|
70
70
|
Publish the draft as a new version behind the share link. Refused while the draft has issues. Only when the person asked for it.
|
|
71
71
|
|
|
72
72
|
<!-- section: tool.set_sharing -->
|
|
73
|
-
Turn the share link on or off, or change how many runs it allows per day.
|
|
73
|
+
Turn the share link on or off, or change how many runs it allows per day and how many emails and messages its guests' runs send per day (0: none).
|
|
74
74
|
|
|
75
75
|
<!-- section: tool.start_test_run -->
|
|
76
76
|
Run the draft once with your answers. Spends the person's credits (short copy + image about 15, research about 150, video about 250). Pages are filled from `answers`, reviews accepted when acceptReviews is true. Follow it with get_test_run. Shows the flow with the run on it.
|
|
@@ -11,7 +11,7 @@ returns and when to use it.
|
|
|
11
11
|
<!-- Web: search, fetch, HTTP (tools/index.ts) -->
|
|
12
12
|
|
|
13
13
|
<!-- section: tool.web_search -->
|
|
14
|
-
Search the web.
|
|
14
|
+
Search the web. Each result has its address, title and the sentences that fit the query; read a page in full with web_fetch. Name the pages you used.
|
|
15
15
|
|
|
16
16
|
<!-- section: tool.web_fetch -->
|
|
17
17
|
Fetch a public web page or file and return its readable text (Markdown).
|
|
@@ -160,6 +160,10 @@ No file "${path}" in ${skill}. Its files: ${files}.
|
|
|
160
160
|
<!-- section: note.skill_folder -->
|
|
161
161
|
This skill's folder is in the sandbox at ${folder}: its SKILL.md and every file. Run its scripts with run_command from the working directory, e.g. python3 ${folder}/scripts/<file>.py, and install what they import first (pip install, npm install). Write what you make outside ${folder}.
|
|
162
162
|
|
|
163
|
+
<!-- In skill_load's answer for a skill a plugin brought together with a connector. `names`: the connectors; `prefixes`: what their tools' names start with. -->
|
|
164
|
+
<!-- section: note.skill_connector -->
|
|
165
|
+
This skill came together with the connector ${names}. Where this step has a connection to it, its actions are the tools whose names start with ${prefixes}. Without such a tool, follow the skill as far as it goes and say what you could not reach.
|
|
166
|
+
|
|
163
167
|
<!-- section: note.skill_scripts_refused -->
|
|
164
168
|
This skill's scripts may not run for whoever this step works for: the space's rules keep them closed. Follow its instructions without them.
|
|
165
169
|
|
|
@@ -235,6 +239,18 @@ The rules of ${service} do not allow this action here. Do not try it again or an
|
|
|
235
239
|
<!-- section: note.connector_needs_approval -->
|
|
236
240
|
This action on ${service} needs the approval of the space's admins, which cannot be asked for here. Do not try it again or another way; say in your result that it waits for them.
|
|
237
241
|
|
|
242
|
+
<!-- section: note.connector_paused -->
|
|
243
|
+
${service} is paused: an admin of the space stopped all use of it for now. Do not try it again or another way; say in your result that it waits until the connection is resumed.
|
|
244
|
+
|
|
245
|
+
<!-- section: note.connector_calls_per_run -->
|
|
246
|
+
${service} takes only so many calls from one run, and this run has made them. Do not try it again or another way; work with what you have, and say in your result what could not be done.
|
|
247
|
+
|
|
248
|
+
<!-- section: note.connector_calls_per_day -->
|
|
249
|
+
${service} takes only so many calls a day, and today's are made. Do not try it again or another way; say in your result that it can be done again tomorrow.
|
|
250
|
+
|
|
251
|
+
<!-- section: note.run_ended -->
|
|
252
|
+
This run has ended, so nothing more is called for it. Stop here; do not try it again or another way.
|
|
253
|
+
|
|
238
254
|
<!-- section: note.connector_ai_step_writes -->
|
|
239
255
|
An AI step only reads ${service}, which signs in as the space. A change there is a fixed step of the wizard, not yours; do not try it another way. Say in your result what should change.
|
|
240
256
|
|
|
@@ -26,7 +26,7 @@ import { exportWizard } from "../services/package.js";
|
|
|
26
26
|
import { siteJob, siteSchema, startSiteJob } from "../services/site.js";
|
|
27
27
|
import { checkOnServer, checkSchema, listSyncedSpaces, patchSyncedWizard, removeSyncedSpace, removeSyncedWizard, rotateSyncedLink, syncDataSchema, syncSettingsSchema, syncSpaceData, syncWizard, syncWizardSchema, } from "../services/synced-spaces.js";
|
|
28
28
|
import { createWizard, ownedWizard, publishWizard, writeDraft } from "../services/wizards.js";
|
|
29
|
-
import { adoptSpace, blobBytes, missingBlobs, publishSynced, pullChanges, pushChanges, rotateSynced, syncOverview, takeBlob, } from "../sync/hub.js";
|
|
29
|
+
import { adoptSpace, blobBytes, missingBlobs, publishSynced, pullChanges, pushChanges, rotateSynced, syncHears, syncOverview, takeBlob, } from "../sync/hub.js";
|
|
30
30
|
import { codeOf, tenantStatus } from "../tenants/control.js";
|
|
31
31
|
import { notFoundAnswer, say } from "./lang.js";
|
|
32
32
|
import { dispatchAs } from "./plugins.js";
|
|
@@ -466,7 +466,7 @@ export const apiRoutes = new Hono()
|
|
|
466
466
|
const stop = await followFor(who.tenantId, install, since, (e) => {
|
|
467
467
|
const { event, ...data } = e;
|
|
468
468
|
write(event, data, e.seq);
|
|
469
|
-
});
|
|
469
|
+
}, (changes) => asRole(who.role, () => syncHears(changes)));
|
|
470
470
|
stream.onAbort(() => {
|
|
471
471
|
closed = true;
|
|
472
472
|
stop();
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { eq, inArray } from "drizzle-orm";
|
|
2
2
|
import { Hono } from "hono";
|
|
3
3
|
import { z } from "zod";
|
|
4
|
-
import { cursorOf, decide, kindOf, LOG_PAGE, logLine, logOfSpace, readCursor, } from "../broker/index.js";
|
|
4
|
+
import { cursorOf, decide, FIXED_CHANNEL_ONLY, inAudience, kindOf, LOG_PAGE, logLine, logOfSpace, postsToChannel, readCursor, } from "../broker/index.js";
|
|
5
5
|
import { resolveConnector } from "../connectors/external.js";
|
|
6
6
|
import { connectorOfRow, listSpaceConnections, spaceConnectionById, } from "../connectors/space-connections.js";
|
|
7
7
|
import { db, schema } from "../db/client.js";
|
|
8
8
|
import { managed, tenantMembers } from "../manage.js";
|
|
9
|
-
import { isAdminRole, requireAdmin } from "../services/access.js";
|
|
9
|
+
import { currentRole, isAdminRole, requireAdmin } from "../services/access.js";
|
|
10
10
|
import { notFound } from "../services/errors.js";
|
|
11
11
|
import { userProfile } from "../services/profile.js";
|
|
12
12
|
import { ownedSpace } from "../services/spaces.js";
|
|
@@ -83,13 +83,22 @@ export function logView(row) {
|
|
|
83
83
|
criticalKind: row.criticalKind,
|
|
84
84
|
};
|
|
85
85
|
}
|
|
86
|
-
/** The
|
|
87
|
-
|
|
86
|
+
/** The person whose own lines are all they read of the log: a member. Undefined for an admin. */
|
|
87
|
+
const memberOf = (user) => managed && !isAdminRole(currentRole()) ? user.id : undefined;
|
|
88
|
+
/** The organization's people by id, with their role; alone, the one person; for a member, themselves. */
|
|
89
|
+
export async function peopleOf(user, own) {
|
|
88
90
|
if (!managed) {
|
|
89
91
|
return [{ id: user.id, name: (await userProfile(user)).name, role: "owner" }];
|
|
90
92
|
}
|
|
91
93
|
const people = await tenantMembers(currentTenant()).catch(() => null);
|
|
92
|
-
return (people?.members ?? [])
|
|
94
|
+
return (people?.members ?? [])
|
|
95
|
+
.filter((m) => !own || m.userId === own)
|
|
96
|
+
.map((m) => ({ id: m.userId, name: m.name, role: m.role }));
|
|
97
|
+
}
|
|
98
|
+
/** The space's connections the lines are named by: for a member, the ones open to them. */
|
|
99
|
+
async function connectionsOf(spaceId, own) {
|
|
100
|
+
const all = await listSpaceConnections(spaceId);
|
|
101
|
+
return own ? all.filter((c) => inAudience(c.audience, { kind: "person", id: own })) : all;
|
|
93
102
|
}
|
|
94
103
|
/** A connector, looked up once per request. */
|
|
95
104
|
function connectorCache(spaceId) {
|
|
@@ -109,9 +118,9 @@ function connectorCache(spaceId) {
|
|
|
109
118
|
* The lines with the names the page shows: who by name (a fixed step: whom its run is held for),
|
|
110
119
|
* the connection and the action by theirs, the wizard of a run, the title of a chat.
|
|
111
120
|
*/
|
|
112
|
-
async function describeLines(rows, spaceId, people) {
|
|
121
|
+
async function describeLines(rows, spaceId, people, own) {
|
|
113
122
|
const named = new Map(people.map((p) => [p.id, p]));
|
|
114
|
-
const connections = new Map((await
|
|
123
|
+
const connections = new Map((await connectionsOf(spaceId, own)).map((c) => [c.id, c]));
|
|
115
124
|
const connector = connectorCache(spaceId);
|
|
116
125
|
const ids = (pick) => [
|
|
117
126
|
...new Set(rows.map(pick).filter((id) => !!id)),
|
|
@@ -186,7 +195,7 @@ async function describeLines(rows, spaceId, people) {
|
|
|
186
195
|
}));
|
|
187
196
|
}
|
|
188
197
|
/** The ids whose names hold the search text: people, the space's connections, its wizards. */
|
|
189
|
-
async function matchesOf(q, spaceId, people) {
|
|
198
|
+
async function matchesOf(q, spaceId, people, own) {
|
|
190
199
|
const text = q.trim().toLowerCase();
|
|
191
200
|
if (!text) {
|
|
192
201
|
return undefined;
|
|
@@ -198,7 +207,7 @@ async function matchesOf(q, spaceId, people) {
|
|
|
198
207
|
.where(eq(schema.wizard.spaceId, spaceId));
|
|
199
208
|
return {
|
|
200
209
|
who: people.filter((p) => has(p.name)).map((p) => p.id),
|
|
201
|
-
connections: (await
|
|
210
|
+
connections: (await connectionsOf(spaceId, own)).filter((c) => has(c.name)).map((c) => c.id),
|
|
202
211
|
wizards: wizards.filter((w) => has(w.title)).map((w) => w.id),
|
|
203
212
|
};
|
|
204
213
|
}
|
|
@@ -222,7 +231,25 @@ export const brokerRoutes = new Hono()
|
|
|
222
231
|
...(ask.in === "run" ? { runId: "ask", mode: "live" } : {}),
|
|
223
232
|
...(ask.in === "chat" ? { chatId: "ask" } : {}),
|
|
224
233
|
};
|
|
225
|
-
|
|
234
|
+
let decision = decide({ who, where, connection, actionId: ask.action, kind });
|
|
235
|
+
// A guest's post (broker/send.ts): only a fixed step posts, to the channel its published
|
|
236
|
+
// step fixes. No step is named here, so a fixed step's answer says the condition.
|
|
237
|
+
const post = where.guest &&
|
|
238
|
+
kind === "send" &&
|
|
239
|
+
decision.outcome !== "deny" &&
|
|
240
|
+
postsToChannel(connector.id, ask.action);
|
|
241
|
+
const fixedChannel = post && who.kind === "step";
|
|
242
|
+
if (fixedChannel) {
|
|
243
|
+
decision = { ...decision, reason: `${decision.reason} ${FIXED_CHANNEL_ONLY}` };
|
|
244
|
+
}
|
|
245
|
+
else if (post) {
|
|
246
|
+
decision = {
|
|
247
|
+
outcome: "deny",
|
|
248
|
+
rule: "guest_send",
|
|
249
|
+
refused: "channel_not_fixed",
|
|
250
|
+
reason: FIXED_CHANNEL_ONLY,
|
|
251
|
+
};
|
|
252
|
+
}
|
|
226
253
|
return c.json({
|
|
227
254
|
who,
|
|
228
255
|
connection: { id: row.id, name: row.name, connector: connector.id },
|
|
@@ -232,6 +259,7 @@ export const brokerRoutes = new Hono()
|
|
|
232
259
|
reason: decision.reason,
|
|
233
260
|
...(decision.refused ? { refused: decision.refused } : {}),
|
|
234
261
|
...(decision.admins ? { admins: true } : {}),
|
|
262
|
+
...(fixedChannel ? { fixedChannel: true } : {}),
|
|
235
263
|
});
|
|
236
264
|
})
|
|
237
265
|
// What „Was darf …?“ picks from: the organization's people, the space's connections and their actions.
|
|
@@ -260,40 +288,51 @@ export const brokerRoutes = new Hono()
|
|
|
260
288
|
.get("/spaces/:id/broker/log", async (c) => {
|
|
261
289
|
const user = c.get("user");
|
|
262
290
|
const space = await ownedSpace(user.id, c.req.param("id"));
|
|
263
|
-
|
|
291
|
+
const own = memberOf(user);
|
|
264
292
|
const { cursor, q, ...query } = logSchema.parse(c.req.query());
|
|
265
293
|
const before = cursor ? readCursor(cursor) : null;
|
|
266
294
|
const limit = query.limit ?? LOG_PAGE;
|
|
267
|
-
const people = await peopleOf(user);
|
|
295
|
+
const people = await peopleOf(user, own);
|
|
268
296
|
const rows = await logOfSpace(space.id, {
|
|
269
297
|
...query,
|
|
270
298
|
limit,
|
|
299
|
+
...(own ? { own } : {}),
|
|
271
300
|
...(before ? { before } : {}),
|
|
272
|
-
...(q?.trim() ? { q, matches: await matchesOf(q, space.id, people) } : {}),
|
|
301
|
+
...(q?.trim() ? { q, matches: await matchesOf(q, space.id, people, own) } : {}),
|
|
273
302
|
});
|
|
274
303
|
const last = rows.at(-1);
|
|
275
304
|
return c.json({
|
|
276
|
-
lines: await describeLines(rows, space.id, people),
|
|
305
|
+
lines: await describeLines(rows, space.id, people, own),
|
|
277
306
|
// A full page may have more behind it.
|
|
278
307
|
next: last && rows.length === limit ? cursorOf(last) : null,
|
|
279
308
|
});
|
|
280
309
|
})
|
|
281
|
-
// One line, with what its run was allowed through that connection or to that host.
|
|
310
|
+
// One line, with what its run was allowed through that connection or to that host. A member's
|
|
311
|
+
// own line; another person's is not there for them.
|
|
282
312
|
.get("/spaces/:id/broker/log/:line", async (c) => {
|
|
283
313
|
const user = c.get("user");
|
|
284
314
|
const space = await ownedSpace(user.id, c.req.param("id"));
|
|
285
|
-
|
|
286
|
-
const row = await logLine(space.id, c.req.param("line"));
|
|
315
|
+
const own = memberOf(user);
|
|
316
|
+
const row = await logLine(space.id, c.req.param("line"), own);
|
|
287
317
|
if (!row) {
|
|
288
318
|
throw notFound();
|
|
289
319
|
}
|
|
290
|
-
const [line] = await describeLines([row], space.id, await peopleOf(user));
|
|
291
|
-
const
|
|
320
|
+
const [line] = await describeLines([row], space.id, await peopleOf(user, own), own);
|
|
321
|
+
const found = row.runId
|
|
292
322
|
? await db.query.run.findFirst({
|
|
293
323
|
where: (t, { eq }) => eq(t.id, row.runId),
|
|
294
|
-
columns: {
|
|
324
|
+
columns: {
|
|
325
|
+
id: true,
|
|
326
|
+
wizardId: true,
|
|
327
|
+
mode: true,
|
|
328
|
+
status: true,
|
|
329
|
+
grant: true,
|
|
330
|
+
userId: true,
|
|
331
|
+
},
|
|
295
332
|
})
|
|
296
333
|
: undefined;
|
|
334
|
+
// A member reads what a run was allowed only of a run held for them.
|
|
335
|
+
const run = found && (!own || found.userId === own) ? found : undefined;
|
|
297
336
|
const host = row.connectionId.startsWith("host:") ? row.connectionId.slice(5) : null;
|
|
298
337
|
return c.json({
|
|
299
338
|
line,
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { note } from "@engenty/wizards-shared/run";
|
|
2
|
+
import { Hono } from "hono";
|
|
3
|
+
import { bodyLimit } from "hono/body-limit";
|
|
4
|
+
import { z } from "zod";
|
|
5
|
+
import { applyBundleUpdate, bundleRemoval, bundleUpdate, importBundle, listBundles, previewBundle, removeBundle, } from "../bundles/index.js";
|
|
6
|
+
import { MAX_ARCHIVE_MB } from "../bundles/read.js";
|
|
7
|
+
import { actionKindSchema, signInChoiceSchema } from "../connectors/external.js";
|
|
8
|
+
import { ServiceError } from "../services/errors.js";
|
|
9
|
+
import { requestLang, say } from "./lang.js";
|
|
10
|
+
const serverChoice = z.object({
|
|
11
|
+
take: z.boolean().optional(),
|
|
12
|
+
id: z.string().min(2).max(60).optional(),
|
|
13
|
+
toolPrefix: z.string().min(2).max(31).optional(),
|
|
14
|
+
name: z.string().trim().min(1).max(120).optional(),
|
|
15
|
+
signIn: signInChoiceSchema.optional(),
|
|
16
|
+
actionKinds: z.record(z.string().max(200), actionKindSchema).optional(),
|
|
17
|
+
oauthClientId: z.string().max(500).optional(),
|
|
18
|
+
oauthClientSecret: z.string().max(500).optional(),
|
|
19
|
+
});
|
|
20
|
+
const sourceFields = {
|
|
21
|
+
address: z.string().trim().min(1).max(500).optional(),
|
|
22
|
+
path: z.string().max(300).optional(),
|
|
23
|
+
servers: z.record(z.string().max(100), serverChoice).optional(),
|
|
24
|
+
};
|
|
25
|
+
const previewSchema = z.object(sourceFields);
|
|
26
|
+
const importSchema = z.object({
|
|
27
|
+
...sourceFields,
|
|
28
|
+
hash: z.string().max(100).optional(),
|
|
29
|
+
skills: z.array(z.string().max(300)).max(200).optional(),
|
|
30
|
+
});
|
|
31
|
+
const updateSchema = z.object({ hash: z.string().max(100).optional() });
|
|
32
|
+
// A zip may weigh what a repository's archive may, and a little for the form around it.
|
|
33
|
+
const uploadLimit = bodyLimit({
|
|
34
|
+
maxSize: (MAX_ARCHIVE_MB + 4) * 1_000_000,
|
|
35
|
+
onError: (c) => c.json({ error: say(c, "tooLarge"), code: "too_large" }, 413),
|
|
36
|
+
});
|
|
37
|
+
/** A request's JSON, and its file where it came as a form. */
|
|
38
|
+
async function bodyOf(c) {
|
|
39
|
+
if (!(c.req.header("content-type") ?? "").startsWith("multipart/form-data")) {
|
|
40
|
+
return { options: await c.req.json().catch(() => ({})), file: null };
|
|
41
|
+
}
|
|
42
|
+
const form = await c.req.formData();
|
|
43
|
+
const file = form.get("file");
|
|
44
|
+
if (!(file instanceof File)) {
|
|
45
|
+
throw new ServiceError("invalid", note("chooseFile"));
|
|
46
|
+
}
|
|
47
|
+
const raw = form.get("options");
|
|
48
|
+
let options = {};
|
|
49
|
+
if (typeof raw === "string" && raw.trim()) {
|
|
50
|
+
try {
|
|
51
|
+
options = JSON.parse(raw);
|
|
52
|
+
}
|
|
53
|
+
catch {
|
|
54
|
+
throw new ServiceError("invalid", { server: "bundleUploadKind" });
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
return { options, file: { name: file.name, data: new Uint8Array(await file.arrayBuffer()) } };
|
|
58
|
+
}
|
|
59
|
+
function sourceOf(input, file) {
|
|
60
|
+
const path = input.path?.trim() ? { path: input.path.trim() } : {};
|
|
61
|
+
if (file) {
|
|
62
|
+
return { file, ...path };
|
|
63
|
+
}
|
|
64
|
+
if (!input.address) {
|
|
65
|
+
throw new ServiceError("invalid", { server: "bundleNotARepository" });
|
|
66
|
+
}
|
|
67
|
+
return { address: input.address, ...path };
|
|
68
|
+
}
|
|
69
|
+
export const bundleRoutes = new Hono()
|
|
70
|
+
.post("/spaces/:id/bundles/preview", uploadLimit, async (c) => {
|
|
71
|
+
const { options, file } = await bodyOf(c);
|
|
72
|
+
const input = previewSchema.parse(options);
|
|
73
|
+
return c.json(await previewBundle(c.get("user").id, c.req.param("id"), sourceOf(input, file), requestLang(c), input.servers));
|
|
74
|
+
})
|
|
75
|
+
.get("/spaces/:id/bundles", async (c) => c.json({ bundles: await listBundles(c.get("user").id, c.req.param("id")) }))
|
|
76
|
+
.post("/spaces/:id/bundles", uploadLimit, async (c) => {
|
|
77
|
+
const { options, file } = await bodyOf(c);
|
|
78
|
+
const { address, path, ...input } = importSchema.parse(options);
|
|
79
|
+
return c.json(await importBundle(c.get("user").id, c.req.param("id"), sourceOf({ address, path }, file), input, requestLang(c)));
|
|
80
|
+
})
|
|
81
|
+
.get("/bundles/:id/update", async (c) => c.json(await bundleUpdate(c.get("user").id, c.req.param("id"), requestLang(c))))
|
|
82
|
+
.post("/bundles/:id/update", uploadLimit, async (c) => {
|
|
83
|
+
const { options, file } = await bodyOf(c);
|
|
84
|
+
const { hash } = updateSchema.parse(options);
|
|
85
|
+
return c.json(await applyBundleUpdate(c.get("user").id, c.req.param("id"), { ...(hash ? { hash } : {}), ...(file ? { file } : {}) }, requestLang(c)));
|
|
86
|
+
})
|
|
87
|
+
.get("/bundles/:id/removal", async (c) => c.json(await bundleRemoval(c.get("user").id, c.req.param("id"))))
|
|
88
|
+
.delete("/bundles/:id", async (c) => {
|
|
89
|
+
await removeBundle(c.get("user").id, c.req.param("id"));
|
|
90
|
+
return c.json({ ok: true });
|
|
91
|
+
});
|
|
@@ -2,7 +2,7 @@ import { Hono } from "hono";
|
|
|
2
2
|
import { z } from "zod";
|
|
3
3
|
import { inAudience } from "../broker/index.js";
|
|
4
4
|
import { namesOf } from "../connectors/person-sign-ins.js";
|
|
5
|
-
import { connectionPatchSchema, createSpaceConnection, newConnectionSchema, removeSignIn, removeSpaceConnection, signInWithCredentials, spaceConnectionViews, startSpaceConnectionOAuth, updateSpaceConnection, } from "../connectors/space-connections.js";
|
|
5
|
+
import { connectionPatchSchema, createSpaceConnection, newConnectionSchema, pauseSpaceConnection, removeSignIn, removeSpaceConnection, signInWithCredentials, spaceConnectionViews, startSpaceConnectionOAuth, updateSpaceConnection, } from "../connectors/space-connections.js";
|
|
6
6
|
import { isAdminRole } from "../services/access.js";
|
|
7
7
|
import { ownedSpace } from "../services/spaces.js";
|
|
8
8
|
import { requestLang } from "./lang.js";
|
|
@@ -19,12 +19,20 @@ async function views(user, spaceId) {
|
|
|
19
19
|
const shown = admin
|
|
20
20
|
? all
|
|
21
21
|
: all.filter((v) => inAudience(v.audience, { kind: "person", id: user.id }));
|
|
22
|
-
const names = shown.some((v) => v.setUpBy) ? await namesOf(user) : null;
|
|
23
|
-
return shown.map((v) => ({
|
|
22
|
+
const names = shown.some((v) => v.setUpBy || v.pausedBy) ? await namesOf(user) : null;
|
|
23
|
+
return shown.map(({ pausedBy, ...v }) => ({
|
|
24
24
|
...v,
|
|
25
25
|
setUpByName: v.setUpBy ? (names?.get(v.setUpBy) ?? null) : null,
|
|
26
|
+
pausedByName: pausedBy ? (names?.get(pausedBy) ?? null) : null,
|
|
26
27
|
}));
|
|
27
28
|
}
|
|
29
|
+
/** Pauses or resumes a connection, and answers with it as the studio shows it. */
|
|
30
|
+
async function pause(c, paused) {
|
|
31
|
+
const user = c.get("user");
|
|
32
|
+
const row = await pauseSpaceConnection(user.id, c.req.param("id") ?? "", paused);
|
|
33
|
+
const [view] = (await views(user, row.spaceId)).filter((v) => v.id === row.id);
|
|
34
|
+
return c.json(view);
|
|
35
|
+
}
|
|
28
36
|
const asMe = (user) => ({ as: "person", userId: user.id, role: user.role });
|
|
29
37
|
export const connectionRoutes = new Hono()
|
|
30
38
|
.get("/spaces/:id/connections", async (c) => {
|
|
@@ -48,6 +56,9 @@ export const connectionRoutes = new Hono()
|
|
|
48
56
|
await removeSpaceConnection(c.get("user").id, c.req.param("id"));
|
|
49
57
|
return c.json({ ok: true });
|
|
50
58
|
})
|
|
59
|
+
// Nobody reaches a connection that pauses; resuming gives it back as it was.
|
|
60
|
+
.post("/connections/:id/pause", (c) => pause(c, true))
|
|
61
|
+
.post("/connections/:id/resume", (c) => pause(c, false))
|
|
51
62
|
// As the space: the admins' sign-in, kept on the connection itself.
|
|
52
63
|
.post("/connections/:id/sign-in", async (c) => signIn(c, asSpace))
|
|
53
64
|
.delete("/connections/:id/sign-in", async (c) => {
|
|
@@ -3,7 +3,7 @@ import { streamSSE } from "hono/streaming";
|
|
|
3
3
|
import { subjectsOfPerson } from "../broker/rwx.js";
|
|
4
4
|
import { feature, remoteFeatures } from "../features.js";
|
|
5
5
|
import { openStreams, subscribe } from "../live/hub.js";
|
|
6
|
-
import { itemView } from "../live/views.js";
|
|
6
|
+
import { heardChanges, itemView } from "../live/views.js";
|
|
7
7
|
import { asRole } from "../services/access.js";
|
|
8
8
|
import { chatChangesFor } from "../services/work-chats.js";
|
|
9
9
|
import { requestLang, say } from "./lang.js";
|
|
@@ -66,7 +66,9 @@ export const liveRoutes = new Hono().get("/", async (c) => {
|
|
|
66
66
|
const unsubscribe = await subscribe(user.tenantId, since, send, {
|
|
67
67
|
key: `${user.role}|${reader.lang}`,
|
|
68
68
|
read: (x) => asRole(user.role, () => itemView(reader, x)),
|
|
69
|
-
}
|
|
69
|
+
},
|
|
70
|
+
// A member hears nothing of the Studio of a space closed to them.
|
|
71
|
+
(changes) => asRole(user.role, () => heardChanges(changes)));
|
|
70
72
|
const end = () => {
|
|
71
73
|
if (closed) {
|
|
72
74
|
return;
|