@segmentstream/ontology 0.95.0 → 0.97.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +39 -4
- package/dist/analyze.d.ts +23 -3
- package/dist/analyze.js +431 -17
- package/dist/authoring.js +3 -0
- package/dist/bin/check.js +2 -0
- package/dist/diagnostics.d.ts +3 -3
- package/dist/diagnostics.js +2 -0
- package/dist/index.d.ts +5 -3
- package/dist/index.js +3 -2
- package/dist/manifest.d.ts +607 -20
- package/dist/manifest.js +96 -4
- package/dist/migrate/apply.js +5 -1
- package/dist/migrate/model.d.ts +332 -12
- package/dist/migrate/storage.js +2 -0
- package/dist/ontology.d.ts +5 -2
- package/dist/ontology.js +1 -0
- package/dist/runtime/member-tables.d.ts +7 -2
- package/dist/runtime/member-tables.js +18 -3
- package/dist/runtime/new-user-hook.d.ts +11 -1
- package/dist/runtime/new-user-hook.js +69 -29
- package/dist/runtime/pipeline.d.ts +2 -0
- package/dist/runtime/pipeline.js +11 -3
- package/dist/runtime/principals.d.ts +13 -0
- package/dist/runtime/principals.js +98 -28
- package/dist/runtime/resolve-agent-identity.js +43 -12
- package/dist/runtime/service-binding.js +10 -4
- package/dist/service/catalog.js +10 -1
- package/dist/service/chat/envelope.d.ts +16 -16
- package/dist/service/connections.js +1 -0
- package/dist/service/discovery-search.d.ts +1 -1
- package/dist/service/mcp/server.js +13 -1
- package/dist/service/mcp/tools.d.ts +5 -0
- package/dist/service/mcp/tools.js +30 -0
- package/dist/service/operations.d.ts +3 -1
- package/dist/service/operations.js +3 -0
- package/dist/service/schemas.d.ts +74 -0
- package/dist/service/toolsets.d.ts +49 -0
- package/dist/service/toolsets.js +284 -0
- package/dist/sign-in.d.ts +32 -1
- package/dist/sign-in.js +12 -1
- package/dist/toolset.d.ts +141 -0
- package/dist/toolset.js +154 -0
- package/dist/user-identity.d.ts +1 -1
- package/package.json +1 -1
package/dist/analyze.js
CHANGED
|
@@ -6,12 +6,12 @@ import { isBlobAccept, MAX_BLOB_BYTES } from "./blob.js";
|
|
|
6
6
|
import { isAction } from "./action.js";
|
|
7
7
|
import { CONNECTION_KEY, isConnection } from "./connection.js";
|
|
8
8
|
import { isEntity } from "./entity.js";
|
|
9
|
-
import { QUERY_METRICS_ROUTE, LEGACY_MEMBER_NAME, ENTITY_ID, GENERATED_ACTIONS, GENERATED_UPSERT_PREFIX, HISTORY_SUFFIX, MCP_METRIC_TOOLS, MCP_READ_TOOLS, MCP_TOOL_NAME_MAX_LENGTH, MEMBER_ROLE, FEEDBACK_REPORTER_ROLE, mcpToolName, RESERVED_ENTITY_NAMES, RESERVED_MEMBER_NAMES, RESERVED_RELATIONSHIP_NAMES, SNAKE_CASE_NAME, SYSTEM_PROPERTIES, isSystemProperty, toCamelCase, } from "./names.js";
|
|
9
|
+
import { QUERY_METRICS_ROUTE, LEGACY_MEMBER_NAME, ENTITY_ID, GENERATED_ACTIONS, GENERATED_UPSERT_PREFIX, HISTORY_SUFFIX, MCP_METRIC_TOOLS, MCP_READ_TOOLS, MCP_TOOL_NAME_MAX_LENGTH, MEMBER_ROLE, FEEDBACK_REPORTER_ROLE, mcpToolName, RESERVED_ENTITY_NAMES, RESERVED_MEMBER_NAMES, RESERVED_RELATIONSHIP_NAMES, SNAKE_CASE_NAME, SYSTEM_PROPERTIES, humanize, isSystemProperty, toCamelCase, } from "./names.js";
|
|
10
10
|
import { REFERENCE_ANNOTATION, propertyDefinition, propertyOptionNames, unknownPropertyOptions, referenceTarget, } from "./property.js";
|
|
11
11
|
import { generatedActionPermissions, grants, isAllowed, normalizePermission, parsePermission, parseWorkflowPermission, permissionOf, READ_VERB, rolesGranting, USER_IDENTITY_VERBS, USER_MEMBER_VERBS, WILDCARD, wildcardEntityCovers, } from "./permissions.js";
|
|
12
12
|
import { ON_DELETE, isRelationship } from "./relationship.js";
|
|
13
13
|
import { isRole, member, role } from "./role.js";
|
|
14
|
-
import { CHANNEL_PROVIDERS, DEFAULT_SIGN_IN_POLICY, isSignInPolicy, } from "./sign-in.js";
|
|
14
|
+
import { CHANNEL_PROVIDERS, DEFAULT_SIGN_IN_POLICY, SIGN_UP_CHANNELS, SIGN_UP_CHAT_CHANNELS, isSignInPolicy, isSignUpChannel, } from "./sign-in.js";
|
|
15
15
|
import { emailOptions } from "./emails.js";
|
|
16
16
|
import { AgentChat } from "./agent-chat.js";
|
|
17
17
|
import { APP_FEEDBACK_ENTITIES } from "./app-feedback.js";
|
|
@@ -29,6 +29,7 @@ import { cronNeverFires, cronProblem, isAsyncFunction, isWorkflow, isWorkflowTri
|
|
|
29
29
|
import { MAX_WEBHOOK_HEADERS, MAX_WEBHOOKS, WEBHOOK_SIGNATURE_SCHEMES, webhookDelivery, webhookHeaderProblem, WORKSPACE_SECRET_NAME, } from "./webhooks.js";
|
|
30
30
|
import { actionInputToWire } from "./authoring-input.js";
|
|
31
31
|
import { validate } from "./runtime/validation.js";
|
|
32
|
+
import { fixedArgumentsConflict, isToolset, MAXIMUM_TOOLSET_TOOLS, MCP_TOOL_NAME, toolHints, ToolsetLock, withoutFixedArguments, } from "./toolset.js";
|
|
32
33
|
const GENERATED_UPSERT = new RegExp(`^${GENERATED_UPSERT_PREFIX}`);
|
|
33
34
|
/** The providers `chat` may declare a posting connection for, in the order posting lists them. */
|
|
34
35
|
const CHAT_PROVIDER_KEYS = ["telegram", "slack", "whatsapp"];
|
|
@@ -70,7 +71,11 @@ export function analyze(config, options = {}) {
|
|
|
70
71
|
!declaredRoles.some((candidate) => candidate.name === nameToWire(config.hooks.role)))) {
|
|
71
72
|
report("invalid-permission", "hooks.role", "hooks.role must name a declared ontology role.");
|
|
72
73
|
}
|
|
73
|
-
const
|
|
74
|
+
const signInDeclared = signInOptions(config, report);
|
|
75
|
+
const signIn = {
|
|
76
|
+
...signInDeclared,
|
|
77
|
+
...signUpOptions(config, signInDeclared, declaredRoles, report),
|
|
78
|
+
};
|
|
74
79
|
const discovery = config.discovery;
|
|
75
80
|
if (discovery !== undefined &&
|
|
76
81
|
(!isPlainObject(discovery) ||
|
|
@@ -195,7 +200,8 @@ export function analyze(config, options = {}) {
|
|
|
195
200
|
}
|
|
196
201
|
checkEntityIdentities(resolved, report);
|
|
197
202
|
checkMemberNames(resolved, report);
|
|
198
|
-
|
|
203
|
+
const toolsets = resolveToolsets(original.toolsets, resolved, connections, report);
|
|
204
|
+
checkToolNames(resolved, report, toolsets);
|
|
199
205
|
checkWarehouseSource(resolved, report);
|
|
200
206
|
const metrics = resolveModelMetrics({ metrics: config.metrics, entities: resolved, report });
|
|
201
207
|
const workflows = resolveWorkflows({
|
|
@@ -205,21 +211,21 @@ export function analyze(config, options = {}) {
|
|
|
205
211
|
scope,
|
|
206
212
|
checkGrants: options.checkPermissions !== false,
|
|
207
213
|
});
|
|
208
|
-
checkConnectionsUsed(resolved, connections, config.connections ?? [], workflows, report);
|
|
214
|
+
checkConnectionsUsed(resolved, connections, config.connections ?? [], workflows, report, toolsets);
|
|
209
215
|
if (options.checkPermissions !== false) {
|
|
210
216
|
// Validate authored grants before augmentation can replace a scoped grant with an unscoped
|
|
211
217
|
// builder grant. Invalid authored scopes must remain errors; generated redundancy needs no warning.
|
|
212
|
-
checkPermissions(resolved, roles, workflows, report, [
|
|
213
|
-
...declaredRoles,
|
|
214
|
-
...roles.filter((candidate) => candidate.name === FEEDBACK_REPORTER_ROLE),
|
|
215
|
-
]);
|
|
218
|
+
checkPermissions(resolved, roles, workflows, report, [...declaredRoles, ...roles.filter((candidate) => candidate.name === FEEDBACK_REPORTER_ROLE)], toolsets);
|
|
216
219
|
checkOpenWarehouseReads({ entities: resolved, roles, signIn, report });
|
|
217
220
|
checkOpenChannels({ config, entities: resolved, roles, signIn, report });
|
|
218
221
|
checkNewUserAction({ entities: resolved, roles, signIn, report });
|
|
222
|
+
checkSignUpRoles({ entities: resolved, roles, signIn, report });
|
|
223
|
+
checkSignUpAction({ entities: resolved, roles, signIn, report });
|
|
219
224
|
if (feedback.enabled) {
|
|
220
225
|
checkFeedbackResponders(roles, report);
|
|
221
226
|
}
|
|
222
|
-
if (Object.values(signIn.channels ?? {}).includes("open")
|
|
227
|
+
if ((Object.values(signIn.channels ?? {}).includes("open") ||
|
|
228
|
+
SIGN_UP_CHAT_CHANNELS.some((channel) => signIn.signUp?.channels[channel] !== undefined)) &&
|
|
223
229
|
options.agentConfig !== undefined) {
|
|
224
230
|
const contact = options.agentConfig.firstContact;
|
|
225
231
|
const hasNotice = isPlainObject(contact) &&
|
|
@@ -246,6 +252,7 @@ export function analyze(config, options = {}) {
|
|
|
246
252
|
connections,
|
|
247
253
|
metrics,
|
|
248
254
|
workflows,
|
|
255
|
+
toolsets,
|
|
249
256
|
diagnostics,
|
|
250
257
|
...(chat === undefined ? {} : { chat }),
|
|
251
258
|
};
|
|
@@ -807,7 +814,7 @@ function toolOperations(candidate) {
|
|
|
807
814
|
* entity's and the operation's with an underscore, so entity `pilot` with an action `request_find`
|
|
808
815
|
* would take the name of entity `pilot_request`'s `find`.
|
|
809
816
|
*/
|
|
810
|
-
function checkToolNames(entities, report) {
|
|
817
|
+
function checkToolNames(entities, report, toolsets = []) {
|
|
811
818
|
const owners = new Map(MCP_METRIC_TOOLS.map((name) => [name, "the ontology's metric tools"]));
|
|
812
819
|
const seen = new Set();
|
|
813
820
|
for (const candidate of entities) {
|
|
@@ -830,6 +837,205 @@ function checkToolNames(entities, report) {
|
|
|
830
837
|
}
|
|
831
838
|
}
|
|
832
839
|
}
|
|
840
|
+
for (const candidate of toolsets) {
|
|
841
|
+
for (const tool of candidate.tools) {
|
|
842
|
+
const path = `toolsets.${candidate.name}.tools.${tool.name}`;
|
|
843
|
+
const owner = owners.get(tool.mcpName);
|
|
844
|
+
if (owner !== undefined) {
|
|
845
|
+
report("invalid-tool-name", path, `its MCP tool ${tool.mcpName} is already the tool of ${owner}; rename the toolset.`);
|
|
846
|
+
continue;
|
|
847
|
+
}
|
|
848
|
+
owners.set(tool.mcpName, `toolset ${candidate.name}`);
|
|
849
|
+
if (tool.mcpName.length > MCP_TOOL_NAME_MAX_LENGTH) {
|
|
850
|
+
report("invalid-tool-name", path, `its MCP tool ${tool.mcpName} is ${tool.mcpName.length} characters long; agents accept ` +
|
|
851
|
+
`at most ${MCP_TOOL_NAME_MAX_LENGTH}. Shorten the toolset name.`);
|
|
852
|
+
}
|
|
853
|
+
}
|
|
854
|
+
}
|
|
855
|
+
}
|
|
856
|
+
const TOOLSET_KEYS = ["connection", "api", "lock", "description", "tools"];
|
|
857
|
+
/** Names whose tools the service already has: its routes, `chat_*`, `attachments_*` and `files_*`. */
|
|
858
|
+
const RESERVED_TOOLSET_NAMES = [
|
|
859
|
+
...RESERVED_ENTITY_NAMES,
|
|
860
|
+
"attachments",
|
|
861
|
+
"files",
|
|
862
|
+
];
|
|
863
|
+
const FIXED_ARGUMENT = /^[A-Za-z_][A-Za-z0-9_]{0,63}$/;
|
|
864
|
+
/** Arguments the MCP server takes for itself: confirmation presentation and the runtime envelope. */
|
|
865
|
+
const RESERVED_TOOL_ARGUMENTS = ["_confirmation", "_segmentstream"];
|
|
866
|
+
const MAXIMUM_FIXED_ARGUMENTS = 16;
|
|
867
|
+
const MAXIMUM_FIXED_TEXT = 1024;
|
|
868
|
+
const LOCK_AGAIN = "write it again with segmentstream connection mcp lock";
|
|
869
|
+
/**
|
|
870
|
+
* The toolsets `defineOntology({ toolsets })` lists: each named apart from the entities, over a
|
|
871
|
+
* connection listed in `connections`, with a lock written for that connection's API. A toolset with
|
|
872
|
+
* any problem is reported and left out.
|
|
873
|
+
*/
|
|
874
|
+
function resolveToolsets(declared, entities, connections, report) {
|
|
875
|
+
if (declared === undefined) {
|
|
876
|
+
return [];
|
|
877
|
+
}
|
|
878
|
+
if (!Array.isArray(declared)) {
|
|
879
|
+
report("invalid-toolset", "toolsets", "toolsets is a list of toolset(name, { … }) declarations.");
|
|
880
|
+
return [];
|
|
881
|
+
}
|
|
882
|
+
const entityNames = new Set(entities.map((candidate) => candidate.name));
|
|
883
|
+
const keys = new Set(connections.map((candidate) => candidate.key));
|
|
884
|
+
const seen = new Set();
|
|
885
|
+
const resolved = [];
|
|
886
|
+
declared.forEach((candidate, index) => {
|
|
887
|
+
if (!isToolset(candidate)) {
|
|
888
|
+
report("invalid-toolset", `toolsets[${index}]`, "is not a toolset; declare it with toolset(name, { … }).");
|
|
889
|
+
return;
|
|
890
|
+
}
|
|
891
|
+
if (typeof candidate.name !== "string" || !/^[a-z][a-zA-Z0-9]*$/.test(candidate.name)) {
|
|
892
|
+
report("invalid-name", `toolsets[${index}]`, `${JSON.stringify(candidate.name)} is not a toolset name; use a camelCase identifier ` +
|
|
893
|
+
"such as github.");
|
|
894
|
+
return;
|
|
895
|
+
}
|
|
896
|
+
const name = nameToWire(candidate.name);
|
|
897
|
+
const path = `toolsets.${name}`;
|
|
898
|
+
if (seen.has(name)) {
|
|
899
|
+
report("duplicate-name", path, `the toolset ${name} is declared twice.`);
|
|
900
|
+
return;
|
|
901
|
+
}
|
|
902
|
+
seen.add(name);
|
|
903
|
+
if (entityNames.has(name)) {
|
|
904
|
+
report("duplicate-name", path, `${name} is an entity; a toolset needs a name of its own.`);
|
|
905
|
+
return;
|
|
906
|
+
}
|
|
907
|
+
if (RESERVED_TOOLSET_NAMES.includes(name)) {
|
|
908
|
+
report("reserved-name", path, `${name} is reserved: the service's own tools or routes start with it; rename the toolset.`);
|
|
909
|
+
return;
|
|
910
|
+
}
|
|
911
|
+
const definition = candidate.definition;
|
|
912
|
+
if (!isPlainObject(definition)) {
|
|
913
|
+
report("invalid-toolset", path, "a toolset takes { connection, api, lock, description }.");
|
|
914
|
+
return;
|
|
915
|
+
}
|
|
916
|
+
let valid = true;
|
|
917
|
+
const fail = (code, at, message) => {
|
|
918
|
+
report(code, at, message);
|
|
919
|
+
valid = false;
|
|
920
|
+
};
|
|
921
|
+
for (const key of Object.keys(definition)) {
|
|
922
|
+
if (!TOOLSET_KEYS.includes(key)) {
|
|
923
|
+
fail("invalid-toolset", `${path}.${key}`, `a toolset takes only ${TOOLSET_KEYS.join(", ")}.`);
|
|
924
|
+
}
|
|
925
|
+
}
|
|
926
|
+
const { connection, api, lock, description, tools } = definition;
|
|
927
|
+
if (typeof description !== "string" || description.trim() === "") {
|
|
928
|
+
fail("missing-description", `${path}.description`, "describe what the toolset is for, in the workspace's words; agents read it to choose a tool.");
|
|
929
|
+
}
|
|
930
|
+
if (!isConnection(connection)) {
|
|
931
|
+
fail("invalid-connection", `${path}.connection`, "is not a connection; declare it with connection(key, { … }).");
|
|
932
|
+
}
|
|
933
|
+
else if (!keys.has(connection.key)) {
|
|
934
|
+
fail("unknown-connection", `${path}.connection`, `the connection ${String(connection.key)} is not listed in defineOntology({ connections }).`);
|
|
935
|
+
}
|
|
936
|
+
if (typeof api !== "string" || !/^[a-z][a-z0-9_]{0,63}$/.test(api)) {
|
|
937
|
+
fail("invalid-toolset", `${path}.api`, "api names the connection's MCP API in connections/connections.py, such as mcp.");
|
|
938
|
+
}
|
|
939
|
+
const decoded = Schema.decodeUnknownResult(ToolsetLock)(lock);
|
|
940
|
+
if (Result.isFailure(decoded)) {
|
|
941
|
+
fail("invalid-toolset", `${path}.lock`, `is not a toolset lock of this SDK; ${LOCK_AGAIN}.`);
|
|
942
|
+
return;
|
|
943
|
+
}
|
|
944
|
+
const locked = decoded.success;
|
|
945
|
+
if (isConnection(connection) && (locked.connection !== connection.key || locked.api !== api)) {
|
|
946
|
+
fail("toolset-lock-mismatch", `${path}.lock`, `the lock is for ${locked.connection}'s ${locked.api} API, not ` +
|
|
947
|
+
`${String(connection.key)}'s ${String(api)}; ${LOCK_AGAIN} ${String(connection.key)}.`);
|
|
948
|
+
}
|
|
949
|
+
if (locked.tools.length === 0 || locked.tools.length > MAXIMUM_TOOLSET_TOOLS) {
|
|
950
|
+
fail("invalid-toolset", `${path}.lock`, `a toolset serves 1 to ${MAXIMUM_TOOLSET_TOOLS} tools; declare them on the connection's ` +
|
|
951
|
+
`MCP API and ${LOCK_AGAIN}.`);
|
|
952
|
+
}
|
|
953
|
+
const names = new Set();
|
|
954
|
+
for (const tool of locked.tools) {
|
|
955
|
+
const at = `${path}.tools.${tool.name}`;
|
|
956
|
+
if (!MCP_TOOL_NAME.test(tool.name)) {
|
|
957
|
+
fail("invalid-toolset", at, `${JSON.stringify(tool.name)} is not a tool name: lowercase snake_case of at most 64 ` +
|
|
958
|
+
"characters.");
|
|
959
|
+
}
|
|
960
|
+
else if (tool.name === READ_VERB) {
|
|
961
|
+
// `<toolset>:read` is what `*:read` and the OAuth read scope grant.
|
|
962
|
+
fail("invalid-toolset", at, "a tool named read would be granted by *:read and by the OAuth ontology:read scope " +
|
|
963
|
+
"whatever it does; a toolset cannot serve it.");
|
|
964
|
+
}
|
|
965
|
+
else if (names.has(tool.name)) {
|
|
966
|
+
fail("duplicate-name", at, `the lock lists ${tool.name} twice; ${LOCK_AGAIN}.`);
|
|
967
|
+
}
|
|
968
|
+
names.add(tool.name);
|
|
969
|
+
const fixed = Object.entries(tool.fixed);
|
|
970
|
+
if (fixed.length > MAXIMUM_FIXED_ARGUMENTS ||
|
|
971
|
+
fixed.some(([argument, value]) => !FIXED_ARGUMENT.test(argument) ||
|
|
972
|
+
(typeof value === "string" && value.length > MAXIMUM_FIXED_TEXT) ||
|
|
973
|
+
(typeof value === "number" && !Number.isSafeInteger(value)))) {
|
|
974
|
+
fail("invalid-toolset", `${at}.fixed`, `fixed values are at most ${MAXIMUM_FIXED_ARGUMENTS} named strings, booleans and integers ` +
|
|
975
|
+
`of at most 2**53 - 1; ${LOCK_AGAIN}.`);
|
|
976
|
+
}
|
|
977
|
+
if (tool.inputSchema.type !== undefined && tool.inputSchema.type !== "object") {
|
|
978
|
+
fail("invalid-toolset", `${at}.inputSchema`, "a tool's input schema must describe an object.");
|
|
979
|
+
}
|
|
980
|
+
const properties = isPlainObject(tool.inputSchema.properties)
|
|
981
|
+
? Object.keys(tool.inputSchema.properties)
|
|
982
|
+
: [];
|
|
983
|
+
const reserved = [...properties, ...Object.keys(tool.fixed)].find((argument) => RESERVED_TOOL_ARGUMENTS.includes(argument));
|
|
984
|
+
const conflict = fixedArgumentsConflict(tool.inputSchema, tool.fixed, tool.access);
|
|
985
|
+
if (conflict !== undefined) {
|
|
986
|
+
fail("invalid-toolset", `${at}.inputSchema`, `the tool's input uses ${conflict}, which the service cannot adjust for fixed values or ` +
|
|
987
|
+
"for the confirmation argument a write tool takes; serve it as a read without fixed " +
|
|
988
|
+
"values or leave it out.");
|
|
989
|
+
}
|
|
990
|
+
if (reserved !== undefined) {
|
|
991
|
+
// The service consumes these arguments itself before a call reaches the provider.
|
|
992
|
+
fail("invalid-toolset", `${at}.inputSchema`, `the tool takes ${reserved}, an argument the ontology's MCP server reserves; a toolset ` +
|
|
993
|
+
"cannot serve it.");
|
|
994
|
+
}
|
|
995
|
+
}
|
|
996
|
+
if (tools !== undefined) {
|
|
997
|
+
if (!isPlainObject(tools)) {
|
|
998
|
+
fail("invalid-toolset", `${path}.tools`, "tools maps tool names to { description }.");
|
|
999
|
+
}
|
|
1000
|
+
else {
|
|
1001
|
+
for (const [tool, options] of Object.entries(tools)) {
|
|
1002
|
+
const at = `${path}.tools.${tool}`;
|
|
1003
|
+
if (!names.has(tool)) {
|
|
1004
|
+
fail("invalid-toolset", at, `the lock has no tool ${tool}.`);
|
|
1005
|
+
}
|
|
1006
|
+
else if (!isPlainObject(options) ||
|
|
1007
|
+
Object.keys(options).some((key) => key !== "description") ||
|
|
1008
|
+
(options.description !== undefined &&
|
|
1009
|
+
(typeof options.description !== "string" || options.description.trim() === ""))) {
|
|
1010
|
+
fail("invalid-toolset", at, "a tool's options are { description }, a non-empty text.");
|
|
1011
|
+
}
|
|
1012
|
+
}
|
|
1013
|
+
}
|
|
1014
|
+
}
|
|
1015
|
+
if (!valid || !isConnection(connection) || typeof api !== "string") {
|
|
1016
|
+
return;
|
|
1017
|
+
}
|
|
1018
|
+
const overrides = (tools ?? {});
|
|
1019
|
+
resolved.push({
|
|
1020
|
+
name,
|
|
1021
|
+
description: description,
|
|
1022
|
+
connection: connection.key,
|
|
1023
|
+
api,
|
|
1024
|
+
protocolVersion: locked.protocolVersion,
|
|
1025
|
+
tools: locked.tools.map((tool) => ({
|
|
1026
|
+
name: tool.name,
|
|
1027
|
+
mcpName: mcpToolName(name, tool.name),
|
|
1028
|
+
permission: `${name}:${tool.name}`,
|
|
1029
|
+
access: tool.access,
|
|
1030
|
+
fixed: tool.fixed,
|
|
1031
|
+
description: overrides[tool.name]?.description ??
|
|
1032
|
+
(tool.description.trim() === "" ? humanize(tool.name) : tool.description),
|
|
1033
|
+
inputSchema: withoutFixedArguments(tool.inputSchema, tool.fixed),
|
|
1034
|
+
hints: toolHints(tool.access, tool.annotations),
|
|
1035
|
+
})),
|
|
1036
|
+
});
|
|
1037
|
+
});
|
|
1038
|
+
return resolved;
|
|
833
1039
|
}
|
|
834
1040
|
/** The handles `defineOntology({ connections })` lists, each with a valid key and a description. */
|
|
835
1041
|
function collectConnections(config, report) {
|
|
@@ -872,15 +1078,16 @@ function collectConnections(config, report) {
|
|
|
872
1078
|
return connections;
|
|
873
1079
|
}
|
|
874
1080
|
/** A listed connection that no action calls is a leftover: it grants the deployment for nothing. */
|
|
875
|
-
function checkConnectionsUsed(entities, connections, declared, workflows, report) {
|
|
1081
|
+
function checkConnectionsUsed(entities, connections, declared, workflows, report, toolsets = []) {
|
|
876
1082
|
const used = new Set([
|
|
877
1083
|
...entities.flatMap((entity) => entity.actions.flatMap((candidate) => candidate.connections)),
|
|
878
1084
|
...workflows.flatMap((candidate) => candidate.connections),
|
|
1085
|
+
...toolsets.map((candidate) => candidate.connection),
|
|
879
1086
|
]);
|
|
880
1087
|
connections.forEach((candidate) => {
|
|
881
1088
|
if (!used.has(candidate.key)) {
|
|
882
|
-
report("unused-connection", `connections[${declared.indexOf(candidate.handle)}]`, `no action or
|
|
883
|
-
"or a workflow's connections or remove it.");
|
|
1089
|
+
report("unused-connection", `connections[${declared.indexOf(candidate.handle)}]`, `no action, workflow or toolset calls the connection ${candidate.key}; list it in an ` +
|
|
1090
|
+
"action's or a workflow's connections, serve it as a toolset, or remove it.");
|
|
884
1091
|
}
|
|
885
1092
|
});
|
|
886
1093
|
}
|
|
@@ -991,6 +1198,7 @@ function signInOptions(config, report) {
|
|
|
991
1198
|
'(only people invited as members) or "open" (anyone who signs in becomes a member).');
|
|
992
1199
|
return fallback;
|
|
993
1200
|
}
|
|
1201
|
+
// @legacy ontology.legacy-channel-admission
|
|
994
1202
|
const channels = {};
|
|
995
1203
|
if (options.channels !== undefined) {
|
|
996
1204
|
if (!isPlainObject(options.channels)) {
|
|
@@ -1040,6 +1248,200 @@ function signInOptions(config, report) {
|
|
|
1040
1248
|
...(typeof codeLink === "boolean" ? { codeLink } : {}),
|
|
1041
1249
|
};
|
|
1042
1250
|
}
|
|
1251
|
+
/**
|
|
1252
|
+
* Where strangers may sign up and the wire names of the roles each open channel grants, and the
|
|
1253
|
+
* `onSignUp` action. Every role must be a declared one other than `member`. A channel opened both
|
|
1254
|
+
* here and by the earlier `signIn.channels` or `signIn.policy: "open"` is refused.
|
|
1255
|
+
*/
|
|
1256
|
+
function signUpOptions(config, signIn, declaredRoles, report) {
|
|
1257
|
+
const options = config.signUp;
|
|
1258
|
+
const hook = config.onSignUp;
|
|
1259
|
+
const result = {};
|
|
1260
|
+
if (hook !== undefined &&
|
|
1261
|
+
(typeof hook !== "string" || !parsePermission(hook) || hook.includes("*"))) {
|
|
1262
|
+
report("invalid-sign-in", "onSignUp", "Use an action name: <entity>:<action>.");
|
|
1263
|
+
}
|
|
1264
|
+
else if (typeof hook === "string") {
|
|
1265
|
+
if (options === undefined) {
|
|
1266
|
+
report("invalid-sign-in", "onSignUp", "onSignUp runs after sign-up; declare signUp.");
|
|
1267
|
+
}
|
|
1268
|
+
result.onSignUp = hook;
|
|
1269
|
+
}
|
|
1270
|
+
if (options === undefined) {
|
|
1271
|
+
return result;
|
|
1272
|
+
}
|
|
1273
|
+
if (!isPlainObject(options)) {
|
|
1274
|
+
report("invalid-sign-in", "signUp", 'signUp takes { channels: ["telegram", "whatsapp", "email"], roles: [...] }.');
|
|
1275
|
+
return result;
|
|
1276
|
+
}
|
|
1277
|
+
for (const key of Object.keys(options)) {
|
|
1278
|
+
if (!["channels", "roles", "byChannel"].includes(key)) {
|
|
1279
|
+
report("invalid-sign-in", `signUp.${key}`, `Unknown signUp key: ${key}.`);
|
|
1280
|
+
}
|
|
1281
|
+
}
|
|
1282
|
+
const declared = new Set(declaredRoles.map((candidate) => candidate.name).filter((name) => name !== MEMBER_ROLE));
|
|
1283
|
+
const roleNames = (value, path) => {
|
|
1284
|
+
if (!Array.isArray(value)) {
|
|
1285
|
+
report("invalid-sign-in", path, "Use a list of declared roles; [] grants none.");
|
|
1286
|
+
return undefined;
|
|
1287
|
+
}
|
|
1288
|
+
const names = [];
|
|
1289
|
+
value.forEach((candidate, index) => {
|
|
1290
|
+
const name = isRole(candidate)
|
|
1291
|
+
? nameToWire(candidate.name)
|
|
1292
|
+
: typeof candidate === "string"
|
|
1293
|
+
? nameToWire(candidate)
|
|
1294
|
+
: undefined;
|
|
1295
|
+
if (name === MEMBER_ROLE) {
|
|
1296
|
+
report("invalid-sign-in", `${path}[${index}]`, "member is the baseline of invited people; sign-up grants declared roles only.");
|
|
1297
|
+
}
|
|
1298
|
+
else if (name === undefined || !declared.has(name)) {
|
|
1299
|
+
report("invalid-sign-in", `${path}[${index}]`, "Use a role the ontology declares.");
|
|
1300
|
+
}
|
|
1301
|
+
else if (!names.includes(name)) {
|
|
1302
|
+
names.push(name);
|
|
1303
|
+
}
|
|
1304
|
+
});
|
|
1305
|
+
return names;
|
|
1306
|
+
};
|
|
1307
|
+
const channels = [];
|
|
1308
|
+
if (!Array.isArray(options.channels) || options.channels.length === 0) {
|
|
1309
|
+
report("invalid-sign-in", "signUp.channels", `List the channels strangers may sign up through: ${SIGN_UP_CHANNELS.join(", ")}.`);
|
|
1310
|
+
}
|
|
1311
|
+
else {
|
|
1312
|
+
options.channels.forEach((channel, index) => {
|
|
1313
|
+
const path = `signUp.channels[${index}]`;
|
|
1314
|
+
if (!isSignUpChannel(channel)) {
|
|
1315
|
+
report("invalid-sign-in", path, `Unsupported sign-up channel: ${String(channel)}. Use ${SIGN_UP_CHANNELS.join(", ")}.`);
|
|
1316
|
+
}
|
|
1317
|
+
else if (channels.includes(channel)) {
|
|
1318
|
+
report("invalid-sign-in", path, `${channel} is listed twice.`);
|
|
1319
|
+
}
|
|
1320
|
+
else {
|
|
1321
|
+
channels.push(channel);
|
|
1322
|
+
}
|
|
1323
|
+
});
|
|
1324
|
+
}
|
|
1325
|
+
const roles = roleNames(options.roles, "signUp.roles");
|
|
1326
|
+
const byChannel = {};
|
|
1327
|
+
if (options.byChannel !== undefined) {
|
|
1328
|
+
if (!isPlainObject(options.byChannel)) {
|
|
1329
|
+
report("invalid-sign-in", "signUp.byChannel", "byChannel maps a listed channel to its roles.");
|
|
1330
|
+
}
|
|
1331
|
+
else {
|
|
1332
|
+
for (const [channel, value] of Object.entries(options.byChannel)) {
|
|
1333
|
+
const path = `signUp.byChannel.${channel}`;
|
|
1334
|
+
if (!isSignUpChannel(channel) || !channels.includes(channel)) {
|
|
1335
|
+
report("invalid-sign-in", path, "byChannel names only channels listed in channels.");
|
|
1336
|
+
continue;
|
|
1337
|
+
}
|
|
1338
|
+
const names = roleNames(value, path);
|
|
1339
|
+
if (names !== undefined) {
|
|
1340
|
+
byChannel[channel] = names;
|
|
1341
|
+
}
|
|
1342
|
+
}
|
|
1343
|
+
}
|
|
1344
|
+
}
|
|
1345
|
+
for (const channel of channels) {
|
|
1346
|
+
// @legacy ontology.legacy-channel-admission
|
|
1347
|
+
const legacyOpen = channel === "email"
|
|
1348
|
+
? signIn.policy === "open"
|
|
1349
|
+
: signIn.channels?.[channel] === "open";
|
|
1350
|
+
if (legacyOpen) {
|
|
1351
|
+
report("invalid-sign-in", `signUp.channels`, channel === "email"
|
|
1352
|
+
? 'email is opened by signIn.policy "open" too; declare it in signUp only.'
|
|
1353
|
+
: `${channel} is opened by signIn.channels too; declare it in signUp only.`);
|
|
1354
|
+
}
|
|
1355
|
+
if (SIGN_UP_CHAT_CHANNELS.includes(channel)) {
|
|
1356
|
+
const adapters = config.chat;
|
|
1357
|
+
if (adapters?.[channel] === undefined) {
|
|
1358
|
+
report("invalid-sign-in", `signUp.channels`, `Signing up on ${channel} needs a matching chat.${channel} adapter.`);
|
|
1359
|
+
}
|
|
1360
|
+
}
|
|
1361
|
+
}
|
|
1362
|
+
if (channels.length > 0 && roles !== undefined) {
|
|
1363
|
+
result.signUp = {
|
|
1364
|
+
channels: Object.fromEntries(channels.map((channel) => [channel, byChannel[channel] ?? roles])),
|
|
1365
|
+
};
|
|
1366
|
+
}
|
|
1367
|
+
return result;
|
|
1368
|
+
}
|
|
1369
|
+
/**
|
|
1370
|
+
* The roles sign-up grants admit strangers. Each must be explicitly reviewed: no entity wildcard,
|
|
1371
|
+
* and no generated create, update, delete, link or unlink that is not scoped to the person's own
|
|
1372
|
+
* records. An unscoped read of a stored entity is a shared read, warned about for review.
|
|
1373
|
+
*/
|
|
1374
|
+
function checkSignUpRoles(input) {
|
|
1375
|
+
const { entities, roles, signIn, report } = input;
|
|
1376
|
+
const granted = new Set(Object.values(signIn.signUp?.channels ?? {}).flat());
|
|
1377
|
+
const hint = "Scope it to the person's own records or use an ownership-checked action.";
|
|
1378
|
+
for (const name of granted) {
|
|
1379
|
+
const candidate = roles.find((declared) => declared.name === name);
|
|
1380
|
+
if (candidate === undefined || !Array.isArray(candidate.permissions)) {
|
|
1381
|
+
continue;
|
|
1382
|
+
}
|
|
1383
|
+
const scoped = new Set((candidate.scopes ?? []).map((scope) => scope.permission));
|
|
1384
|
+
const path = `roles.${name}.permissions`;
|
|
1385
|
+
for (const permission of candidate.permissions) {
|
|
1386
|
+
const parsed = parsePermission(permission);
|
|
1387
|
+
const entity = entities.find((resolved) => resolved.name === parsed?.entity);
|
|
1388
|
+
if (parsed?.entity === WILDCARD) {
|
|
1389
|
+
report("invalid-sign-in", path, `${name} is granted on sign-up and cannot hold ${permission}; name the entities it may use.`);
|
|
1390
|
+
continue;
|
|
1391
|
+
}
|
|
1392
|
+
if (entity === undefined || scoped.has(permission)) {
|
|
1393
|
+
continue;
|
|
1394
|
+
}
|
|
1395
|
+
const generatedWrite = [
|
|
1396
|
+
entity.permissions.create,
|
|
1397
|
+
entity.permissions.update,
|
|
1398
|
+
entity.permissions.delete,
|
|
1399
|
+
entity.permissions.link,
|
|
1400
|
+
entity.permissions.unlink,
|
|
1401
|
+
].some((required) => required !== undefined && isAllowed(required, { permissions: [permission] }));
|
|
1402
|
+
if (generatedWrite) {
|
|
1403
|
+
report("invalid-sign-in", path, `${name} is granted on sign-up and cannot hold ${permission} on every record. ${hint}`);
|
|
1404
|
+
}
|
|
1405
|
+
else if (isAllowed(entity.permissions.read, { permissions: [permission] })) {
|
|
1406
|
+
report("invalid-sign-in", path, `${name} is granted on sign-up; ${permission} lets anyone who signs up read every ` +
|
|
1407
|
+
`${entity.name}. Review it, or scope it to the person's own records.`, "warning");
|
|
1408
|
+
}
|
|
1409
|
+
}
|
|
1410
|
+
}
|
|
1411
|
+
}
|
|
1412
|
+
/** The sign-up hook runs with each channel's roles and cannot enter the external preparation phase. */
|
|
1413
|
+
function checkSignUpAction(input) {
|
|
1414
|
+
const { entities, roles, signIn, report } = input;
|
|
1415
|
+
if (signIn.onSignUp === undefined) {
|
|
1416
|
+
return;
|
|
1417
|
+
}
|
|
1418
|
+
const parsed = parsePermission(signIn.onSignUp);
|
|
1419
|
+
const found = entities
|
|
1420
|
+
.find((entity) => entity.name === parsed?.entity)
|
|
1421
|
+
?.actions.find((candidate) => candidate.name === parsed?.verb);
|
|
1422
|
+
const fail = (message) => report("invalid-sign-in", "onSignUp", message);
|
|
1423
|
+
if (found === undefined) {
|
|
1424
|
+
fail("onSignUp must name an existing authored action.");
|
|
1425
|
+
return;
|
|
1426
|
+
}
|
|
1427
|
+
if (Result.isFailure(Schema.decodeUnknownResult(found.action.input)({}))) {
|
|
1428
|
+
fail("onSignUp cannot have required input; it is called with {}.");
|
|
1429
|
+
}
|
|
1430
|
+
for (const [channel, granted] of Object.entries(signIn.signUp?.channels ?? {})) {
|
|
1431
|
+
const permissions = roles
|
|
1432
|
+
.filter((candidate) => granted.includes(candidate.name))
|
|
1433
|
+
.flatMap((candidate) => (Array.isArray(candidate.permissions) ? candidate.permissions : []));
|
|
1434
|
+
if (!isAllowed(found.permission, { permissions })) {
|
|
1435
|
+
fail(`onSignUp must be runnable by the roles ${channel} sign-up grants.`);
|
|
1436
|
+
}
|
|
1437
|
+
}
|
|
1438
|
+
if (found.action.hints?.idempotent !== true) {
|
|
1439
|
+
fail("onSignUp must declare hints.idempotent: true.");
|
|
1440
|
+
}
|
|
1441
|
+
if (found.action.prepare !== undefined || found.action.connections.length > 0) {
|
|
1442
|
+
fail("onSignUp cannot prepare or use external connections.");
|
|
1443
|
+
}
|
|
1444
|
+
}
|
|
1043
1445
|
function collectRoles(config, report) {
|
|
1044
1446
|
const roles = [memberRole(config, report)];
|
|
1045
1447
|
(config.roles ?? []).forEach((candidate, index) => {
|
|
@@ -1827,8 +2229,12 @@ function ownMembers(candidate, entitiesByName) {
|
|
|
1827
2229
|
* built-in user also has its member management verbs, and the built-in sign-in identities their
|
|
1828
2230
|
* attach and revoke, which roles may grant.
|
|
1829
2231
|
*/
|
|
1830
|
-
function knownVerbs(entities) {
|
|
2232
|
+
function knownVerbs(entities, toolsets = []) {
|
|
1831
2233
|
const verbs = new Map();
|
|
2234
|
+
// A toolset's tools are its verbs. Entity names are checked against toolset names elsewhere.
|
|
2235
|
+
for (const candidate of toolsets) {
|
|
2236
|
+
verbs.set(candidate.name, new Set(candidate.tools.map((tool) => tool.name)));
|
|
2237
|
+
}
|
|
1832
2238
|
for (const candidate of entities) {
|
|
1833
2239
|
const own = verbs.get(candidate.name) ?? new Set();
|
|
1834
2240
|
for (const permission of Object.values(candidate.permissions)) {
|
|
@@ -1921,6 +2327,7 @@ function checkRolePermissions(candidate, verbs, workflows, report) {
|
|
|
1921
2327
|
}
|
|
1922
2328
|
});
|
|
1923
2329
|
}
|
|
2330
|
+
// @legacy ontology.legacy-channel-admission
|
|
1924
2331
|
/**
|
|
1925
2332
|
* Under the open policy anyone who signs in holds `member`. Warehouse-backed entities hold company
|
|
1926
2333
|
* figures, such as revenue or stock, that metric queries read with `<entity>:read`; a wildcard of
|
|
@@ -1952,6 +2359,7 @@ function checkOpenWarehouseReads(input) {
|
|
|
1952
2359
|
`(${warehouseBacked.join(", ")}). Grant them to member by name, such as ` +
|
|
1953
2360
|
`${warehouseBacked[0]}:read, or use the invited policy.`);
|
|
1954
2361
|
}
|
|
2362
|
+
// @legacy ontology.legacy-channel-admission
|
|
1955
2363
|
/** Public channels admit strangers with explicitly reviewed baseline grants. */
|
|
1956
2364
|
function checkOpenChannels(input) {
|
|
1957
2365
|
const { config, entities, roles, signIn, report } = input;
|
|
@@ -1988,6 +2396,7 @@ function checkOpenChannels(input) {
|
|
|
1988
2396
|
}
|
|
1989
2397
|
}
|
|
1990
2398
|
}
|
|
2399
|
+
// @legacy ontology.legacy-channel-admission
|
|
1991
2400
|
/** The hook has only member authority and cannot enter the external preparation phase. */
|
|
1992
2401
|
function checkNewUserAction(input) {
|
|
1993
2402
|
const { entities, roles, signIn, report } = input;
|
|
@@ -2043,8 +2452,8 @@ function checkRosterReads(roles, report) {
|
|
|
2043
2452
|
* action that no role grants is a warning. Generated actions are not warned about: they stay closed
|
|
2044
2453
|
* until a role grants them.
|
|
2045
2454
|
*/
|
|
2046
|
-
function checkPermissions(entities, roles, workflows, report, authoredRoles = roles) {
|
|
2047
|
-
const verbs = knownVerbs(entities);
|
|
2455
|
+
function checkPermissions(entities, roles, workflows, report, authoredRoles = roles, toolsets = []) {
|
|
2456
|
+
const verbs = knownVerbs(entities, toolsets);
|
|
2048
2457
|
const workflowNames = new Set(workflows.map((candidate) => candidate.name));
|
|
2049
2458
|
for (const candidate of authoredRoles) {
|
|
2050
2459
|
checkRolePermissions(candidate, verbs, workflowNames, report);
|
|
@@ -2335,6 +2744,11 @@ function checkScope(input) {
|
|
|
2335
2744
|
return;
|
|
2336
2745
|
}
|
|
2337
2746
|
const entity = entities.find((candidate) => candidate.name === parsed.entity);
|
|
2747
|
+
if (entity === undefined && verbs.get(parsed.entity)?.has(parsed.verb) === true) {
|
|
2748
|
+
report("invalid-scope", path, `${parsed.entity} is a toolset, which has no records to scope; list ${permission} as a ` +
|
|
2749
|
+
"string in the roles that may call the tool.");
|
|
2750
|
+
return;
|
|
2751
|
+
}
|
|
2338
2752
|
if (entity === undefined || verbs.get(parsed.entity)?.has(parsed.verb) !== true) {
|
|
2339
2753
|
return;
|
|
2340
2754
|
}
|
package/dist/authoring.js
CHANGED
|
@@ -321,6 +321,9 @@ export function authoringToWire(config, builtIns, report) {
|
|
|
321
321
|
if (isRecord(config.signIn) && typeof config.signIn.onNewUser === "string") {
|
|
322
322
|
normalized.signIn = { ...config.signIn, onNewUser: permissionToWire(config.signIn.onNewUser) };
|
|
323
323
|
}
|
|
324
|
+
if (typeof config.onSignUp === "string") {
|
|
325
|
+
normalized.onSignUp = permissionToWire(config.onSignUp);
|
|
326
|
+
}
|
|
324
327
|
if (isRecord(config.member) && Array.isArray(config.member.permissions)) {
|
|
325
328
|
normalized.member = {
|
|
326
329
|
...config.member,
|
package/dist/bin/check.js
CHANGED
|
@@ -16,6 +16,7 @@ export function catalogSummary(manifest) {
|
|
|
16
16
|
const actions = manifest.entities.flatMap((entity) => entity.actions.map((action) => `${entity.name}.${action.name}`));
|
|
17
17
|
const roles = manifest.roles.map((role) => role.name);
|
|
18
18
|
const workflows = (manifest.workflows ?? []).map((workflow) => workflow.name);
|
|
19
|
+
const tools = (manifest.toolsets ?? []).flatMap((toolset) => toolset.tools.map((tool) => `${toolset.name}_${tool.name} (${tool.access})`));
|
|
19
20
|
return [
|
|
20
21
|
`Entities: ${listed(entities.length, entities)}`,
|
|
21
22
|
`Properties: ${properties}`,
|
|
@@ -31,6 +32,7 @@ export function catalogSummary(manifest) {
|
|
|
31
32
|
`builders: ${manifest.feedback.builders.join(", ") || "none"}`,
|
|
32
33
|
]),
|
|
33
34
|
...(workflows.length > 0 ? [`Workflows: ${listed(workflows.length, workflows)}`] : []),
|
|
35
|
+
...(tools.length > 0 ? [`Toolset tools: ${listed(tools.length, tools)}`] : []),
|
|
34
36
|
`Manifest hash: ${manifest.hash}`,
|
|
35
37
|
"",
|
|
36
38
|
].join("\n");
|