@segmentstream/ontology 0.96.0 → 0.98.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 +15 -3
- package/dist/agent-review.d.ts +95 -0
- package/dist/agent-review.js +200 -0
- package/dist/analyze.d.ts +10 -2
- package/dist/analyze.js +240 -19
- package/dist/bin/check.js +2 -0
- package/dist/chat.d.ts +16 -0
- package/dist/diagnostics.d.ts +3 -3
- package/dist/diagnostics.js +2 -0
- package/dist/index.d.ts +5 -1
- package/dist/index.js +2 -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/permissions.d.ts +5 -3
- package/dist/permissions.js +9 -5
- package/dist/runtime/agents.js +53 -0
- package/dist/service/agent/protocol.d.ts +18 -0
- package/dist/service/agent/protocol.js +33 -0
- package/dist/service/agent/server.js +48 -1
- package/dist/service/catalog.js +10 -1
- package/dist/service/chat/archive.d.ts +2 -1
- package/dist/service/chat/delivery.js +11 -0
- package/dist/service/chat/envelope.d.ts +16 -16
- package/dist/service/chat/providers/provider.d.ts +2 -0
- package/dist/service/chat/providers/slack.js +1 -1
- package/dist/service/chat/providers/telegram.d.ts +6 -1
- package/dist/service/chat/providers/telegram.js +14 -3
- package/dist/service/chat/providers/whatsapp.js +1 -1
- package/dist/service/chat/review-delivery.d.ts +38 -0
- package/dist/service/chat/review-delivery.js +258 -0
- package/dist/service/connections.js +1 -0
- package/dist/service/discovery-search.d.ts +1 -1
- package/dist/service/mcp/runtime-policy.js +5 -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 +16 -1
- package/dist/service/runtime-contract.d.ts +28 -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/slack.js +3 -1
- package/dist/toolset.d.ts +141 -0
- package/dist/toolset.js +154 -0
- package/dist/whatsapp.js +3 -1
- package/package.json +1 -1
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import { Schema } from "effect";
|
|
2
|
+
import type { AnyConnectionHandle } from "./connection.js";
|
|
3
|
+
export declare const ToolsetTypeId: unique symbol;
|
|
4
|
+
/** The lock format `segmentstream connection mcp lock` writes. */
|
|
5
|
+
export declare const TOOLSET_LOCK_VERSION = 1;
|
|
6
|
+
/**
|
|
7
|
+
* A tool name an MCP API may declare: lowercase snake_case of at most 64 characters, so that
|
|
8
|
+
* `<toolset>:<tool>` is an ontology permission and `<toolset>_<tool>` an MCP tool name.
|
|
9
|
+
*/
|
|
10
|
+
export declare const MCP_TOOL_NAME: RegExp;
|
|
11
|
+
/** The most tools one MCP API may declare, as `connections/connections.py` enforces. */
|
|
12
|
+
export declare const MAXIMUM_TOOLSET_TOOLS = 100;
|
|
13
|
+
/** A value the workspace fixes for one argument of a tool. */
|
|
14
|
+
export declare const FixedValue: Schema.Union<readonly [Schema.String, Schema.Number, Schema.Boolean]>;
|
|
15
|
+
export type FixedValue = typeof FixedValue.Type;
|
|
16
|
+
/** One locked tool: the declared access and fixed values, and what the server said about it. */
|
|
17
|
+
export declare const ToolsetLockTool: Schema.Struct<{
|
|
18
|
+
readonly name: Schema.String;
|
|
19
|
+
readonly access: Schema.Literals<readonly ["read", "write"]>;
|
|
20
|
+
readonly fixed: Schema.$Record<Schema.String, Schema.Union<readonly [Schema.String, Schema.Number, Schema.Boolean]>>;
|
|
21
|
+
readonly description: Schema.String;
|
|
22
|
+
readonly inputSchema: Schema.$Record<Schema.String, Schema.Codec<Schema.Json, Schema.Json, never, never>>;
|
|
23
|
+
readonly outputSchema: Schema.optionalKey<Schema.$Record<Schema.String, Schema.Codec<Schema.Json, Schema.Json, never, never>>>;
|
|
24
|
+
readonly annotations: Schema.optionalKey<Schema.$Record<Schema.String, Schema.Codec<Schema.Json, Schema.Json, never, never>>>;
|
|
25
|
+
}>;
|
|
26
|
+
export type ToolsetLockTool = typeof ToolsetLockTool.Type;
|
|
27
|
+
/**
|
|
28
|
+
* The pinned tools of one MCP API of a connection, written by `segmentstream connection mcp lock`
|
|
29
|
+
* and committed with the workspace. The ontology's catalog is built from it, so a provider's
|
|
30
|
+
* change reaches members only through a reviewed commit and a deploy.
|
|
31
|
+
*/
|
|
32
|
+
export declare const ToolsetLock: Schema.Struct<{
|
|
33
|
+
readonly version: Schema.Literal<1>;
|
|
34
|
+
readonly connection: Schema.String;
|
|
35
|
+
readonly api: Schema.String;
|
|
36
|
+
readonly url: Schema.String;
|
|
37
|
+
readonly protocolVersion: Schema.String;
|
|
38
|
+
readonly server: Schema.optionalKey<Schema.Struct<{
|
|
39
|
+
readonly name: Schema.String;
|
|
40
|
+
readonly version: Schema.optionalKey<Schema.String>;
|
|
41
|
+
}>>;
|
|
42
|
+
readonly tools: Schema.$Array<Schema.Struct<{
|
|
43
|
+
readonly name: Schema.String;
|
|
44
|
+
readonly access: Schema.Literals<readonly ["read", "write"]>;
|
|
45
|
+
readonly fixed: Schema.$Record<Schema.String, Schema.Union<readonly [Schema.String, Schema.Number, Schema.Boolean]>>;
|
|
46
|
+
readonly description: Schema.String;
|
|
47
|
+
readonly inputSchema: Schema.$Record<Schema.String, Schema.Codec<Schema.Json, Schema.Json, never, never>>;
|
|
48
|
+
readonly outputSchema: Schema.optionalKey<Schema.$Record<Schema.String, Schema.Codec<Schema.Json, Schema.Json, never, never>>>;
|
|
49
|
+
readonly annotations: Schema.optionalKey<Schema.$Record<Schema.String, Schema.Codec<Schema.Json, Schema.Json, never, never>>>;
|
|
50
|
+
}>>;
|
|
51
|
+
}>;
|
|
52
|
+
export type ToolsetLock = typeof ToolsetLock.Type;
|
|
53
|
+
/** The workspace's own words for one tool, replacing the provider's. */
|
|
54
|
+
export interface ToolsetToolOptions {
|
|
55
|
+
readonly description?: string;
|
|
56
|
+
}
|
|
57
|
+
export interface ToolsetDefinition {
|
|
58
|
+
/** The connection whose MCP API serves the tools, listed in `defineOntology({ connections })`. */
|
|
59
|
+
readonly connection: AnyConnectionHandle;
|
|
60
|
+
/** The name of the connection's MCP API in `connections/connections.py`. */
|
|
61
|
+
readonly api: string;
|
|
62
|
+
/** The content of the lock file `ontology/mcp/<key>.<api>.lock.json`, imported as JSON. */
|
|
63
|
+
readonly lock: unknown;
|
|
64
|
+
/** What the toolset is for, in the workspace's words; agents read it to choose a tool. */
|
|
65
|
+
readonly description: string;
|
|
66
|
+
/** Per-tool overrides, by the provider's tool name. */
|
|
67
|
+
readonly tools?: Readonly<Record<string, ToolsetToolOptions>>;
|
|
68
|
+
}
|
|
69
|
+
/** A provider's MCP tools served by the ontology: see {@link toolset}. */
|
|
70
|
+
export interface Toolset<Name extends string = string> {
|
|
71
|
+
readonly [ToolsetTypeId]: typeof ToolsetTypeId;
|
|
72
|
+
readonly name: Name;
|
|
73
|
+
readonly definition: ToolsetDefinition;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Serves the tools a connection's MCP API declares, as `connections/connections.py` lists them and
|
|
77
|
+
* the lock pins them, to every client of the ontology's MCP server. Each tool becomes the MCP tool
|
|
78
|
+
* `<toolset>_<tool>`, which a member may see and call with the permission `<toolset>:<tool>`. A
|
|
79
|
+
* toolset has no records: no table, `find`, `get` or `history`.
|
|
80
|
+
*
|
|
81
|
+
* `lock` is the JSON of `ontology/mcp/<key>.<api>.lock.json`, imported with `{ type: "json" }`:
|
|
82
|
+
*
|
|
83
|
+
* ```ts
|
|
84
|
+
* export const GitHub = toolset("github", {
|
|
85
|
+
* connection: github,
|
|
86
|
+
* api: "mcp",
|
|
87
|
+
* lock: githubLock,
|
|
88
|
+
* description: "The platform's source repository: code, commits, pull requests and issues.",
|
|
89
|
+
* });
|
|
90
|
+
* ```
|
|
91
|
+
*/
|
|
92
|
+
export declare function toolset<const Name extends string>(name: Name, definition: ToolsetDefinition): Toolset<Name>;
|
|
93
|
+
export declare function isToolset(value: unknown): value is Toolset;
|
|
94
|
+
/** How a tool behaves, from the workspace's declared access and the provider's hints. */
|
|
95
|
+
export interface ResolvedToolHints {
|
|
96
|
+
readonly readOnly: boolean;
|
|
97
|
+
readonly destructive: boolean;
|
|
98
|
+
readonly idempotent: boolean;
|
|
99
|
+
}
|
|
100
|
+
/** One tool of a checked toolset, as the service serves it. */
|
|
101
|
+
export interface ResolvedTool {
|
|
102
|
+
/** The provider's tool name. */
|
|
103
|
+
readonly name: string;
|
|
104
|
+
/** `<toolset>_<tool>`. */
|
|
105
|
+
readonly mcpName: string;
|
|
106
|
+
/** `<toolset>:<tool>`. */
|
|
107
|
+
readonly permission: string;
|
|
108
|
+
readonly access: "read" | "write";
|
|
109
|
+
readonly fixed: Readonly<Record<string, FixedValue>>;
|
|
110
|
+
readonly description: string;
|
|
111
|
+
/** The locked input schema without the fixed arguments, which callers never send. */
|
|
112
|
+
readonly inputSchema: Readonly<Record<string, unknown>>;
|
|
113
|
+
readonly hints: ResolvedToolHints;
|
|
114
|
+
}
|
|
115
|
+
/** A checked toolset. */
|
|
116
|
+
export interface ResolvedToolset {
|
|
117
|
+
/** The wire name. */
|
|
118
|
+
readonly name: string;
|
|
119
|
+
readonly description: string;
|
|
120
|
+
readonly connection: string;
|
|
121
|
+
readonly api: string;
|
|
122
|
+
readonly protocolVersion: string;
|
|
123
|
+
readonly tools: ReadonlyArray<ResolvedTool>;
|
|
124
|
+
}
|
|
125
|
+
/** The root keyword that composes subschemas in a tool's input, if any. */
|
|
126
|
+
export declare function composingKeyword(schema: Readonly<Record<string, unknown>>): string | undefined;
|
|
127
|
+
/**
|
|
128
|
+
* The root keyword that keeps the service from changing a tool's input, if any: fixed values are
|
|
129
|
+
* removed from it, and a tool that is not a read gains the confirmation argument.
|
|
130
|
+
*/
|
|
131
|
+
export declare function fixedArgumentsConflict(schema: Readonly<Record<string, unknown>>, fixed: Readonly<Record<string, unknown>>, access?: "read" | "write"): string | undefined;
|
|
132
|
+
/**
|
|
133
|
+
* A tool's input schema without its fixed arguments: they are removed from `properties`,
|
|
134
|
+
* `required` and `dependentRequired`, and `minProperties` and `maxProperties` no longer count the
|
|
135
|
+
* ones the schema declares, so a caller cannot send or even see them and the remaining input is
|
|
136
|
+
* satisfiable; the service adds their values to each call. `check` refuses a schema whose other
|
|
137
|
+
* root keywords a fixed value could break ({@link fixedArgumentsConflict}).
|
|
138
|
+
*/
|
|
139
|
+
export declare function withoutFixedArguments(schema: Readonly<Record<string, unknown>>, fixed: Readonly<Record<string, unknown>>): Readonly<Record<string, unknown>>;
|
|
140
|
+
/** The workspace's access and the provider's annotations, as the service's tool hints. */
|
|
141
|
+
export declare function toolHints(access: "read" | "write", annotations: Readonly<Record<string, unknown>> | undefined): ResolvedToolHints;
|
package/dist/toolset.js
ADDED
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import { Schema } from "effect";
|
|
2
|
+
export const ToolsetTypeId = Symbol.for("@segmentstream/ontology/Toolset");
|
|
3
|
+
/** The lock format `segmentstream connection mcp lock` writes. */
|
|
4
|
+
export const TOOLSET_LOCK_VERSION = 1;
|
|
5
|
+
/**
|
|
6
|
+
* A tool name an MCP API may declare: lowercase snake_case of at most 64 characters, so that
|
|
7
|
+
* `<toolset>:<tool>` is an ontology permission and `<toolset>_<tool>` an MCP tool name.
|
|
8
|
+
*/
|
|
9
|
+
export const MCP_TOOL_NAME = /^(?=.{1,64}$)[a-z][a-z0-9]*(?:_[a-z0-9]+)*$/;
|
|
10
|
+
/** The most tools one MCP API may declare, as `connections/connections.py` enforces. */
|
|
11
|
+
export const MAXIMUM_TOOLSET_TOOLS = 100;
|
|
12
|
+
/** A value the workspace fixes for one argument of a tool. */
|
|
13
|
+
export const FixedValue = Schema.Union([Schema.String, Schema.Number, Schema.Boolean]);
|
|
14
|
+
/** One locked tool: the declared access and fixed values, and what the server said about it. */
|
|
15
|
+
export const ToolsetLockTool = Schema.Struct({
|
|
16
|
+
name: Schema.String,
|
|
17
|
+
access: Schema.Literals(["read", "write"]),
|
|
18
|
+
fixed: Schema.Record(Schema.String, FixedValue),
|
|
19
|
+
description: Schema.String,
|
|
20
|
+
inputSchema: Schema.Record(Schema.String, Schema.Json),
|
|
21
|
+
outputSchema: Schema.optionalKey(Schema.Record(Schema.String, Schema.Json)),
|
|
22
|
+
annotations: Schema.optionalKey(Schema.Record(Schema.String, Schema.Json)),
|
|
23
|
+
});
|
|
24
|
+
/**
|
|
25
|
+
* The pinned tools of one MCP API of a connection, written by `segmentstream connection mcp lock`
|
|
26
|
+
* and committed with the workspace. The ontology's catalog is built from it, so a provider's
|
|
27
|
+
* change reaches members only through a reviewed commit and a deploy.
|
|
28
|
+
*/
|
|
29
|
+
export const ToolsetLock = Schema.Struct({
|
|
30
|
+
version: Schema.Literal(TOOLSET_LOCK_VERSION),
|
|
31
|
+
connection: Schema.String,
|
|
32
|
+
api: Schema.String,
|
|
33
|
+
url: Schema.String,
|
|
34
|
+
protocolVersion: Schema.String,
|
|
35
|
+
server: Schema.optionalKey(Schema.Struct({ name: Schema.String, version: Schema.optionalKey(Schema.String) })),
|
|
36
|
+
tools: Schema.Array(ToolsetLockTool),
|
|
37
|
+
});
|
|
38
|
+
/**
|
|
39
|
+
* Serves the tools a connection's MCP API declares, as `connections/connections.py` lists them and
|
|
40
|
+
* the lock pins them, to every client of the ontology's MCP server. Each tool becomes the MCP tool
|
|
41
|
+
* `<toolset>_<tool>`, which a member may see and call with the permission `<toolset>:<tool>`. A
|
|
42
|
+
* toolset has no records: no table, `find`, `get` or `history`.
|
|
43
|
+
*
|
|
44
|
+
* `lock` is the JSON of `ontology/mcp/<key>.<api>.lock.json`, imported with `{ type: "json" }`:
|
|
45
|
+
*
|
|
46
|
+
* ```ts
|
|
47
|
+
* export const GitHub = toolset("github", {
|
|
48
|
+
* connection: github,
|
|
49
|
+
* api: "mcp",
|
|
50
|
+
* lock: githubLock,
|
|
51
|
+
* description: "The platform's source repository: code, commits, pull requests and issues.",
|
|
52
|
+
* });
|
|
53
|
+
* ```
|
|
54
|
+
*/
|
|
55
|
+
export function toolset(name, definition) {
|
|
56
|
+
return { [ToolsetTypeId]: ToolsetTypeId, name, definition };
|
|
57
|
+
}
|
|
58
|
+
export function isToolset(value) {
|
|
59
|
+
return (typeof value === "object" &&
|
|
60
|
+
value !== null &&
|
|
61
|
+
value[ToolsetTypeId] === ToolsetTypeId);
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Root keywords that constrain arguments through subschemas. Removing a fixed argument cannot be
|
|
65
|
+
* reflected in them, so a tool whose input uses one cannot have fixed values.
|
|
66
|
+
*/
|
|
67
|
+
const COMPOSING_KEYWORDS = [
|
|
68
|
+
"allOf",
|
|
69
|
+
"anyOf",
|
|
70
|
+
"oneOf",
|
|
71
|
+
"not",
|
|
72
|
+
"if",
|
|
73
|
+
"then",
|
|
74
|
+
"else",
|
|
75
|
+
"dependentSchemas",
|
|
76
|
+
"dependencies",
|
|
77
|
+
"patternProperties",
|
|
78
|
+
"propertyNames",
|
|
79
|
+
"unevaluatedProperties",
|
|
80
|
+
];
|
|
81
|
+
/** The root keyword that composes subschemas in a tool's input, if any. */
|
|
82
|
+
export function composingKeyword(schema) {
|
|
83
|
+
return COMPOSING_KEYWORDS.find((keyword) => Object.hasOwn(schema, keyword));
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* The root keyword that keeps the service from changing a tool's input, if any: fixed values are
|
|
87
|
+
* removed from it, and a tool that is not a read gains the confirmation argument.
|
|
88
|
+
*/
|
|
89
|
+
export function fixedArgumentsConflict(schema, fixed, access = "read") {
|
|
90
|
+
return Object.keys(fixed).length === 0 && access === "read"
|
|
91
|
+
? undefined
|
|
92
|
+
: composingKeyword(schema);
|
|
93
|
+
}
|
|
94
|
+
function isSchemaObject(value) {
|
|
95
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* A tool's input schema without its fixed arguments: they are removed from `properties`,
|
|
99
|
+
* `required` and `dependentRequired`, and `minProperties` and `maxProperties` no longer count the
|
|
100
|
+
* ones the schema declares, so a caller cannot send or even see them and the remaining input is
|
|
101
|
+
* satisfiable; the service adds their values to each call. `check` refuses a schema whose other
|
|
102
|
+
* root keywords a fixed value could break ({@link fixedArgumentsConflict}).
|
|
103
|
+
*/
|
|
104
|
+
export function withoutFixedArguments(schema, fixed) {
|
|
105
|
+
const names = new Set(Object.keys(fixed));
|
|
106
|
+
if (names.size === 0) {
|
|
107
|
+
return { ...schema, type: "object" };
|
|
108
|
+
}
|
|
109
|
+
const declared = isSchemaObject(schema.properties) ? schema.properties : undefined;
|
|
110
|
+
const properties = declared === undefined
|
|
111
|
+
? undefined
|
|
112
|
+
: Object.fromEntries(Object.entries(declared).filter(([property]) => !names.has(property)));
|
|
113
|
+
const required = Array.isArray(schema.required)
|
|
114
|
+
? schema.required.filter((property) => typeof property !== "string" || !names.has(property))
|
|
115
|
+
: undefined;
|
|
116
|
+
const dependentRequired = isSchemaObject(schema.dependentRequired)
|
|
117
|
+
? Object.fromEntries(Object.entries(schema.dependentRequired)
|
|
118
|
+
.filter(([property]) => !names.has(property))
|
|
119
|
+
.map(([property, needs]) => [
|
|
120
|
+
property,
|
|
121
|
+
Array.isArray(needs)
|
|
122
|
+
? needs.filter((need) => typeof need !== "string" || !names.has(need))
|
|
123
|
+
: needs,
|
|
124
|
+
]))
|
|
125
|
+
: undefined;
|
|
126
|
+
// Fixed arguments the schema declares count towards the properties of every call.
|
|
127
|
+
const counted = declared === undefined ? names.size : [...names].filter((name) => name in declared).length;
|
|
128
|
+
const minimum = typeof schema.minProperties === "number"
|
|
129
|
+
? { minProperties: Math.max(0, schema.minProperties - counted) }
|
|
130
|
+
: {};
|
|
131
|
+
const maximum = typeof schema.maxProperties === "number"
|
|
132
|
+
? { maxProperties: Math.max(0, schema.maxProperties - counted) }
|
|
133
|
+
: {};
|
|
134
|
+
return {
|
|
135
|
+
...schema,
|
|
136
|
+
type: "object",
|
|
137
|
+
...(properties === undefined ? {} : { properties }),
|
|
138
|
+
...(required === undefined ? {} : { required }),
|
|
139
|
+
...(dependentRequired === undefined ? {} : { dependentRequired }),
|
|
140
|
+
...minimum,
|
|
141
|
+
...maximum,
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
/** The workspace's access and the provider's annotations, as the service's tool hints. */
|
|
145
|
+
export function toolHints(access, annotations) {
|
|
146
|
+
return access === "read"
|
|
147
|
+
? { readOnly: true, destructive: false, idempotent: true }
|
|
148
|
+
: {
|
|
149
|
+
readOnly: false,
|
|
150
|
+
// The provider's own hints can only add caution: an unknown write is not called safe.
|
|
151
|
+
destructive: annotations?.destructiveHint !== false,
|
|
152
|
+
idempotent: annotations?.idempotentHint === true,
|
|
153
|
+
};
|
|
154
|
+
}
|
package/dist/whatsapp.js
CHANGED
|
@@ -25,5 +25,7 @@ export function literalWhatsAppText(text) {
|
|
|
25
25
|
* attribution in italics. Neither can open or close the member's formatting.
|
|
26
26
|
*/
|
|
27
27
|
export function renderWhatsApp(text, attribution, separator = "\n\n") {
|
|
28
|
-
return
|
|
28
|
+
return attribution === ""
|
|
29
|
+
? text
|
|
30
|
+
: `${text}${literalWhatsAppText(separator)}_${literalWhatsAppText(attribution)}_`;
|
|
29
31
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@segmentstream/ontology",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.98.0",
|
|
4
4
|
"description": "Define a SegmentStream workspace app's ontology: entities, relationships, roles and actions, written with Effect.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": "SegmentStream",
|