@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.
Files changed (44) hide show
  1. package/README.md +39 -4
  2. package/dist/analyze.d.ts +23 -3
  3. package/dist/analyze.js +431 -17
  4. package/dist/authoring.js +3 -0
  5. package/dist/bin/check.js +2 -0
  6. package/dist/diagnostics.d.ts +3 -3
  7. package/dist/diagnostics.js +2 -0
  8. package/dist/index.d.ts +5 -3
  9. package/dist/index.js +3 -2
  10. package/dist/manifest.d.ts +607 -20
  11. package/dist/manifest.js +96 -4
  12. package/dist/migrate/apply.js +5 -1
  13. package/dist/migrate/model.d.ts +332 -12
  14. package/dist/migrate/storage.js +2 -0
  15. package/dist/ontology.d.ts +5 -2
  16. package/dist/ontology.js +1 -0
  17. package/dist/runtime/member-tables.d.ts +7 -2
  18. package/dist/runtime/member-tables.js +18 -3
  19. package/dist/runtime/new-user-hook.d.ts +11 -1
  20. package/dist/runtime/new-user-hook.js +69 -29
  21. package/dist/runtime/pipeline.d.ts +2 -0
  22. package/dist/runtime/pipeline.js +11 -3
  23. package/dist/runtime/principals.d.ts +13 -0
  24. package/dist/runtime/principals.js +98 -28
  25. package/dist/runtime/resolve-agent-identity.js +43 -12
  26. package/dist/runtime/service-binding.js +10 -4
  27. package/dist/service/catalog.js +10 -1
  28. package/dist/service/chat/envelope.d.ts +16 -16
  29. package/dist/service/connections.js +1 -0
  30. package/dist/service/discovery-search.d.ts +1 -1
  31. package/dist/service/mcp/server.js +13 -1
  32. package/dist/service/mcp/tools.d.ts +5 -0
  33. package/dist/service/mcp/tools.js +30 -0
  34. package/dist/service/operations.d.ts +3 -1
  35. package/dist/service/operations.js +3 -0
  36. package/dist/service/schemas.d.ts +74 -0
  37. package/dist/service/toolsets.d.ts +49 -0
  38. package/dist/service/toolsets.js +284 -0
  39. package/dist/sign-in.d.ts +32 -1
  40. package/dist/sign-in.js +12 -1
  41. package/dist/toolset.d.ts +141 -0
  42. package/dist/toolset.js +154 -0
  43. package/dist/user-identity.d.ts +1 -1
  44. package/package.json +1 -1
