@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
|
@@ -65,6 +65,7 @@ export async function personSignIns(user) {
|
|
|
65
65
|
: null,
|
|
66
66
|
setUpBy: row.setUpBy ? (names?.get(row.setUpBy) ?? null) : null,
|
|
67
67
|
setUpAt: row.setUpAt.toISOString(),
|
|
68
|
+
pausedAt: row.pausedAt?.toISOString() ?? null,
|
|
68
69
|
});
|
|
69
70
|
}
|
|
70
71
|
spaces.push({ id: space.id, name: space.name, connections });
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { note } from "@engenty/wizards-shared/run";
|
|
2
|
+
import { eq } from "drizzle-orm";
|
|
3
|
+
import { brokerCall } from "../broker/index.js";
|
|
4
|
+
import { db, schema } from "../db/client.js";
|
|
5
|
+
import { requireAdmin, requireWritableSpace } from "../services/access.js";
|
|
6
|
+
import { ServiceError } from "../services/errors.js";
|
|
7
|
+
import { importedView, refreshConnector, resolveConnector } from "./external.js";
|
|
8
|
+
import { listSpaceConnections } from "./space-connections.js";
|
|
9
|
+
/*
|
|
10
|
+
* „Aktionen neu laden“ in the studio (docs/plans/capabilities-next.md, piece 1): an admin of a
|
|
11
|
+
* space that can be changed here has an imported connector's source read again. An MCP server
|
|
12
|
+
* that lists its tools only to a signed-in account is asked with the sign-in of a connection on
|
|
13
|
+
* that connector: the space's own, or the admin's where each person signs in. The broker reads
|
|
14
|
+
* the sign-in, as for every call, and the reload is a line of the audit.
|
|
15
|
+
*/
|
|
16
|
+
export async function reloadConnector(userId, spaceId, id) {
|
|
17
|
+
await requireWritableSpace(spaceId);
|
|
18
|
+
await requireAdmin();
|
|
19
|
+
const current = await importedView(spaceId, id);
|
|
20
|
+
const resolved = current ? await resolveConnector(spaceId, id) : null;
|
|
21
|
+
if (!(current && resolved)) {
|
|
22
|
+
throw new ServiceError("not_found", note("connectorNotExist"));
|
|
23
|
+
}
|
|
24
|
+
const rows = (await listSpaceConnections(spaceId)).filter((row) => row.connectorId === id);
|
|
25
|
+
const own = rows.some((row) => row.signIn === "person")
|
|
26
|
+
? new Set((await db
|
|
27
|
+
.select({ connectionId: schema.spaceConnectionSignIn.connectionId })
|
|
28
|
+
.from(schema.spaceConnectionSignIn)
|
|
29
|
+
.where(eq(schema.spaceConnectionSignIn.userId, userId))).map((s) => s.connectionId))
|
|
30
|
+
: new Set();
|
|
31
|
+
const signedIn = rows.filter((row) => (row.signIn === "space" ? !!row.secret : own.has(row.id)));
|
|
32
|
+
let failed;
|
|
33
|
+
let refused = null;
|
|
34
|
+
for (const row of signedIn) {
|
|
35
|
+
try {
|
|
36
|
+
const out = await brokerCall({
|
|
37
|
+
who: { kind: "admin", id: userId },
|
|
38
|
+
where: { spaceId },
|
|
39
|
+
// Listing the tools is none of the connector's actions, so a connection that is for a
|
|
40
|
+
// few of them does not narrow it. Its rule for reading still decides.
|
|
41
|
+
connection: {
|
|
42
|
+
kind: "space_connection",
|
|
43
|
+
row: { ...row, actions: [] },
|
|
44
|
+
connector: resolved.connector,
|
|
45
|
+
},
|
|
46
|
+
action: { id: "list_tools", kind: "read" },
|
|
47
|
+
input: {},
|
|
48
|
+
handler: (account) => refreshConnector(spaceId, id, account.ctx.accessToken),
|
|
49
|
+
});
|
|
50
|
+
if (out.ok) {
|
|
51
|
+
return out.result;
|
|
52
|
+
}
|
|
53
|
+
refused ??= out.reason;
|
|
54
|
+
}
|
|
55
|
+
catch (err) {
|
|
56
|
+
failed ??= err;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
try {
|
|
60
|
+
return await refreshConnector(spaceId, id, null);
|
|
61
|
+
}
|
|
62
|
+
catch (err) {
|
|
63
|
+
// A signed-in connection asked and the source failed: that is the answer.
|
|
64
|
+
if (failed) {
|
|
65
|
+
throw failed;
|
|
66
|
+
}
|
|
67
|
+
// The source wants a sign-in, and no connection gave one.
|
|
68
|
+
if (/(^|\D)401(\D|$)|unauthori[sz]ed/i.test(err instanceof Error ? err.message : "")) {
|
|
69
|
+
throw new ServiceError("invalid", refused ?? note("connectorNoSignedInConnection", { name: current.name }));
|
|
70
|
+
}
|
|
71
|
+
throw err;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
import { CONNECTION_ACTION_KINDS, CONNECTION_AUDIENCES, CONNECTION_LIMITS, CONNECTION_OUTCOMES, CONNECTION_SIGN_INS, DEFAULT_CONNECTION_RULES, } from "@engenty/wizards-shared/connectors";
|
|
2
|
+
import { featureOn } from "@engenty/wizards-shared/features";
|
|
2
3
|
import { note } from "@engenty/wizards-shared/run";
|
|
3
4
|
import { and, asc, eq, inArray } from "drizzle-orm";
|
|
4
5
|
import { nanoid } from "nanoid";
|
|
5
6
|
import { z } from "zod";
|
|
6
|
-
import { inAudience, logRuleChange } from "../broker/index.js";
|
|
7
|
+
import { callsToday, inAudience, logRuleChange } from "../broker/index.js";
|
|
7
8
|
import { db, schema } from "../db/client.js";
|
|
8
9
|
import { buildAuthorizationUrl, createOAuth2Pkce, exchangeAuthorizationCode, } from "../engenty/connections-sdk/oauth2.js";
|
|
10
|
+
import { currentFeatures } from "../features.js";
|
|
11
|
+
import { managed, tenantInfo } from "../manage.js";
|
|
12
|
+
import { loadedPlugin } from "../plugins/registry.js";
|
|
9
13
|
import { seal, unseal } from "../secrets/crypto.js";
|
|
10
14
|
import { isAdminRole, requireAdmin, requireWritableSpace } from "../services/access.js";
|
|
11
15
|
import { notFound, ServiceError } from "../services/errors.js";
|
|
@@ -20,16 +24,24 @@ export const newConnectionSchema = z.object({
|
|
|
20
24
|
connectorId: z.string().min(1).max(200),
|
|
21
25
|
name: z.string().trim().min(1).max(CONNECTION_LIMITS.name),
|
|
22
26
|
signIn: z.enum(CONNECTION_SIGN_INS),
|
|
23
|
-
|
|
27
|
+
/** Left out: the members, and the admins on a connector that came from a pasted address. */
|
|
28
|
+
audience: z.enum(CONNECTION_AUDIENCES).optional(),
|
|
24
29
|
rules: rulesSchema.default(DEFAULT_CONNECTION_RULES),
|
|
25
30
|
/** The connector's actions it is for; left out: every action. */
|
|
26
31
|
actions: z.array(z.string().max(200)).max(200).default([]),
|
|
27
32
|
});
|
|
33
|
+
/** A limit on a connection's calls: a whole number from 1, or null for none. */
|
|
34
|
+
const callLimit = z.number().int().min(1).max(CONNECTION_LIMITS.calls).nullable();
|
|
28
35
|
export const connectionPatchSchema = z.object({
|
|
29
36
|
name: z.string().trim().min(1).max(CONNECTION_LIMITS.name).optional(),
|
|
37
|
+
/** How it signs in: a change forgets the sign-ins of the way it leaves. */
|
|
38
|
+
signIn: z.enum(CONNECTION_SIGN_INS).optional(),
|
|
30
39
|
audience: z.enum(CONNECTION_AUDIENCES).optional(),
|
|
31
40
|
rules: rulesSchema.optional(),
|
|
32
41
|
actions: z.array(z.string().max(200)).max(200).optional(),
|
|
42
|
+
/** The calls one run makes through it at most, and the calls it takes per day; null: no limit. */
|
|
43
|
+
callsPerRun: callLimit.optional(),
|
|
44
|
+
callsPerDay: callLimit.optional(),
|
|
33
45
|
});
|
|
34
46
|
// --- reading ---------------------------------------------------------------------------------
|
|
35
47
|
/** A connection by id, in this tenant; not found where the id is another tenant's or nobody's. */
|
|
@@ -102,8 +114,10 @@ export async function spaceConnectionViews(spaceId, userId) {
|
|
|
102
114
|
.from(schema.spaceConnectionSignIn)
|
|
103
115
|
.where(inArray(schema.spaceConnectionSignIn.connectionId, rows.map((row) => row.id)))
|
|
104
116
|
: [];
|
|
117
|
+
const today = await callsToday(rows.map((row) => row.id));
|
|
105
118
|
return Promise.all(rows.map(async (row) => {
|
|
106
|
-
const
|
|
119
|
+
const found = await resolveConnector(spaceId, row.connectorId);
|
|
120
|
+
const connector = found?.connector ?? null;
|
|
107
121
|
const theirs = row.signIn === "person" ? signIns.filter((s) => s.connectionId === row.id) : [];
|
|
108
122
|
const mine = theirs.find((s) => s.userId === userId);
|
|
109
123
|
return {
|
|
@@ -119,6 +133,7 @@ export async function spaceConnectionViews(spaceId, userId) {
|
|
|
119
133
|
...(connector.auth.kind === "api_key"
|
|
120
134
|
? { fields: connector.auth.apiKey.fields }
|
|
121
135
|
: {}),
|
|
136
|
+
...(found?.fromAddress ? { fromAddress: true } : {}),
|
|
122
137
|
}
|
|
123
138
|
: null,
|
|
124
139
|
name: row.name,
|
|
@@ -127,6 +142,10 @@ export async function spaceConnectionViews(spaceId, userId) {
|
|
|
127
142
|
rules: row.rules,
|
|
128
143
|
actions: row.actions,
|
|
129
144
|
plugin: row.plugin,
|
|
145
|
+
pluginName: row.plugin
|
|
146
|
+
? (loadedPlugin(row.plugin)?.source.manifest.name ?? row.plugin)
|
|
147
|
+
: null,
|
|
148
|
+
bundleId: row.bundleId,
|
|
130
149
|
account: row.signIn === "space" && row.secret
|
|
131
150
|
? {
|
|
132
151
|
label: row.label ?? connector?.name ?? row.name,
|
|
@@ -140,6 +159,11 @@ export async function spaceConnectionViews(spaceId, userId) {
|
|
|
140
159
|
setUpAt: row.setUpAt.toISOString(),
|
|
141
160
|
lastUsedAt: row.lastUsedAt?.toISOString() ?? null,
|
|
142
161
|
signedIn: theirs.length,
|
|
162
|
+
pausedAt: row.pausedAt?.toISOString() ?? null,
|
|
163
|
+
pausedBy: row.pausedBy,
|
|
164
|
+
callsPerRun: row.callsPerRun,
|
|
165
|
+
callsPerDay: row.callsPerDay,
|
|
166
|
+
callsToday: today.get(row.id) ?? 0,
|
|
143
167
|
};
|
|
144
168
|
}));
|
|
145
169
|
}
|
|
@@ -153,12 +177,27 @@ function knownActions(connector, actions) {
|
|
|
153
177
|
}
|
|
154
178
|
return [...new Set(actions)];
|
|
155
179
|
}
|
|
180
|
+
/** Whether a connection here may have each person sign in. A computer of one's own has no plan. */
|
|
181
|
+
export async function personSignInAllowed() {
|
|
182
|
+
return !managed || featureOn(await currentFeatures(), "personSignIn");
|
|
183
|
+
}
|
|
184
|
+
/** Refuses each person signing in where the organization's plan leaves it out, naming the plan. */
|
|
185
|
+
async function requirePersonSignIn() {
|
|
186
|
+
if (await personSignInAllowed()) {
|
|
187
|
+
return;
|
|
188
|
+
}
|
|
189
|
+
const plan = (await tenantInfo(currentTenant()).catch(() => null))?.plan?.name;
|
|
190
|
+
throw new ServiceError("plan", plan ? note("personSignInNotInPlan", { plan }) : note("personSignInNotInOrganizationPlan"));
|
|
191
|
+
}
|
|
156
192
|
export async function createSpaceConnection(userId, spaceId, input,
|
|
157
193
|
/** The plugin that sets it up through `server.connections`, where one does. */
|
|
158
194
|
plugin = null) {
|
|
159
195
|
await ownedSpace(userId ?? "", spaceId);
|
|
160
196
|
await requireWritableSpace(spaceId);
|
|
161
197
|
await requireAdmin();
|
|
198
|
+
if (input.signIn === "person") {
|
|
199
|
+
await requirePersonSignIn();
|
|
200
|
+
}
|
|
162
201
|
const found = await resolveConnector(spaceId, input.connectorId);
|
|
163
202
|
if (!found || found.connector.auth.kind === "browser") {
|
|
164
203
|
throw new ServiceError("invalid", note("connectorGone", { id: input.connectorId }));
|
|
@@ -174,9 +213,12 @@ plugin = null) {
|
|
|
174
213
|
spaceId,
|
|
175
214
|
connectorId: found.connector.id,
|
|
176
215
|
plugin,
|
|
216
|
+
// Its connector came with a plugin for Claude Code or Cursor: it goes with that, too.
|
|
217
|
+
bundleId: found.bundleId,
|
|
177
218
|
name: input.name,
|
|
178
219
|
signIn: input.signIn,
|
|
179
|
-
|
|
220
|
+
// A server nobody checked reaches the AI with its own texts: the admins use it first.
|
|
221
|
+
audience: input.audience ?? (found.fromAddress ? "admins" : "members"),
|
|
180
222
|
rules: input.rules,
|
|
181
223
|
actions: knownActions(found.connector, input.actions),
|
|
182
224
|
setUpBy: userId,
|
|
@@ -189,6 +231,14 @@ export async function updateSpaceConnection(userId, id, patch) {
|
|
|
189
231
|
await ownedSpace(userId, row.spaceId);
|
|
190
232
|
await requireWritableSpace(row.spaceId);
|
|
191
233
|
await requireAdmin();
|
|
234
|
+
const signInChanged = patch.signIn !== undefined && patch.signIn !== row.signIn;
|
|
235
|
+
if (signInChanged && patch.signIn === "person") {
|
|
236
|
+
// A plugin calls with no person: its connection stays the space's.
|
|
237
|
+
if (row.plugin) {
|
|
238
|
+
throw new ServiceError("invalid", note("pluginConnectionSignsInAsSpace"));
|
|
239
|
+
}
|
|
240
|
+
await requirePersonSignIn();
|
|
241
|
+
}
|
|
192
242
|
const actions = patch.actions !== undefined
|
|
193
243
|
? knownActions(await connectorOfRow(row), patch.actions)
|
|
194
244
|
: undefined;
|
|
@@ -196,28 +246,47 @@ export async function updateSpaceConnection(userId, id, patch) {
|
|
|
196
246
|
.update(schema.spaceConnection)
|
|
197
247
|
.set({
|
|
198
248
|
...(patch.name !== undefined ? { name: patch.name } : {}),
|
|
249
|
+
// The space's own sign-in goes with the way it leaves; a person's has none on the row.
|
|
250
|
+
...(signInChanged ? { signIn: patch.signIn, secret: null, label: null } : {}),
|
|
199
251
|
...(patch.audience !== undefined ? { audience: patch.audience } : {}),
|
|
200
252
|
...(patch.rules !== undefined ? { rules: patch.rules } : {}),
|
|
201
253
|
...(actions !== undefined ? { actions } : {}),
|
|
254
|
+
...(patch.callsPerRun !== undefined ? { callsPerRun: patch.callsPerRun } : {}),
|
|
255
|
+
...(patch.callsPerDay !== undefined ? { callsPerDay: patch.callsPerDay } : {}),
|
|
202
256
|
updatedAt: new Date(),
|
|
203
257
|
})
|
|
204
258
|
.where(eq(schema.spaceConnection.id, row.id))
|
|
205
259
|
.returning();
|
|
206
|
-
|
|
260
|
+
if (signInChanged && updated.signIn === "space") {
|
|
261
|
+
await db
|
|
262
|
+
.delete(schema.spaceConnectionSignIn)
|
|
263
|
+
.where(eq(schema.spaceConnectionSignIn.connectionId, row.id));
|
|
264
|
+
}
|
|
265
|
+
// How it signs in, who may use it, what each kind of action may do and how many calls it takes:
|
|
266
|
+
// a change there is heard of.
|
|
207
267
|
const rulesChanged = patch.rules !== undefined && JSON.stringify(patch.rules) !== JSON.stringify(row.rules);
|
|
208
268
|
const audienceChanged = patch.audience !== undefined && patch.audience !== row.audience;
|
|
209
|
-
|
|
269
|
+
const limits = changedLimits(row, updated);
|
|
270
|
+
if (rulesChanged || audienceChanged || signInChanged || limits) {
|
|
210
271
|
await logRuleChange({
|
|
211
272
|
userId,
|
|
212
273
|
spaceId: row.spaceId,
|
|
213
274
|
connectionId: row.id,
|
|
214
275
|
summary: {
|
|
276
|
+
...(signInChanged ? { signIn: `${row.signIn} → ${updated.signIn}` } : {}),
|
|
215
277
|
...(audienceChanged ? { audience: `${row.audience} → ${updated.audience}` } : {}),
|
|
216
278
|
...(rulesChanged ? { rules: changedRules(row.rules, updated.rules) } : {}),
|
|
279
|
+
...(limits ? { limits } : {}),
|
|
217
280
|
},
|
|
218
281
|
reason: [
|
|
282
|
+
signInChanged
|
|
283
|
+
? updated.signIn === "space"
|
|
284
|
+
? "It now signs in as the space."
|
|
285
|
+
: "Each person now signs in."
|
|
286
|
+
: "",
|
|
219
287
|
audienceChanged ? `The audience is now ${updated.audience}.` : "",
|
|
220
288
|
rulesChanged ? `The rules changed: ${changedRules(row.rules, updated.rules)}.` : "",
|
|
289
|
+
limits ? `The limits changed: ${limits}.` : "",
|
|
221
290
|
]
|
|
222
291
|
.filter(Boolean)
|
|
223
292
|
.join(" "),
|
|
@@ -232,6 +301,49 @@ function changedRules(before, after) {
|
|
|
232
301
|
.map((k) => `${k}: ${before[k]} → ${after[k]}`)
|
|
233
302
|
.join(", ");
|
|
234
303
|
}
|
|
304
|
+
/** "calls per run: none → 20, calls per day: 500 → none"; empty where no limit changed. */
|
|
305
|
+
function changedLimits(before, after) {
|
|
306
|
+
const said = (limit) => (limit === null ? "none" : String(limit));
|
|
307
|
+
return [
|
|
308
|
+
["calls per run", before.callsPerRun, after.callsPerRun],
|
|
309
|
+
["calls per day", before.callsPerDay, after.callsPerDay],
|
|
310
|
+
]
|
|
311
|
+
.filter(([, was, is]) => was !== is)
|
|
312
|
+
.map(([name, was, is]) => `${name}: ${said(was)} → ${said(is)}`)
|
|
313
|
+
.join(", ");
|
|
314
|
+
}
|
|
315
|
+
/**
|
|
316
|
+
* Pauses a connection, or resumes it (docs/plans/capabilities-next.md, 2a): while it pauses the
|
|
317
|
+
* broker refuses every call through it, whoever calls, at the call (broker/call.ts reads the
|
|
318
|
+
* pause each time). Nothing is lost: its sign-ins, rules and audience stay. Heard of as a changed
|
|
319
|
+
* rule, with who did it. Pausing what pauses, or resuming what does not, changes nothing.
|
|
320
|
+
*/
|
|
321
|
+
export async function pauseSpaceConnection(userId, id, paused) {
|
|
322
|
+
const row = await spaceConnectionById(id);
|
|
323
|
+
await ownedSpace(userId, row.spaceId);
|
|
324
|
+
await requireWritableSpace(row.spaceId);
|
|
325
|
+
await requireAdmin();
|
|
326
|
+
if (Boolean(row.pausedAt) === paused) {
|
|
327
|
+
return row;
|
|
328
|
+
}
|
|
329
|
+
const [updated] = await db
|
|
330
|
+
.update(schema.spaceConnection)
|
|
331
|
+
.set({
|
|
332
|
+
pausedAt: paused ? new Date() : null,
|
|
333
|
+
pausedBy: paused ? userId : null,
|
|
334
|
+
updatedAt: new Date(),
|
|
335
|
+
})
|
|
336
|
+
.where(eq(schema.spaceConnection.id, row.id))
|
|
337
|
+
.returning();
|
|
338
|
+
await logRuleChange({
|
|
339
|
+
userId,
|
|
340
|
+
spaceId: row.spaceId,
|
|
341
|
+
connectionId: row.id,
|
|
342
|
+
summary: { paused: paused ? "yes" : "no" },
|
|
343
|
+
reason: paused ? "The connection is paused: nobody reaches it." : "The connection is resumed.",
|
|
344
|
+
});
|
|
345
|
+
return updated;
|
|
346
|
+
}
|
|
235
347
|
export async function removeSpaceConnection(userId, id) {
|
|
236
348
|
const row = await spaceConnectionById(id);
|
|
237
349
|
await ownedSpace(userId, row.spaceId);
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
CREATE TABLE `draft_change` (
|
|
2
|
+
`id` integer PRIMARY KEY AUTOINCREMENT NOT NULL,
|
|
3
|
+
`wizard_id` text NOT NULL,
|
|
4
|
+
`change` text NOT NULL,
|
|
5
|
+
`created_at` integer DEFAULT (unixepoch() * 1000) NOT NULL,
|
|
6
|
+
FOREIGN KEY (`wizard_id`) REFERENCES `wizard`(`id`) ON UPDATE no action ON DELETE cascade
|
|
7
|
+
);
|
|
8
|
+
--> statement-breakpoint
|
|
9
|
+
CREATE INDEX `draft_change_wizard` ON `draft_change` (`wizard_id`,`id`);--> statement-breakpoint
|
|
10
|
+
CREATE INDEX `draft_change_at` ON `draft_change` (`created_at`);--> statement-breakpoint
|
|
11
|
+
CREATE TABLE `mcp_app_check` (
|
|
12
|
+
`app` text NOT NULL,
|
|
13
|
+
`person` text NOT NULL,
|
|
14
|
+
`kind` text NOT NULL,
|
|
15
|
+
`allowed` integer DEFAULT 0 NOT NULL,
|
|
16
|
+
`refused` integer DEFAULT 0 NOT NULL,
|
|
17
|
+
`at` integer NOT NULL,
|
|
18
|
+
PRIMARY KEY(`app`, `person`)
|
|
19
|
+
);
|
|
20
|
+
--> statement-breakpoint
|
|
21
|
+
CREATE TABLE `mcp_app_seen` (
|
|
22
|
+
`app` text PRIMARY KEY NOT NULL,
|
|
23
|
+
`at` integer NOT NULL,
|
|
24
|
+
`tool_at` integer,
|
|
25
|
+
`widget_at` integer
|
|
26
|
+
);
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
CREATE TABLE `space_bundle` (
|
|
2
|
+
`id` text PRIMARY KEY NOT NULL,
|
|
3
|
+
`tenant_id` text NOT NULL,
|
|
4
|
+
`space_id` text NOT NULL,
|
|
5
|
+
`name` text NOT NULL,
|
|
6
|
+
`version` text,
|
|
7
|
+
`description` text,
|
|
8
|
+
`format` text NOT NULL,
|
|
9
|
+
`origin` text NOT NULL,
|
|
10
|
+
`hash` text NOT NULL,
|
|
11
|
+
`left_out` text DEFAULT '[]' NOT NULL,
|
|
12
|
+
`added_by` text,
|
|
13
|
+
`created_at` integer DEFAULT (unixepoch() * 1000) NOT NULL,
|
|
14
|
+
`updated_at` integer DEFAULT (unixepoch() * 1000) NOT NULL,
|
|
15
|
+
FOREIGN KEY (`space_id`) REFERENCES `space`(`id`) ON UPDATE no action ON DELETE cascade
|
|
16
|
+
);
|
|
17
|
+
--> statement-breakpoint
|
|
18
|
+
CREATE INDEX `space_bundle_space` ON `space_bundle` (`space_id`);--> statement-breakpoint
|
|
19
|
+
ALTER TABLE `space_connection` ADD `bundle_id` text;--> statement-breakpoint
|
|
20
|
+
ALTER TABLE `space_connector` ADD `bundle_id` text;--> statement-breakpoint
|
|
21
|
+
ALTER TABLE `space_skill` ADD `bundle_id` text;
|