@segmentstream/ontology 0.96.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 +11 -0
- package/dist/analyze.d.ts +8 -0
- package/dist/analyze.js +223 -14
- 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 +2 -0
- package/dist/index.js +1 -0
- package/dist/manifest.d.ts +505 -2
- package/dist/manifest.js +55 -2
- package/dist/migrate/model.d.ts +272 -0
- package/dist/ontology.d.ts +3 -0
- package/dist/ontology.js +1 -0
- package/dist/service/catalog.js +10 -1
- package/dist/service/chat/envelope.d.ts +14 -14
- 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 +62 -0
- package/dist/service/toolsets.d.ts +49 -0
- package/dist/service/toolsets.js +284 -0
- package/dist/toolset.d.ts +141 -0
- package/dist/toolset.js +154 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1241,6 +1241,17 @@ is visible. Attachment guidance appears only when attach is visible. The caller
|
|
|
1241
1241
|
problem, asks approval for the title and summary, then later reports and acknowledges the answer.
|
|
1242
1242
|
Builders use `segmentstream ontology feedback list`, `show` and `respond` as their app member.
|
|
1243
1243
|
|
|
1244
|
+
## Toolsets
|
|
1245
|
+
|
|
1246
|
+
`toolset(name, { connection, api, lock, description })` serves the tools of a connection's MCP
|
|
1247
|
+
API from the ontology's MCP server: each tool in the lock, written by
|
|
1248
|
+
`segmentstream connection mcp lock <key>`, is the MCP tool `<toolset>_<tool>`, granted by
|
|
1249
|
+
`<toolset>:<tool>` or `<toolset>:*`. A read tool needs no confirmation; every other tool is
|
|
1250
|
+
confirmed. Fixed values the connection declares are removed from the tool's input and added to each
|
|
1251
|
+
call, and backend-next admits only the declared tools and values. A toolset has no records. It is
|
|
1252
|
+
served over MCP only: not by the REST API, to workflows or under the OAuth `ontology:read` scope.
|
|
1253
|
+
See [MCP connections](https://github.com/segmentstream/segmentstream/blob/main/docs/mcp-connections-spec.md).
|
|
1254
|
+
|
|
1244
1255
|
## Agents
|
|
1245
1256
|
|
|
1246
1257
|
The app's own agent runs in the same Vercel project as the service and calls it as the
|
package/dist/analyze.d.ts
CHANGED
|
@@ -14,6 +14,7 @@ import { type ModelMetricManifest, type WorkflowManifest } from "./manifest.js";
|
|
|
14
14
|
import type { ModelMetrics } from "./metric.js";
|
|
15
15
|
import { type EarlierMetricsField } from "./legacy.js";
|
|
16
16
|
import { type AnyWorkflow } from "./workflow.js";
|
|
17
|
+
import { type ResolvedToolset, type Toolset } from "./toolset.js";
|
|
17
18
|
/** The input of `defineOntology` and `check`. */
|
|
18
19
|
export interface OntologyConfig<Entities extends ReadonlyArray<AnyEntity> = ReadonlyArray<AnyEntity>, Metrics extends ModelMetrics = ModelMetrics> extends EarlierMetricsField<Metrics> {
|
|
19
20
|
/**
|
|
@@ -77,6 +78,11 @@ export interface OntologyConfig<Entities extends ReadonlyArray<AnyEntity> = Read
|
|
|
77
78
|
* handle an action lists must be here, and every handle here must be used by an action.
|
|
78
79
|
*/
|
|
79
80
|
readonly connections?: ReadonlyArray<AnyConnectionHandle>;
|
|
81
|
+
/**
|
|
82
|
+
* Provider MCP tools the ontology serves, each declared with `toolset(name, { … })` over a
|
|
83
|
+
* connection's MCP API. Their connections must be listed in `connections`.
|
|
84
|
+
*/
|
|
85
|
+
readonly toolsets?: ReadonlyArray<Toolset>;
|
|
80
86
|
/**
|
|
81
87
|
* The providers the built-in exact chat post delivers to, each through its connection, which
|
|
82
88
|
* must be listed in `connections`. Only declared providers are destinations.
|
|
@@ -226,6 +232,8 @@ export interface Analysis {
|
|
|
226
232
|
readonly metrics: ReadonlyArray<ModelMetricManifest>;
|
|
227
233
|
/** The workflows that passed `check`, in their manifest form: wire names and wire input. */
|
|
228
234
|
readonly workflows: ReadonlyArray<WorkflowManifest>;
|
|
235
|
+
/** The toolsets that passed `check`, with wire names. */
|
|
236
|
+
readonly toolsets: ReadonlyArray<ResolvedToolset>;
|
|
229
237
|
readonly diagnostics: ReadonlyArray<Diagnostic>;
|
|
230
238
|
}
|
|
231
239
|
/**
|
package/dist/analyze.js
CHANGED
|
@@ -6,7 +6,7 @@ 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";
|
|
@@ -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"];
|
|
@@ -199,7 +200,8 @@ export function analyze(config, options = {}) {
|
|
|
199
200
|
}
|
|
200
201
|
checkEntityIdentities(resolved, report);
|
|
201
202
|
checkMemberNames(resolved, report);
|
|
202
|
-
|
|
203
|
+
const toolsets = resolveToolsets(original.toolsets, resolved, connections, report);
|
|
204
|
+
checkToolNames(resolved, report, toolsets);
|
|
203
205
|
checkWarehouseSource(resolved, report);
|
|
204
206
|
const metrics = resolveModelMetrics({ metrics: config.metrics, entities: resolved, report });
|
|
205
207
|
const workflows = resolveWorkflows({
|
|
@@ -209,14 +211,11 @@ export function analyze(config, options = {}) {
|
|
|
209
211
|
scope,
|
|
210
212
|
checkGrants: options.checkPermissions !== false,
|
|
211
213
|
});
|
|
212
|
-
checkConnectionsUsed(resolved, connections, config.connections ?? [], workflows, report);
|
|
214
|
+
checkConnectionsUsed(resolved, connections, config.connections ?? [], workflows, report, toolsets);
|
|
213
215
|
if (options.checkPermissions !== false) {
|
|
214
216
|
// Validate authored grants before augmentation can replace a scoped grant with an unscoped
|
|
215
217
|
// builder grant. Invalid authored scopes must remain errors; generated redundancy needs no warning.
|
|
216
|
-
checkPermissions(resolved, roles, workflows, report, [
|
|
217
|
-
...declaredRoles,
|
|
218
|
-
...roles.filter((candidate) => candidate.name === FEEDBACK_REPORTER_ROLE),
|
|
219
|
-
]);
|
|
218
|
+
checkPermissions(resolved, roles, workflows, report, [...declaredRoles, ...roles.filter((candidate) => candidate.name === FEEDBACK_REPORTER_ROLE)], toolsets);
|
|
220
219
|
checkOpenWarehouseReads({ entities: resolved, roles, signIn, report });
|
|
221
220
|
checkOpenChannels({ config, entities: resolved, roles, signIn, report });
|
|
222
221
|
checkNewUserAction({ entities: resolved, roles, signIn, report });
|
|
@@ -253,6 +252,7 @@ export function analyze(config, options = {}) {
|
|
|
253
252
|
connections,
|
|
254
253
|
metrics,
|
|
255
254
|
workflows,
|
|
255
|
+
toolsets,
|
|
256
256
|
diagnostics,
|
|
257
257
|
...(chat === undefined ? {} : { chat }),
|
|
258
258
|
};
|
|
@@ -814,7 +814,7 @@ function toolOperations(candidate) {
|
|
|
814
814
|
* entity's and the operation's with an underscore, so entity `pilot` with an action `request_find`
|
|
815
815
|
* would take the name of entity `pilot_request`'s `find`.
|
|
816
816
|
*/
|
|
817
|
-
function checkToolNames(entities, report) {
|
|
817
|
+
function checkToolNames(entities, report, toolsets = []) {
|
|
818
818
|
const owners = new Map(MCP_METRIC_TOOLS.map((name) => [name, "the ontology's metric tools"]));
|
|
819
819
|
const seen = new Set();
|
|
820
820
|
for (const candidate of entities) {
|
|
@@ -837,6 +837,205 @@ function checkToolNames(entities, report) {
|
|
|
837
837
|
}
|
|
838
838
|
}
|
|
839
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;
|
|
840
1039
|
}
|
|
841
1040
|
/** The handles `defineOntology({ connections })` lists, each with a valid key and a description. */
|
|
842
1041
|
function collectConnections(config, report) {
|
|
@@ -879,15 +1078,16 @@ function collectConnections(config, report) {
|
|
|
879
1078
|
return connections;
|
|
880
1079
|
}
|
|
881
1080
|
/** A listed connection that no action calls is a leftover: it grants the deployment for nothing. */
|
|
882
|
-
function checkConnectionsUsed(entities, connections, declared, workflows, report) {
|
|
1081
|
+
function checkConnectionsUsed(entities, connections, declared, workflows, report, toolsets = []) {
|
|
883
1082
|
const used = new Set([
|
|
884
1083
|
...entities.flatMap((entity) => entity.actions.flatMap((candidate) => candidate.connections)),
|
|
885
1084
|
...workflows.flatMap((candidate) => candidate.connections),
|
|
1085
|
+
...toolsets.map((candidate) => candidate.connection),
|
|
886
1086
|
]);
|
|
887
1087
|
connections.forEach((candidate) => {
|
|
888
1088
|
if (!used.has(candidate.key)) {
|
|
889
|
-
report("unused-connection", `connections[${declared.indexOf(candidate.handle)}]`, `no action or
|
|
890
|
-
"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.");
|
|
891
1091
|
}
|
|
892
1092
|
});
|
|
893
1093
|
}
|
|
@@ -2029,8 +2229,12 @@ function ownMembers(candidate, entitiesByName) {
|
|
|
2029
2229
|
* built-in user also has its member management verbs, and the built-in sign-in identities their
|
|
2030
2230
|
* attach and revoke, which roles may grant.
|
|
2031
2231
|
*/
|
|
2032
|
-
function knownVerbs(entities) {
|
|
2232
|
+
function knownVerbs(entities, toolsets = []) {
|
|
2033
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
|
+
}
|
|
2034
2238
|
for (const candidate of entities) {
|
|
2035
2239
|
const own = verbs.get(candidate.name) ?? new Set();
|
|
2036
2240
|
for (const permission of Object.values(candidate.permissions)) {
|
|
@@ -2248,8 +2452,8 @@ function checkRosterReads(roles, report) {
|
|
|
2248
2452
|
* action that no role grants is a warning. Generated actions are not warned about: they stay closed
|
|
2249
2453
|
* until a role grants them.
|
|
2250
2454
|
*/
|
|
2251
|
-
function checkPermissions(entities, roles, workflows, report, authoredRoles = roles) {
|
|
2252
|
-
const verbs = knownVerbs(entities);
|
|
2455
|
+
function checkPermissions(entities, roles, workflows, report, authoredRoles = roles, toolsets = []) {
|
|
2456
|
+
const verbs = knownVerbs(entities, toolsets);
|
|
2253
2457
|
const workflowNames = new Set(workflows.map((candidate) => candidate.name));
|
|
2254
2458
|
for (const candidate of authoredRoles) {
|
|
2255
2459
|
checkRolePermissions(candidate, verbs, workflowNames, report);
|
|
@@ -2540,6 +2744,11 @@ function checkScope(input) {
|
|
|
2540
2744
|
return;
|
|
2541
2745
|
}
|
|
2542
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
|
+
}
|
|
2543
2752
|
if (entity === undefined || verbs.get(parsed.entity)?.has(parsed.verb) !== true) {
|
|
2544
2753
|
return;
|
|
2545
2754
|
}
|
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");
|
package/dist/diagnostics.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { Schema } from "effect";
|
|
2
|
-
export declare const DIAGNOSTIC_CODES: readonly ["invalid-source", "missing-column", "invalid-column", "invalid-scope", "invalid-scope-path", "scope-reads-all", "scope-unused", "scope-member-overlap", "source-with-actions", "source-with-index", "invalid-metric", "unknown-metric", "circular-metric", "invalid-join", "missing-join", "invalid-entity", "invalid-property", "invalid-relationship", "invalid-actions", "invalid-action", "invalid-action-input", "invalid-role", "invalid-name", "reserved-name", "duplicate-name", "invalid-entity-id", "duplicate-entity-id", "missing-label", "missing-description", "invalid-title", "invalid-options", "invalid-default", "invalid-constraint", "unknown-relationship-target", "inverse-collision", "invalid-on-delete", "invalid-phrase", "invalid-index", "unknown-reference", "invalid-renamed-from", "earlier-name", "invalid-guide", "invalid-writes", "generated-update-empty", "managed-without-effect", "missing-permissions", "invalid-permission", "unknown-permission", "removed-allow", "unreachable-action", "wildcard-permission", "invalid-sign-in", "invalid-connection", "invalid-feedback", "invalid-discovery", "invalid-email", "feedback-unanswerable", "unknown-connection", "unused-connection", "invalid-prepare", "invalid-tool-name", "invalid-alignment", "single-entity-model-metric", "invalid-workflow", "workflow_role_unknown", "workflow_role_is_member", "workflow_role_grants_nothing", "workflow_role_wildcard", "workflow_role_scoped", "workflow_cron_never_fires", "workflow_input_invalid", "workflow_cron_invalid", "workflow_run_missing", "invalid-trigger", "trigger_action_unknown", "trigger_function_async", "workflow_trigger_limit_exceeded", "workflow_webhook_duplicate", "workflow_webhook_input_invalid", "workflow_webhook_mixed_triggers", "workflow_webhook_signature_invalid", "workflow_webhook_verification_invalid", "workflow_webhook_headers_invalid", "workflow_webhook_limit_exceeded"];
|
|
2
|
+
export declare const DIAGNOSTIC_CODES: readonly ["invalid-source", "missing-column", "invalid-column", "invalid-scope", "invalid-scope-path", "scope-reads-all", "scope-unused", "scope-member-overlap", "source-with-actions", "source-with-index", "invalid-metric", "unknown-metric", "circular-metric", "invalid-join", "missing-join", "invalid-entity", "invalid-property", "invalid-relationship", "invalid-actions", "invalid-action", "invalid-action-input", "invalid-role", "invalid-name", "reserved-name", "duplicate-name", "invalid-entity-id", "duplicate-entity-id", "missing-label", "missing-description", "invalid-title", "invalid-options", "invalid-default", "invalid-constraint", "unknown-relationship-target", "inverse-collision", "invalid-on-delete", "invalid-phrase", "invalid-index", "unknown-reference", "invalid-renamed-from", "earlier-name", "invalid-guide", "invalid-writes", "generated-update-empty", "managed-without-effect", "missing-permissions", "invalid-permission", "unknown-permission", "removed-allow", "unreachable-action", "wildcard-permission", "invalid-sign-in", "invalid-connection", "invalid-feedback", "invalid-discovery", "invalid-email", "feedback-unanswerable", "unknown-connection", "unused-connection", "invalid-prepare", "invalid-tool-name", "invalid-toolset", "toolset-lock-mismatch", "invalid-alignment", "single-entity-model-metric", "invalid-workflow", "workflow_role_unknown", "workflow_role_is_member", "workflow_role_grants_nothing", "workflow_role_wildcard", "workflow_role_scoped", "workflow_cron_never_fires", "workflow_input_invalid", "workflow_cron_invalid", "workflow_run_missing", "invalid-trigger", "trigger_action_unknown", "trigger_function_async", "workflow_trigger_limit_exceeded", "workflow_webhook_duplicate", "workflow_webhook_input_invalid", "workflow_webhook_mixed_triggers", "workflow_webhook_signature_invalid", "workflow_webhook_verification_invalid", "workflow_webhook_headers_invalid", "workflow_webhook_limit_exceeded"];
|
|
3
3
|
export type DiagnosticCode = (typeof DIAGNOSTIC_CODES)[number];
|
|
4
4
|
/** A problem `check` found in an ontology definition. */
|
|
5
5
|
export declare const Diagnostic: Schema.Struct<{
|
|
6
6
|
readonly severity: Schema.Literals<readonly ["error", "warning", "info"]>;
|
|
7
|
-
readonly code: Schema.Literals<readonly ["invalid-source", "missing-column", "invalid-column", "invalid-scope", "invalid-scope-path", "scope-reads-all", "scope-unused", "scope-member-overlap", "source-with-actions", "source-with-index", "invalid-metric", "unknown-metric", "circular-metric", "invalid-join", "missing-join", "invalid-entity", "invalid-property", "invalid-relationship", "invalid-actions", "invalid-action", "invalid-action-input", "invalid-role", "invalid-name", "reserved-name", "duplicate-name", "invalid-entity-id", "duplicate-entity-id", "missing-label", "missing-description", "invalid-title", "invalid-options", "invalid-default", "invalid-constraint", "unknown-relationship-target", "inverse-collision", "invalid-on-delete", "invalid-phrase", "invalid-index", "unknown-reference", "invalid-renamed-from", "earlier-name", "invalid-guide", "invalid-writes", "generated-update-empty", "managed-without-effect", "missing-permissions", "invalid-permission", "unknown-permission", "removed-allow", "unreachable-action", "wildcard-permission", "invalid-sign-in", "invalid-connection", "invalid-feedback", "invalid-discovery", "invalid-email", "feedback-unanswerable", "unknown-connection", "unused-connection", "invalid-prepare", "invalid-tool-name", "invalid-alignment", "single-entity-model-metric", "invalid-workflow", "workflow_role_unknown", "workflow_role_is_member", "workflow_role_grants_nothing", "workflow_role_wildcard", "workflow_role_scoped", "workflow_cron_never_fires", "workflow_input_invalid", "workflow_cron_invalid", "workflow_run_missing", "invalid-trigger", "trigger_action_unknown", "trigger_function_async", "workflow_trigger_limit_exceeded", "workflow_webhook_duplicate", "workflow_webhook_input_invalid", "workflow_webhook_mixed_triggers", "workflow_webhook_signature_invalid", "workflow_webhook_verification_invalid", "workflow_webhook_headers_invalid", "workflow_webhook_limit_exceeded"]>;
|
|
7
|
+
readonly code: Schema.Literals<readonly ["invalid-source", "missing-column", "invalid-column", "invalid-scope", "invalid-scope-path", "scope-reads-all", "scope-unused", "scope-member-overlap", "source-with-actions", "source-with-index", "invalid-metric", "unknown-metric", "circular-metric", "invalid-join", "missing-join", "invalid-entity", "invalid-property", "invalid-relationship", "invalid-actions", "invalid-action", "invalid-action-input", "invalid-role", "invalid-name", "reserved-name", "duplicate-name", "invalid-entity-id", "duplicate-entity-id", "missing-label", "missing-description", "invalid-title", "invalid-options", "invalid-default", "invalid-constraint", "unknown-relationship-target", "inverse-collision", "invalid-on-delete", "invalid-phrase", "invalid-index", "unknown-reference", "invalid-renamed-from", "earlier-name", "invalid-guide", "invalid-writes", "generated-update-empty", "managed-without-effect", "missing-permissions", "invalid-permission", "unknown-permission", "removed-allow", "unreachable-action", "wildcard-permission", "invalid-sign-in", "invalid-connection", "invalid-feedback", "invalid-discovery", "invalid-email", "feedback-unanswerable", "unknown-connection", "unused-connection", "invalid-prepare", "invalid-tool-name", "invalid-toolset", "toolset-lock-mismatch", "invalid-alignment", "single-entity-model-metric", "invalid-workflow", "workflow_role_unknown", "workflow_role_is_member", "workflow_role_grants_nothing", "workflow_role_wildcard", "workflow_role_scoped", "workflow_cron_never_fires", "workflow_input_invalid", "workflow_cron_invalid", "workflow_run_missing", "invalid-trigger", "trigger_action_unknown", "trigger_function_async", "workflow_trigger_limit_exceeded", "workflow_webhook_duplicate", "workflow_webhook_input_invalid", "workflow_webhook_mixed_triggers", "workflow_webhook_signature_invalid", "workflow_webhook_verification_invalid", "workflow_webhook_headers_invalid", "workflow_webhook_limit_exceeded"]>;
|
|
8
8
|
/** Where the problem is, for example `lead.properties.status.options[1]`. */
|
|
9
9
|
readonly path: Schema.String;
|
|
10
10
|
readonly message: Schema.String;
|
|
@@ -14,7 +14,7 @@ declare const InvalidOntology_base: Schema.Class<InvalidOntology, Schema.TaggedS
|
|
|
14
14
|
readonly message: Schema.String;
|
|
15
15
|
readonly diagnostics: Schema.$Array<Schema.Struct<{
|
|
16
16
|
readonly severity: Schema.Literals<readonly ["error", "warning", "info"]>;
|
|
17
|
-
readonly code: Schema.Literals<readonly ["invalid-source", "missing-column", "invalid-column", "invalid-scope", "invalid-scope-path", "scope-reads-all", "scope-unused", "scope-member-overlap", "source-with-actions", "source-with-index", "invalid-metric", "unknown-metric", "circular-metric", "invalid-join", "missing-join", "invalid-entity", "invalid-property", "invalid-relationship", "invalid-actions", "invalid-action", "invalid-action-input", "invalid-role", "invalid-name", "reserved-name", "duplicate-name", "invalid-entity-id", "duplicate-entity-id", "missing-label", "missing-description", "invalid-title", "invalid-options", "invalid-default", "invalid-constraint", "unknown-relationship-target", "inverse-collision", "invalid-on-delete", "invalid-phrase", "invalid-index", "unknown-reference", "invalid-renamed-from", "earlier-name", "invalid-guide", "invalid-writes", "generated-update-empty", "managed-without-effect", "missing-permissions", "invalid-permission", "unknown-permission", "removed-allow", "unreachable-action", "wildcard-permission", "invalid-sign-in", "invalid-connection", "invalid-feedback", "invalid-discovery", "invalid-email", "feedback-unanswerable", "unknown-connection", "unused-connection", "invalid-prepare", "invalid-tool-name", "invalid-alignment", "single-entity-model-metric", "invalid-workflow", "workflow_role_unknown", "workflow_role_is_member", "workflow_role_grants_nothing", "workflow_role_wildcard", "workflow_role_scoped", "workflow_cron_never_fires", "workflow_input_invalid", "workflow_cron_invalid", "workflow_run_missing", "invalid-trigger", "trigger_action_unknown", "trigger_function_async", "workflow_trigger_limit_exceeded", "workflow_webhook_duplicate", "workflow_webhook_input_invalid", "workflow_webhook_mixed_triggers", "workflow_webhook_signature_invalid", "workflow_webhook_verification_invalid", "workflow_webhook_headers_invalid", "workflow_webhook_limit_exceeded"]>;
|
|
17
|
+
readonly code: Schema.Literals<readonly ["invalid-source", "missing-column", "invalid-column", "invalid-scope", "invalid-scope-path", "scope-reads-all", "scope-unused", "scope-member-overlap", "source-with-actions", "source-with-index", "invalid-metric", "unknown-metric", "circular-metric", "invalid-join", "missing-join", "invalid-entity", "invalid-property", "invalid-relationship", "invalid-actions", "invalid-action", "invalid-action-input", "invalid-role", "invalid-name", "reserved-name", "duplicate-name", "invalid-entity-id", "duplicate-entity-id", "missing-label", "missing-description", "invalid-title", "invalid-options", "invalid-default", "invalid-constraint", "unknown-relationship-target", "inverse-collision", "invalid-on-delete", "invalid-phrase", "invalid-index", "unknown-reference", "invalid-renamed-from", "earlier-name", "invalid-guide", "invalid-writes", "generated-update-empty", "managed-without-effect", "missing-permissions", "invalid-permission", "unknown-permission", "removed-allow", "unreachable-action", "wildcard-permission", "invalid-sign-in", "invalid-connection", "invalid-feedback", "invalid-discovery", "invalid-email", "feedback-unanswerable", "unknown-connection", "unused-connection", "invalid-prepare", "invalid-tool-name", "invalid-toolset", "toolset-lock-mismatch", "invalid-alignment", "single-entity-model-metric", "invalid-workflow", "workflow_role_unknown", "workflow_role_is_member", "workflow_role_grants_nothing", "workflow_role_wildcard", "workflow_role_scoped", "workflow_cron_never_fires", "workflow_input_invalid", "workflow_cron_invalid", "workflow_run_missing", "invalid-trigger", "trigger_action_unknown", "trigger_function_async", "workflow_trigger_limit_exceeded", "workflow_webhook_duplicate", "workflow_webhook_input_invalid", "workflow_webhook_mixed_triggers", "workflow_webhook_signature_invalid", "workflow_webhook_verification_invalid", "workflow_webhook_headers_invalid", "workflow_webhook_limit_exceeded"]>;
|
|
18
18
|
/** Where the problem is, for example `lead.properties.status.options[1]`. */
|
|
19
19
|
readonly path: Schema.String;
|
|
20
20
|
readonly message: Schema.String;
|
package/dist/diagnostics.js
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -18,6 +18,8 @@ export type { DiscoveryOptions, EntityPermissions, JsonSchemaObject, MemberOptio
|
|
|
18
18
|
export { Diagnostic, DIAGNOSTIC_CODES, formatDiagnostics, InvalidOntology } from "./diagnostics.js";
|
|
19
19
|
export type { DiagnosticCode } from "./diagnostics.js";
|
|
20
20
|
export { entity, isEntity } from "./entity.js";
|
|
21
|
+
export { isToolset, MCP_TOOL_NAME, TOOLSET_LOCK_VERSION, toolset, ToolsetLock, ToolsetLockTool, } from "./toolset.js";
|
|
22
|
+
export type { FixedValue, ResolvedTool, ResolvedToolset, Toolset, ToolsetDefinition, ToolsetToolOptions, } from "./toolset.js";
|
|
21
23
|
export type { ActionsBuilder, AnyEntity, ActionHandle, ActionInvoker, MetricQueryGroupKey, AnyStoredEntity, BatchCreateValues, BatchKey, BatchUpdateRecord, BatchUpdateValues, BatchUpsertValues, CreateValues, DraftEntity, Entity, EntityDefinition, EntityRecord, EntityWrites, FreshMetricQueryInput, FreshMetricQueryRow, IndexDefinition, IndexField, InvocableActions, NoActions, Properties, RecordRef, Relationships, SystemFields, UpdateValues, } from "./entity.js";
|
|
22
24
|
export { ActionRejected, BatchErrorDetails, Conflict, DeploymentInterrupted, DeploymentSwitching, LimitErrorDetails, NotFound, PermissionDenied, ScopeViolated, } from "./errors.js";
|
|
23
25
|
export type { ActionError } from "./errors.js";
|
package/dist/index.js
CHANGED
|
@@ -10,6 +10,7 @@ export { ActionConfirmation, ConfirmationFact } from "./confirmation.js";
|
|
|
10
10
|
export { CONNECTION_ERROR_REASONS, CONNECTION_KEY, CONNECTION_METHODS, connection, ConnectionError, Connections, ConnectionTransport, isConnection, MAXIMUM_CONNECTION_BODY_BYTES, MAXIMUM_CONNECTION_RESPONSE_BYTES, } from "./connection.js";
|
|
11
11
|
export { Diagnostic, DIAGNOSTIC_CODES, formatDiagnostics, InvalidOntology } from "./diagnostics.js";
|
|
12
12
|
export { entity, isEntity } from "./entity.js";
|
|
13
|
+
export { isToolset, MCP_TOOL_NAME, TOOLSET_LOCK_VERSION, toolset, ToolsetLock, ToolsetLockTool, } from "./toolset.js";
|
|
13
14
|
export { ActionRejected, BatchErrorDetails, Conflict, DeploymentInterrupted, DeploymentSwitching, LimitErrorDetails, NotFound, PermissionDenied, ScopeViolated, } from "./errors.js";
|
|
14
15
|
export { browserAuthenticationCompatible } from "./manifest-compatibility.js";
|
|
15
16
|
export { ActionManifest, actionConnectionKeys, canonicalJson, ConnectionManifest, EntityManifest, EntityPermissionsManifest, decodeManifestDocument, encodeManifest, formatManifest, IndexManifest, isValueMatched, MANIFEST_VERSION, manifestHash, ModelMetricManifest, OntologyManifest, OntologyManifestWire, PropertyManifest, RelationshipManifest, RoleManifest, ActionTriggerManifest, ScopeManifest, CronTriggerManifest, isActionTrigger, isCronTrigger, isWebhookTrigger, OtherTriggerManifest, WebhookTriggerManifest, WorkflowManifest, WorkflowTriggerManifest, SelectOptionManifest, SignInManifest, signInPolicyOf, channelPolicyOf, signUpRolesOf, } from "./manifest.js";
|