@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/manifest.js
CHANGED
|
@@ -4,7 +4,7 @@ import { acceptingEarlierManifestNames, withEarlierManifestNames } from "./legac
|
|
|
4
4
|
import { humanize, MEMBER_ROLE, FEEDBACK_REPORTER_ROLE } from "./names.js";
|
|
5
5
|
import { PROPERTY_TYPES } from "./property.js";
|
|
6
6
|
import { ON_DELETE } from "./relationship.js";
|
|
7
|
-
import { CHANNEL_PROVIDERS, DEFAULT_SIGN_IN_POLICY, isSignInPolicy, } from "./sign-in.js";
|
|
7
|
+
import { CHANNEL_PROVIDERS, DEFAULT_SIGN_IN_POLICY, isSignInPolicy, isSignUpChannel, } from "./sign-in.js";
|
|
8
8
|
/**
|
|
9
9
|
* The manifest format this SDK writes. Readers accept any version and ignore unknown fields. Version
|
|
10
10
|
* 2 replaced the actions' `allow` with `permission`, and added the roles' `permissions` and the
|
|
@@ -57,6 +57,9 @@ import { CHANNEL_PROVIDERS, DEFAULT_SIGN_IN_POLICY, isSignInPolicy, } from "./si
|
|
|
57
57
|
* Within version 15, `chat` may carry `slack` and `whatsapp` beside `telegram`: the connections
|
|
58
58
|
* exact chat posts to Slack chats and to members' WhatsApp chats go through. Older readers ignore
|
|
59
59
|
* them, and their services post to Telegram alone.
|
|
60
|
+
* Within version 15, `signIn` may carry `signUp`, the wire names of the roles each channel open to
|
|
61
|
+
* sign-up grants, and `onSignUp`, written only when declared. Older readers ignore them and keep
|
|
62
|
+
* every channel closed to sign-up.
|
|
60
63
|
*/
|
|
61
64
|
export const MANIFEST_VERSION = 15;
|
|
62
65
|
/** The first version whose documents use snake_case names on the wire. */
|
|
@@ -348,6 +351,23 @@ export const WorkflowManifest = Schema.Struct({
|
|
|
348
351
|
connections: Schema.Array(Schema.String),
|
|
349
352
|
triggers: Schema.Array(WorkflowTriggerManifest),
|
|
350
353
|
});
|
|
354
|
+
/**
|
|
355
|
+
* A provider's MCP tools the ontology serves, `defineOntology({ toolsets })`: the connection's MCP
|
|
356
|
+
* API, each tool's declared access and fixed values, and the action the catalog serves it as, whose
|
|
357
|
+
* `connections` is the toolset's connection. A toolset has no records.
|
|
358
|
+
*/
|
|
359
|
+
export const ToolsetManifest = Schema.Struct({
|
|
360
|
+
name: Schema.String,
|
|
361
|
+
description: Schema.String,
|
|
362
|
+
connection: Schema.String,
|
|
363
|
+
api: Schema.String,
|
|
364
|
+
tools: Schema.Array(Schema.Struct({
|
|
365
|
+
name: Schema.String,
|
|
366
|
+
access: Schema.Literals(["read", "write"]),
|
|
367
|
+
fixed: Schema.Record(Schema.String, Schema.Union([Schema.String, Schema.Number, Schema.Boolean])),
|
|
368
|
+
})),
|
|
369
|
+
actions: Schema.Array(ActionManifest),
|
|
370
|
+
});
|
|
351
371
|
/** A workspace connection the ontology's actions call, by its key in `connections/connections.py`. */
|
|
352
372
|
export const ConnectionManifest = Schema.Struct({
|
|
353
373
|
key: Schema.String,
|
|
@@ -366,13 +386,24 @@ export const BrowserSignInManifest = Schema.Struct({
|
|
|
366
386
|
autoRedirect: Schema.Boolean,
|
|
367
387
|
local: Schema.optionalKey(Schema.Struct({ port: Schema.Int })),
|
|
368
388
|
}).pipe(Schema.encodeKeys({ autoRedirect: "auto_redirect" }));
|
|
389
|
+
/** Sign-up: the wire names of the roles each open channel grants. Unknown channels stay closed. */
|
|
390
|
+
export const SignUpManifest = Schema.Struct({
|
|
391
|
+
channels: Schema.Record(Schema.String, Schema.Unknown),
|
|
392
|
+
});
|
|
369
393
|
export const SignInManifest = Schema.Struct({
|
|
370
394
|
browser: Schema.optionalKey(BrowserSignInManifest),
|
|
371
395
|
policy: Schema.String,
|
|
372
396
|
channels: Schema.optionalKey(Schema.Record(Schema.String, Schema.Unknown)),
|
|
373
397
|
onNewUser: Schema.optionalKey(Schema.String),
|
|
374
398
|
codeLink: Schema.optionalKey(Schema.Boolean),
|
|
375
|
-
|
|
399
|
+
signUp: Schema.optionalKey(SignUpManifest),
|
|
400
|
+
onSignUp: Schema.optionalKey(Schema.String),
|
|
401
|
+
}).pipe(Schema.encodeKeys({
|
|
402
|
+
onNewUser: "on_new_user",
|
|
403
|
+
codeLink: "code_link",
|
|
404
|
+
signUp: "sign_up",
|
|
405
|
+
onSignUp: "on_sign_up",
|
|
406
|
+
}));
|
|
376
407
|
/** One of the workspace's emails, as `defineOntology({ emails })` declares it; see `EmailTemplate`. */
|
|
377
408
|
export const EmailTemplateManifest = Schema.Struct({
|
|
378
409
|
subject: Schema.String,
|
|
@@ -436,6 +467,11 @@ const OntologyManifestModel = Schema.Struct({
|
|
|
436
467
|
* The workflows, since version 9. Written only when there are some; absent reads as none.
|
|
437
468
|
*/
|
|
438
469
|
workflows: Schema.optionalKey(Schema.Array(WorkflowManifest)),
|
|
470
|
+
/**
|
|
471
|
+
* Provider MCP tools the ontology serves, within version 15. Written only when there are some;
|
|
472
|
+
* absent reads as none, and older readers ignore it.
|
|
473
|
+
*/
|
|
474
|
+
toolsets: Schema.optionalKey(Schema.Array(ToolsetManifest)),
|
|
439
475
|
});
|
|
440
476
|
/** A property in the snake_case wire spelling, for records that store definitions. */
|
|
441
477
|
export const PropertyManifestWire = PropertyManifest.pipe(Schema.encodeKeys({
|
|
@@ -503,6 +539,20 @@ export function signInPolicyOf(manifest) {
|
|
|
503
539
|
const policy = manifest.signIn?.policy;
|
|
504
540
|
return isSignInPolicy(policy) ? policy : DEFAULT_SIGN_IN_POLICY;
|
|
505
541
|
}
|
|
542
|
+
/**
|
|
543
|
+
* The wire names of the roles a stranger who signs up on this channel is given, or `undefined` when
|
|
544
|
+
* the channel is closed to sign-up: not a channel this reader knows, or no well-formed entry.
|
|
545
|
+
*/
|
|
546
|
+
export function signUpRolesOf(manifest, channel) {
|
|
547
|
+
if (!isSignUpChannel(channel)) {
|
|
548
|
+
return undefined;
|
|
549
|
+
}
|
|
550
|
+
const roles = manifest.signIn?.signUp?.channels[channel];
|
|
551
|
+
return Array.isArray(roles) && roles.every((role) => typeof role === "string")
|
|
552
|
+
? roles
|
|
553
|
+
: undefined;
|
|
554
|
+
}
|
|
555
|
+
// @legacy ontology.legacy-channel-admission
|
|
506
556
|
/** Unsupported providers and missing or unknown channel policies require invitation. */
|
|
507
557
|
export function channelPolicyOf(manifest, provider) {
|
|
508
558
|
if (!CHANNEL_PROVIDERS.some((supported) => supported === provider)) {
|
|
@@ -703,6 +753,7 @@ function entityManifest(input) {
|
|
|
703
753
|
/** Builds the manifest of a resolved ontology that passed `check`. */
|
|
704
754
|
export function buildManifest(input) {
|
|
705
755
|
const connections = input.connections ?? [];
|
|
756
|
+
const toolsets = (input.toolsets ?? []).map(toolsetManifest);
|
|
706
757
|
const emails = input.emails ?? {};
|
|
707
758
|
const metrics = input.metrics ?? [];
|
|
708
759
|
const workflows = input.workflows ?? [];
|
|
@@ -741,6 +792,17 @@ export function buildManifest(input) {
|
|
|
741
792
|
...(Object.keys(input.signIn.channels ?? {}).length > 0
|
|
742
793
|
? { channels: input.signIn.channels }
|
|
743
794
|
: {}),
|
|
795
|
+
...(input.signIn.signUp === undefined
|
|
796
|
+
? {}
|
|
797
|
+
: {
|
|
798
|
+
signUp: {
|
|
799
|
+
channels: Object.fromEntries(Object.entries(input.signIn.signUp.channels).map(([channel, roles]) => [
|
|
800
|
+
channel,
|
|
801
|
+
[...(roles ?? [])],
|
|
802
|
+
])),
|
|
803
|
+
},
|
|
804
|
+
}),
|
|
805
|
+
...(input.signIn.onSignUp === undefined ? {} : { onSignUp: input.signIn.onSignUp }),
|
|
744
806
|
},
|
|
745
807
|
...(Object.keys(emails).length > 0 ? { emails } : {}),
|
|
746
808
|
...(input.chat === undefined ? {} : { chat: input.chat }),
|
|
@@ -755,12 +817,42 @@ export function buildManifest(input) {
|
|
|
755
817
|
: {}),
|
|
756
818
|
...(metrics.length > 0 ? { metrics } : {}),
|
|
757
819
|
...(workflows.length > 0 ? { workflows } : {}),
|
|
820
|
+
...(toolsets.length > 0 ? { toolsets } : {}),
|
|
758
821
|
};
|
|
759
822
|
return { ...body, hash: manifestHash(encodeManifest({ ...body, hash: "" })) };
|
|
760
823
|
}
|
|
761
|
-
/**
|
|
824
|
+
/** A checked toolset as the manifest lists it: its tools, and the action each is served as. */
|
|
825
|
+
export function toolsetManifest(resolved) {
|
|
826
|
+
return {
|
|
827
|
+
name: resolved.name,
|
|
828
|
+
description: resolved.description,
|
|
829
|
+
connection: resolved.connection,
|
|
830
|
+
api: resolved.api,
|
|
831
|
+
tools: resolved.tools.map((tool) => ({
|
|
832
|
+
name: tool.name,
|
|
833
|
+
access: tool.access,
|
|
834
|
+
fixed: { ...tool.fixed },
|
|
835
|
+
})),
|
|
836
|
+
actions: resolved.tools.map((tool) => ({
|
|
837
|
+
name: tool.name,
|
|
838
|
+
description: tool.description,
|
|
839
|
+
permission: tool.permission,
|
|
840
|
+
input: tool.inputSchema,
|
|
841
|
+
connections: [resolved.connection],
|
|
842
|
+
hints: {
|
|
843
|
+
readOnly: tool.hints.readOnly,
|
|
844
|
+
destructive: tool.hints.destructive,
|
|
845
|
+
idempotent: tool.hints.idempotent,
|
|
846
|
+
},
|
|
847
|
+
})),
|
|
848
|
+
};
|
|
849
|
+
}
|
|
850
|
+
/** The keys of every connection the manifest's actions and toolsets call, without duplicates. */
|
|
762
851
|
export function actionConnectionKeys(manifest) {
|
|
763
852
|
return [
|
|
764
|
-
...new Set(
|
|
853
|
+
...new Set([
|
|
854
|
+
...manifest.entities.flatMap((entity) => entity.actions.flatMap((candidate) => candidate.connections ?? [])),
|
|
855
|
+
...(manifest.toolsets ?? []).map((candidate) => candidate.connection),
|
|
856
|
+
]),
|
|
765
857
|
];
|
|
766
858
|
}
|
package/dist/migrate/apply.js
CHANGED
|
@@ -19,7 +19,7 @@ import { principalsOntology, reconcileWorkflowUsers } from "../runtime/principal
|
|
|
19
19
|
import { FEDERATION_TABLES } from "../runtime/federation-tables.js";
|
|
20
20
|
import { syncUserIdentities, USER_IDENTITY_ENTITY_ID } from "../runtime/user-identities.js";
|
|
21
21
|
import { resolveReplicationSelection, } from "../replication/model.js";
|
|
22
|
-
import { ACTION_ATTRIBUTION_TABLE, AGENT_TABLES, API_KEYS_TABLE, CATALOG_TABLE, OAUTH_TABLES, USER_ROLES_TABLE, quoteIdentifier, quoteLiteral, historyTableName, } from "./storage.js";
|
|
22
|
+
import { ACTION_ATTRIBUTION_TABLE, AGENT_TABLES, API_KEYS_TABLE, CATALOG_TABLE, CHANNEL_USERS_TABLE, OAUTH_TABLES, USER_ROLES_TABLE, quoteIdentifier, quoteLiteral, historyTableName, } from "./storage.js";
|
|
23
23
|
const CATALOG = quoteIdentifier(CATALOG_TABLE);
|
|
24
24
|
const IDENTITY_SYNC = "Copy members' sign-in identities the legacy identity stores hold.";
|
|
25
25
|
/**
|
|
@@ -489,6 +489,10 @@ export const readRuntimeTables = (input) => input.sql
|
|
|
489
489
|
`AND ("tablename" <> '_oauth_grants' OR EXISTS (` +
|
|
490
490
|
`SELECT 1 FROM information_schema.columns WHERE table_schema = current_schema() ` +
|
|
491
491
|
`AND table_name = '_oauth_grants' AND column_name = 'identity_id')) ` +
|
|
492
|
+
// Without `signed_up` the agent tables' idempotent DDL runs again and adds it.
|
|
493
|
+
`AND ("tablename" <> ${quoteLiteral(CHANNEL_USERS_TABLE)} OR EXISTS (` +
|
|
494
|
+
`SELECT 1 FROM information_schema.columns WHERE table_schema = current_schema() ` +
|
|
495
|
+
`AND table_name = ${quoteLiteral(CHANNEL_USERS_TABLE)} AND column_name = 'signed_up')) ` +
|
|
492
496
|
`AND ("tablename" <> ${quoteLiteral(API_KEYS_TABLE)} OR EXISTS (` +
|
|
493
497
|
`SELECT 1 FROM information_schema.columns WHERE table_schema = current_schema() ` +
|
|
494
498
|
`AND table_name = ${quoteLiteral(API_KEYS_TABLE)} AND column_name = 'delegation')) ` +
|