package/README.md CHANGED
@@ -407,14 +407,37 @@ export default defineOntology({
407
407
  affected member has linked email before restoring an email-only deployment. `User.sendSignInLink`
408
408
  preserves Neon links in compatibility and dual mode; sole SegmentStream uses interactive central
409
409
  sign-in, preserving templates, reply routing and the requested landing path.
410
+ - `signUp: { channels, roles, byChannel? }` opens sign-up to strangers on each listed channel:
411
+ `email` (signing in to the app by email code), `telegram` (a first private message to the bot,
412
+ or opening the Mini App) and `whatsapp` (a first message to the number). The new user holds
413
+ exactly `roles`, declared roles passed as role objects or names, or the channel's own list in
414
+ `byChannel`; `[]` grants nothing beyond what is later granted or shared. Sign-up writes them as
415
+ ordinary role assignments in its own transaction, so one person's roles can be revoked or added
416
+ to like anyone's. A user sign-up created never holds `member`, the baseline of invited people,
417
+ nor the implicit feedback reporter role, and the platform records that they signed up (`_channel_users.signed_up`) whatever roles they
418
+ hold later: turn limits always count them. A channel not listed admits only invited or paired
419
+ people; a workspace without `signUp` is internal. `check` refuses in sign-up roles an
420
+ undeclared role, `member`, an entity wildcard, and a generated create, update, delete, link or
421
+ unlink that is not scoped (`{ permission, where: { createdBy: me } }`); an unscoped read of a
422
+ stored entity warns for review. Telegram and WhatsApp need a matching `chat.<channel>` adapter.
423
+ A channel opened both here and by `signIn.channels` or `signIn.policy: "open"` is refused.
424
+ `onSignUp: "contact:ensureMine"` names an idempotent, input-free action without `prepare` or
425
+ connections, run as each new user with the roles their channel granted, after admission
426
+ commits: before the first agent turn or Mini App session, and before an email user's first
427
+ request. Every channel's roles must be able to run it, it cannot grant roles, and a failure
428
+ leaves it pending for the next contact. Promote a person with an ordinary action that calls
429
+ `User.grantRoles`. The manifest carries `sign_in.sign_up` (each channel's role wire names) and
430
+ `sign_in.on_sign_up` only when declared; `signUpRolesOf(manifest, channel)` reads them and
431
+ keeps unknown or malformed channels closed.
410
432
  - `signIn: { policy }` decides who may become a member by signing in. `invited`, the
411
433
  default, admits only people whose email a member already has, from an invitation or a
412
434
  role grant; anyone else is answered 403 `not_invited`. `open` makes anyone who signs in a
413
- member holding only `member`. The manifest carries the policy.
435
+ member holding only `member`. The manifest carries the policy. <!-- @legacy ontology.legacy-channel-admission -->
414
436
  `signIn.codeLink: true` makes the platform's sign-in code emails also link to the app's
415
437
  `/sign-in` page with the code in the URL fragment; the app SDK's `useSignIn()` fills it in and
416
438
  waits for the person to confirm. Off when omitted; see the app authentication guide.
417
- Explicit app opt-in (never a platform or starter default): channel admission is independent: `signIn: { policy: "invited", channels: { telegram: "open" } }`
439
+ The earlier channel opt-in, kept until `signUp` replaces it: <!-- @legacy ontology.legacy-channel-admission -->
440
+ `signIn: { policy: "invited", channels: { telegram: "open" } }`
418
441
  lets private channel senders become email-less members. Missing channels require pairing; email
419
442
  `policy: "open"` never opens a channel. `CHANNEL_PROVIDERS` lists supported providers (`telegram`).
420
443
  Every configured channel requires a matching `chat.<provider>` adapter; object values are reserved.
@@ -1218,6 +1241,17 @@ is visible. Attachment guidance appears only when attach is visible. The caller
1218
1241
  problem, asks approval for the title and summary, then later reports and acknowledges the answer.
1219
1242
  Builders use `segmentstream ontology feedback list`, `show` and `respond` as their app member.
1220
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
+
1221
1255
  ## Agents
1222
1256
 
1223
1257
  The app's own agent runs in the same Vercel project as the service and calls it as the
@@ -1301,8 +1335,9 @@ These values are platform defaults **and ceilings**; trusted overrides can only
1301
1335
  limits persist in `_channel_limits`; omitted limits reuse them, or defaults before the first submission.
1302
1336
  Only trusted agent configuration may submit limits; browser assertions must never supply them.
1303
1337
  Counters are durable in `_agent_counters`. Sender counters use user ids, so adding/replacing an identity
1304
- cannot reset them. Turn caps apply only to self-registered users with exactly `["member"]`; paired-only
1305
- members and holders of any named role are exempt. Every new registration consumes the hourly cap.
1338
+ cannot reset them. Turn caps apply to every user `signUp` created, whatever roles they hold, and to
1339
+ users an open `signIn.channels` created while they hold exactly `["member"]`; invited and paired-only
1340
+ members are exempt. Every new registration consumes the hourly cap.
1306
1341
  `turn: false` never creates or counts; groups never create. Capped registration writes roll back, with a
1307
1342
  separate durable refusal counter. Each cap notifies on its first rejection per effective threshold
1308
1343
  within the fixed window, including after configured limits change. A `notify` response leases
package/dist/analyze.d.ts CHANGED
@@ -7,13 +7,14 @@ import { type AnyEntity, type EntityWrites } from "./entity.js";
7
7
  import { type PropertyDefinition } from "./property.js";
8
8
  import { type AnyRelationship } from "./relationship.js";
9
9
  import { type Role, type RolePermission } from "./role.js";
10
- import { type SignInOptions } from "./sign-in.js";
10
+ import { type ResolvedSignInOptions, type SignInOptions, type SignUpOptions } from "./sign-in.js";
11
11
  import { type EmailTemplate } from "./emails.js";
12
12
  import { type FeedbackOptions, type ResolvedFeedback } from "./feedback-config.js";
13
13
  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
  /**
@@ -46,6 +47,18 @@ export interface OntologyConfig<Entities extends ReadonlyArray<AnyEntity> = Read
46
47
  readonly member?: MemberOptions;
47
48
  /** Who may become a member by signing in. Only invited people by default. */
48
49
  readonly signIn?: SignInOptions;
50
+ /**
51
+ * Where a stranger may sign up, and the declared roles they get: `{ channels: ["whatsapp"],
52
+ * roles: [lead] }`. Absent, only invited or paired people get in. A user created by sign-up holds
53
+ * exactly these roles and never `member`.
54
+ */
55
+ readonly signUp?: SignUpOptions<Role | string>;
56
+ /**
57
+ * An idempotent, input-free action, as `<entity>:<action>`, run as each user created by sign-up
58
+ * with the roles their channel granted, before their first agent turn or app session. It cannot
59
+ * grant roles.
60
+ */
61
+ readonly onSignUp?: string;
49
62
  /**
50
63
  * How the MCP `discover` tool finds a request's entities. By default it matches words in their
51
64
  * names and descriptions. `{ model }` asks that decision model on AI Gateway, such as
@@ -65,6 +78,11 @@ export interface OntologyConfig<Entities extends ReadonlyArray<AnyEntity> = Read
65
78
  * handle an action lists must be here, and every handle here must be used by an action.
66
79
  */
67
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>;
68
86
  /**
69
87
  * The providers the built-in exact chat post delivers to, each through its connection, which
70
88
  * must be listed in `connections`. Only declared providers are destinations.
@@ -204,8 +222,8 @@ export interface Analysis {
204
222
  readonly entities: ReadonlyArray<ResolvedEntity>;
205
223
  /** The workspace-owned `member` role and declared roles, then the implicit reporter when enabled. */
206
224
  readonly roles: ReadonlyArray<Role>;
207
- /** The sign-in options, with the default policy when the definition sets none. */
208
- readonly signIn: SignInOptions;
225
+ /** The sign-in options, with the default policy when the definition sets none, and sign-up. */
226
+ readonly signIn: ResolvedSignInOptions;
209
227
  /** The declared emails that passed `check`, by wire name. */
210
228
  readonly emails: Readonly<Record<string, EmailTemplate>>;
211
229
  /** The declared connections, in order. */
@@ -214,6 +232,8 @@ export interface Analysis {
214
232
  readonly metrics: ReadonlyArray<ModelMetricManifest>;
215
233
  /** The workflows that passed `check`, in their manifest form: wire names and wire input. */
216
234
  readonly workflows: ReadonlyArray<WorkflowManifest>;
235
+ /** The toolsets that passed `check`, with wire names. */
236
+ readonly toolsets: ReadonlyArray<ResolvedToolset>;
217
237
  readonly diagnostics: ReadonlyArray<Diagnostic>;
218
238
  }
219
239
  /**