@segmentstream/ontology 0.106.3 → 0.108.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 (59) hide show
  1. package/CHANGELOG.md +64 -0
  2. package/README.md +45 -11
  3. package/dist/analyze.d.ts +7 -1
  4. package/dist/analyze.js +271 -16
  5. package/dist/authoring.js +6 -0
  6. package/dist/diagnostics.d.ts +3 -3
  7. package/dist/diagnostics.js +1 -0
  8. package/dist/emails.d.ts +36 -5
  9. package/dist/emails.js +139 -2
  10. package/dist/index.d.ts +7 -7
  11. package/dist/index.js +5 -3
  12. package/dist/manifest.d.ts +262 -1
  13. package/dist/manifest.js +73 -4
  14. package/dist/migrate/apply.js +8 -1
  15. package/dist/migrate/model.d.ts +154 -0
  16. package/dist/migrate/storage.d.ts +2 -0
  17. package/dist/migrate/storage.js +8 -0
  18. package/dist/names.d.ts +5 -0
  19. package/dist/names.js +5 -0
  20. package/dist/ontology.d.ts +4 -1
  21. package/dist/permissions.d.ts +30 -2
  22. package/dist/permissions.js +51 -6
  23. package/dist/runtime/agent-counters.d.ts +5 -1
  24. package/dist/runtime/agent-counters.js +21 -6
  25. package/dist/runtime/agent-web.d.ts +9 -6
  26. package/dist/runtime/agent-web.js +101 -5
  27. package/dist/runtime/generated-actions.js +2 -3
  28. package/dist/runtime/guests.d.ts +32 -0
  29. package/dist/runtime/guests.js +64 -0
  30. package/dist/runtime/new-user-hook.js +2 -1
  31. package/dist/runtime/oauth.js +7 -1
  32. package/dist/runtime/pipeline.js +3 -2
  33. package/dist/runtime/principals.js +6 -4
  34. package/dist/runtime/sql-runtime.js +2 -1
  35. package/dist/runtime.d.ts +10 -2
  36. package/dist/service/agent/authentication.d.ts +6 -4
  37. package/dist/service/agent/authentication.js +20 -5
  38. package/dist/service/agent/protocol.d.ts +28 -2
  39. package/dist/service/agent/protocol.js +23 -10
  40. package/dist/service/agent/server.d.ts +9 -2
  41. package/dist/service/agent/server.js +12 -12
  42. package/dist/service/agent/tasks.d.ts +3 -0
  43. package/dist/service/agent/tasks.js +5 -3
  44. package/dist/service/agent/web-tokens.d.ts +28 -13
  45. package/dist/service/agent/web-tokens.js +91 -38
  46. package/dist/service/authentication.d.ts +6 -0
  47. package/dist/service/authentication.js +11 -2
  48. package/dist/service/chat/review-delivery.js +4 -0
  49. package/dist/service/mcp/server.js +3 -3
  50. package/dist/service/mcp/tools.d.ts +4 -2
  51. package/dist/service/mcp/tools.js +14 -2
  52. package/dist/service/oauth/protocol.js +8 -2
  53. package/dist/service/oauth/server.js +5 -1
  54. package/dist/service/runtime-contract.d.ts +58 -6
  55. package/dist/service/schemas.d.ts +40 -0
  56. package/dist/service/service.js +15 -4
  57. package/dist/sign-in.d.ts +66 -9
  58. package/dist/sign-in.js +87 -9
  59. package/package.json +1 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,69 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.108.0
4
+
5
+ A workspace can send its own invitation. `signIn.invitationEmail` names one of the ontology's
6
+ `emails`, which the platform then sends instead of its own invitation to a member who has not signed
7
+ in yet: when they are invited from `segmentstream ontology member invite` or the console, and from
8
+ `User.sendSignInLink` without a template. It may use only the built-in values; `check` reports
9
+ `invalid-email` for any other, and `invalid-sign-in` when the name is not a declared email.
10
+
11
+ Emails can use two more built-in values, `{{app.url}}`, the app's production address, and
12
+ `{{app.mcpUrl}}`, its MCP server's, and `sections`: boxes below the button with a title, text, a
13
+ value to copy shown large in a monospace box, labelled items with text or a command, and a note.
14
+ The starter's invitation, in `ontology/emails.ts`, uses them to give the MCP server's address and how
15
+ Claude, ChatGPT, Claude Code and Codex connect. Older platform deployments ignore both and send their
16
+ own invitation.
17
+
18
+ ## 0.107.0
19
+
20
+ The agent's own tools are permissions: `agent_tool:sandbox` (the sandbox's shell and file tools,
21
+ staging files into it and file-argument ontology calls) and `agent_tool:web` (reading the web
22
+ domains the agent's configuration lists). A role, `member` or a sign-up role grants them by name,
23
+ or all of them with `agent_tool:*`; no wildcard does, `*:*` included, nor a pipeline workload's
24
+ `*:*`. `check` refuses any other verb of `agent_tool`, a scoped grant of it, and an entity or a
25
+ toolset named `agent_tool`.
26
+
27
+ Wherever the ontology tells the agent whom it acts for, its answer names the tools that caller's
28
+ current roles grant in `agent_tools`: identity lookup and admission, agent token introspection, and
29
+ the current task's user.
30
+
31
+ Action required: name the agent tools in the roles that may use them, such as
32
+ `member: { permissions: ["*:read", "agent_tool:sandbox"] }`, and leave them out of the roles of
33
+ people who sign up. While no role names an `agent_tool` permission, every caller keeps the sandbox
34
+ tools, as before, and `check` warns `agent-tools-implicit`. From 2027-02-15 an ontology whose roles
35
+ name none grants no agent tool.
36
+
37
+ Guests: `defineOntology({ guest: { channels: ["web"], origins, permissions } })` lets the visitors
38
+ of the declared websites talk to the app's agent without signing in or signing up, as the
39
+ counterpart of `member`. A guest is a session, not a user: `POST /api/ontology/agent/visitors`
40
+ from a declared website answers an agent token of a grant to `agent-web` that names no user, with
41
+ a refresh token, and chat `guest:<id>`; no user or identity is created. The guest stays the same,
42
+ in the same chat, while their browser renews the token, and ends after 30 days without a visit.
43
+ One network address may start 10 guests an hour, apart from the cap on new users.
44
+
45
+ Every guest holds the built-in role `guest` alone, with `guest.permissions`. `check` holds them to
46
+ the rules of sign-up roles, and refuses the built-in entities, scopes that name `me`, and
47
+ `agent_tool:sandbox` or `agent_tool:*`: a guest may hold `agent_tool:web`, never the sandbox. The
48
+ agent acting for a guest (`X-SegmentStream-Act-As: guest:<id>` with the token's grant) reaches only
49
+ `/mcp`, where `me`, member files and the chat archive are not offered, and what a guest creates is
50
+ created by nobody. In an action's handler `principal.kind` can now be `guest`. Introspection
51
+ answers a guest's token with `guest_id`, `roles`, `grant_id`, `chat` and `agent_tools`, the agent
52
+ tools `guest.permissions` grant (never the sandbox, never implicitly), and counts each of their
53
+ turns against the agent's new `limits.guest`, per guest and for every guest together, which the web
54
+ channel sends with each turn. `guest.permissions` decide nothing about whether the workspace names
55
+ agent tools: while no other role names one, staff keep the implicit sandbox.
56
+
57
+ `guest.origins` and `signUp.origins` accept a pattern whose leftmost label is `*`, such as
58
+ `https://*.example.com`, which matches one whole label; `websiteOrigin` and `matchesWebsite` check
59
+ them, and `guestOf` reads guests from a manifest. The ontology's migration lets a guest's grant
60
+ name no user. A role declared as `guest` is reserved once the ontology declares guests.
61
+
62
+ Action required: `signUp.channels: ["web"]` is superseded by `guest`, and `check` warns on it.
63
+ Declare `guest` with the same websites and remove `web` from `signUp.channels`; sign-up on `web`
64
+ keeps working until 2027-02-15. `signUpOrigin` is now `websiteOrigin`; the earlier name works until
65
+ 2027-02-15.
66
+
3
67
  ## 0.106.3
4
68
 
5
69
  The ontology service reads less from the workspace database. Its status endpoint reads the hash of
package/README.md CHANGED
@@ -410,11 +410,28 @@ export default defineOntology({
410
410
  affected member has linked email before restoring an email-only deployment. `User.sendSignInLink`
411
411
  preserves Neon links in compatibility and dual mode; sole SegmentStream uses interactive central
412
412
  sign-in, preserving templates, reply routing and the requested landing path.
413
+ - `guest: { channels: ["web"], origins, permissions }` lets the visitors of the websites `origins`
414
+ lists talk to the app's agent without signing in or signing up, as guests: a session, not a user.
415
+ `POST /api/ontology/agent/visitors` from one of those websites answers an agent token of an
416
+ `agent-web` grant that names no user (its id is the guest's), with a refresh token that renews it,
417
+ and chat `guest:<id>`; no user or identity is created, at most 10 guests start per network
418
+ address an hour, and a guest ends after 30 days without a renewal. Every guest holds the built-in
419
+ role `guest` alone, with `permissions`, which `check` holds to the rules of sign-up roles and
420
+ more: no built-in entity, no scope naming `me`, and of the agent's own tools only
421
+ `agent_tool:web`. The agent acting for a guest (`X-SegmentStream-Act-As: guest:<id>` with the
422
+ grant) reaches `/mcp` alone, without `me`, member files or the chat archive; what a guest creates
423
+ is created by nobody, and `principal.kind` is `guest`. Agent token introspection answers a
424
+ guest's token with `guest_id`, `roles`, `grant_id`, `chat` and `agent_tools`, and counts their
425
+ turns against the agent's `limits.guest`. Origins of `guest` and `signUp` are an origin alone
426
+ (`http` only for `localhost` and `127.0.0.1`) or a pattern such as `https://*.example.com`,
427
+ whose `*` is one whole leftmost label over a domain of at least two labels (`websiteOrigin`,
428
+ `matchesWebsite`). The manifest carries `sign_in.guest` and the built-in role only when
429
+ declared; `guestOf(manifest)` reads them.
413
430
  - `signUp: { channels, roles, byChannel?, origins? }` opens sign-up to strangers on each listed
414
431
  channel: `email` (signing in to the app by email code), `telegram` (a first private message to
415
432
  the bot, or opening the Mini App), `whatsapp` (a first message to the number) and `web` (a
416
- visitor of a website `origins` lists, by exact origin, who writes to the agent there; `http` only
417
- for `localhost` and `127.0.0.1`). `web` signs a visitor up at
433
+ visitor of a website `origins` lists who writes to the agent there; `guest` supersedes it, and
434
+ `check` warns on it). `web` signs a visitor up at
418
435
  `POST /api/ontology/agent/visitors`, which answers only browsers on those origins, at most 10 new
419
436
  visitors per network address an hour, with an agent token and a refresh token that renews it at
420
437
  the OAuth token endpoint as client `agent-web`. The new user holds
@@ -466,14 +483,18 @@ export default defineOntology({
466
483
  policy, grants, hook content, notice text, and lower limits. Nothing defaults to open.
467
484
  `check(config, { agentConfig })` warns if open channels lack `firstContact.notice` or `limits` when
468
485
  agent config is supplied. The ontology CLI cannot see that config and says those checks are skipped.
469
- - `emails: { agreementReview: { subject, eyebrow?, heading, card?, note?, paragraphs?, action, footer?, replyTo? } }`
486
+ - `emails: { agreementReview: { subject, eyebrow?, heading, card?, note?, paragraphs?, action, sections?, footer?, replyTo? } }`
470
487
  declares the workspace's own emails, in plain text with `{{value}}` placeholders and the
471
- built-in `{{member.name}}`, `{{member.firstName}}` and `{{workspace.name}}`. A handler sends
488
+ built-in `{{member.name}}`, `{{member.firstName}}`, `{{workspace.name}}`, `{{app.url}}` and
489
+ `{{app.mcpUrl}}`. `sections` are boxes below the button, each
490
+ `{ title, text?, copy?: { label?, value }, items?: [{ label, text?, code? }], note? }`.
491
+ `signIn.invitationEmail: "memberInvitation"` names the one the platform sends instead of its
492
+ own invitation; it may use only built-in values. A handler sends
472
493
  one with `User.sendSignInLink(user, { template: "agreementReview", returnTo: "/shared/1", values })`:
473
494
  after the commit, in production, the platform emails the member a link that signs them in and
474
495
  opens `returnTo`, laid out in its design, from the workspace's name, with replies to `replyTo`
475
496
  or else the member who ran the action. Without `template` the
476
- member gets the platform's own invitation or sign-in email. `check` reports `invalid-email`.
497
+ member gets the invitation, or the platform's sign-in email. `check` reports `invalid-email`.
477
498
  - `defineOntology` checks the definition and builds the manifest. It throws
478
499
  `InvalidOntology` with every diagnostic when the definition has errors. Entities,
479
500
  actions and select options need a description.
@@ -935,9 +956,9 @@ configured. This preparation does not advertise or enable exact chat posting.
935
956
  A permission is `<entity>:<verb>`. The verbs are `read`, the generated `create`, `update`,
936
957
  `delete`, `link` and `unlink`, and the names of authored actions. A role may use `*` for the
937
958
  entity, the verb or both: `lead:*`, `*:read`, `*:*`. An entity wildcard never covers the
938
- built-in `agent_chat`, `agent_review`, `app_feedback`, `app_feedback_file`, `user_identity` or
939
- `workspace_source`: reading or changing them needs a permission that names them, such as
940
- `agent_chat:read` or `agent_chat:*`.
959
+ built-in `agent_chat`, `agent_review`, `agent_tool`, `app_feedback`, `app_feedback_file`,
960
+ `user_identity` or `workspace_source`: reading or changing them needs a permission that names them,
961
+ such as `agent_chat:read` or `agent_chat:*`.
941
962
 
942
963
  `workspace_source:read` (`WORKSPACE_SOURCE_PERMISSION`) is the built-in permission to read the
943
964
  workspace's deployed code through the agent (see [The workspace's code](#the-workspaces-code)).
@@ -945,6 +966,18 @@ workspace's deployed code through the agent (see [The workspace's code](#the-wor
945
966
  an entity or toolset named `workspace_source`. Only `workspace_source:read` or
946
967
  `workspace_source:*` grants it; `*:read`, `*:*` and a pipeline workload's `*:*` do not.
947
968
 
969
+ `agent_tool:sandbox` and `agent_tool:web` (`AGENT_TOOL_VERBS`, `agentToolPermission`) grant the
970
+ app's agent's own tools to a caller: its sandbox (shell and files, staging files, file-argument
971
+ calls) and reading the web domains its configuration lists. `agent_tool` is no entity either:
972
+ `check` refuses any other verb, a scoped grant, and an entity or toolset of the name; only a
973
+ permission naming `agent_tool` grants them, never `*:*` or a workload's `*:*`. `agentToolsOf(roles,
974
+ principal)` is what the ontology tells the agent a caller holds, as `agent_tools` in every answer
975
+ that names whom the agent acts for. While no role, `member` and sign-up roles included, names an
976
+ `agent_tool` permission, it is `["sandbox"]` for everyone, as before these permissions, and `check`
977
+ warns `agent-tools-implicit`; from 2027-02-15 such an ontology grants no agent tool. Guests hold
978
+ what `guest.permissions` grant, never the sandbox and never implicitly, and those permissions count
979
+ for nothing in whether the ontology names agent tools.
980
+
948
981
  - Reads require `<entity>:read`: lists, queries, records, history, both entities of a
949
982
  relationship traversal, and every entity a metric query touches. `include` and a filter through a relationship require `read` on
950
983
  the related entity. A missing permission answers 403 with `<permission> is required.`
@@ -1302,7 +1335,7 @@ task header on any other route are a 403.
1302
1335
 
1303
1336
  | Route | Does |
1304
1337
  | ----------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
1305
- | `GET /api/ontology/agent/tasks/current` | `{ id, workflow, prompt, deadline_at, principal: { id, name, roles } }`; `roles` includes `member` |
1338
+ | `GET /api/ontology/agent/tasks/current` | `{ id, workflow, prompt, deadline_at, principal: { id, name, roles, agent_tools } }`; `roles` includes `member` |
1306
1339
  | `POST /api/ontology/agent/tasks/current/result` | `{ status: "completed" \| "needs_input", text, truncated }` or `{ status: "failed", reason: "agent_failed" }` → `{ accepted: true }`; 409 when the task already ended |
1307
1340
 
1308
1341
  Without either header the agent may call only the agent routes:
@@ -1314,7 +1347,7 @@ Without either header the agent may call only the agent routes:
1314
1347
  | `POST /api/ontology/agent/pairings/{code}/approve` | member | Pairs the account with the member → `{ identity }` |
1315
1348
  | `POST /api/ontology/agent/identities/resolve` | agent | Admission and turn limits; see below |
1316
1349
  | `POST /api/ontology/agent/identities/notice` | agent | `{ provider, external_id, sha256, version? }` acknowledges notice delivery: 204 |
1317
- | `GET /api/ontology/agent/identities/{provider}/{external_id}` | agent | `{ user: { id, name }, roles }`; 404 unpaired, 403 revoked, inactive |
1350
+ | `GET /api/ontology/agent/identities/{provider}/{external_id}` | agent | `{ user: { id, name }, roles, agent_tools }`; 404 unpaired, 403 revoked, inactive |
1318
1351
  | `GET /api/ontology/agent/identities` | member | `{ identities }`: the member's live identities |
1319
1352
  | `DELETE /api/ontology/agent/identities/{id}` | member | Revokes one of them: 204 |
1320
1353
  | `POST /api/ontology/agent/chats/seen` | agent | `{ provider, externalId, title, memberId?, leftMemberId?, agentLeft?, migratedFrom? }` → `{ id, title, purpose, whenToUse }` |
@@ -1337,7 +1370,8 @@ database an earlier SDK migrated. Additive migrations also create `_agent_counte
1337
1370
  display?, username?, notice_version?, notice_sha256?, limits? }` with a verified runtime token.
1338
1371
  It returns 200 with `status`:
1339
1372
 
1340
- - `created` or `existing`: `{ user: { id, name }, roles, provisioned, notice_due, on_new_user_pending }`.
1373
+ - `created` or `existing`: `{ user: { id, name }, roles, agent_tools, provisioned, notice_due, on_new_user_pending }`.
1374
+ `agent_tools` names the agent's own tools the user's roles grant, such as `sandbox`.
1341
1375
  The optional onboarding hook has already been attempted before this response; pending means retry.
1342
1376
  - `pairing_required`: unknown account on an invited channel, in a group, or with `turn: false`.
1343
1377
  - `refused`: `{ reason: "blocked" | "inactive" }`; revoked bindings also return `blocked` and never re-create.
package/dist/analyze.d.ts CHANGED
@@ -7,7 +7,7 @@ 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 ResolvedSignInOptions, type SignInOptions, type SignUpOptions } from "./sign-in.js";
10
+ import { type GuestOptions, 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";
@@ -45,6 +45,12 @@ export interface OntologyConfig<Entities extends ReadonlyArray<AnyEntity> = Read
45
45
  * read everything and run only what other roles grant them.
46
46
  */
47
47
  readonly member?: MemberOptions;
48
+ /**
49
+ * Who may talk to the agent without signing in or signing up: the visitors of the websites
50
+ * `origins` names, on `web`. A guest is a session, not a user, and holds the built-in role
51
+ * `guest` with `permissions` alone. Absent, nobody chats without signing in or signing up.
52
+ */
53
+ readonly guest?: GuestOptions<RolePermission>;
48
54
  /** Who may become a member by signing in. Only invited people by default. */
49
55
  readonly signIn?: SignInOptions;
50
56
  /**