@segmentstream/ontology 0.120.0 → 0.122.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 (45) hide show
  1. package/CHANGELOG.md +36 -0
  2. package/README.md +55 -38
  3. package/dist/analyze.d.ts +11 -5
  4. package/dist/analyze.js +79 -34
  5. package/dist/chat.d.ts +2 -1
  6. package/dist/diagnostics.d.ts +3 -3
  7. package/dist/diagnostics.js +1 -0
  8. package/dist/feedback-config.d.ts +10 -1
  9. package/dist/feedback-config.js +46 -20
  10. package/dist/index.d.ts +3 -3
  11. package/dist/index.js +2 -2
  12. package/dist/manifest.d.ts +29 -9
  13. package/dist/manifest.js +12 -5
  14. package/dist/permissions.d.ts +1 -1
  15. package/dist/permissions.js +1 -1
  16. package/dist/role.d.ts +22 -3
  17. package/dist/role.js +42 -6
  18. package/dist/runtime/agents.js +58 -0
  19. package/dist/runtime/generated-actions.js +14 -4
  20. package/dist/runtime/member-writes.d.ts +10 -4
  21. package/dist/runtime/member-writes.js +15 -7
  22. package/dist/runtime/model.d.ts +5 -0
  23. package/dist/runtime/model.js +5 -2
  24. package/dist/runtime/new-user-hook.js +7 -4
  25. package/dist/runtime/principals.d.ts +30 -10
  26. package/dist/runtime/principals.js +88 -44
  27. package/dist/runtime/records.js +1 -1
  28. package/dist/runtime/resolve-agent-identity.js +3 -3
  29. package/dist/runtime/sql-runtime.js +2 -1
  30. package/dist/runtime/user-roles.d.ts +8 -7
  31. package/dist/runtime/user-roles.js +17 -12
  32. package/dist/runtime/where.js +4 -4
  33. package/dist/service/agent/chat-archive.d.ts +2 -1
  34. package/dist/service/agent/chat-archive.js +12 -8
  35. package/dist/service/agent/server.js +1 -0
  36. package/dist/service/agent/tasks.d.ts +2 -0
  37. package/dist/service/agent/tasks.js +7 -4
  38. package/dist/service/agent/web-tokens.js +9 -1
  39. package/dist/service/chat/reads.js +5 -1
  40. package/dist/service/mcp/tools.js +7 -3
  41. package/dist/service/runtime-contract.d.ts +12 -0
  42. package/dist/service/service.js +2 -0
  43. package/dist/storage/authorization.js +9 -6
  44. package/dist/workflow.d.ts +7 -3
  45. package/package.json +1 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,41 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.122.0
4
+
5
+ The website's visitors' chats in the inbox: `inbox.roles` may list `guest` where the ontology
6
+ declares `guest`, and each visitor's chat with the agent, `guest:<id>` on the `web` channel, then
7
+ becomes an `agent_chat` record of kind `private` when the service admits a turn of theirs, without
8
+ members and with `lastMessageAt` kept current. A workflow's runs and its agent tasks read registered
9
+ chats as staff do: their role's `agent_chat:read`, within its scope, finds the records and reads a
10
+ chat's messages with `chat_history` by the record id, as the workflow's own user and never as a
11
+ participant. A daily report of the website's chats is then a workflow that finds the day's chats,
12
+ has an agent task summarize them and posts the summary.
13
+
14
+ ## 0.121.0
15
+
16
+ The platform builds in no role. An ontology without `defineOntology({ member })` names every role
17
+ itself: an invited or paired person holds exactly the roles their invitation, a later grant or
18
+ `signUp.roles` gave them; a workflow's runs and its agent tasks hold exactly the workflow's role;
19
+ and no `feedback_reporter` role is added. `member` and `feedback_reporter` are names like any
20
+ other, which a workspace may declare and grant. A workspace that wants its people to report app
21
+ feedback grants `app_feedback:submit`, with `app_feedback:read` and `app_feedback:acknowledge`
22
+ scoped to `{ reporter: me }`, in its own roles; `check` warns `feedback-unreportable` when it turns
23
+ feedback on and no role may report. `signIn.policy: "open"` needs `member`, which it admits people
24
+ with; `check` refuses it otherwise, and `signIn.onNewUser` too. The manifest marks `member` and
25
+ `feedback_reporter` built in only while the ontology declares `member`. The agent's identity
26
+ answer says in `counted` whether the person's turns count against the limits.
27
+
28
+ An ontology that declares `defineOntology({ member: { permissions } })` behaves as before: every
29
+ invited or paired user, every workflow and every agent task holds `member`, people also hold the
30
+ implicit `feedback_reporter`, and both names stay reserved.
31
+
32
+ Action required: an ontology that does not set `member` no longer gives every invited member, every
33
+ workflow and every agent task `*:read`. Declare a role for what everyone may do, such as
34
+ `role("team", { permissions: ["*:read", …] })`, grant it to your current members
35
+ (`segmentstream ontology member grant <email> --role team`) and invite people with it, and add the
36
+ reads each workflow needs to its role; or set `member: { permissions: ["*:read"] }` to keep the
37
+ earlier behavior.
38
+
3
39
  ## 0.120.0
4
40
 
5
41
  A chat post whose delivery did not happen and spent its idempotency key, a message the provider
package/README.md CHANGED
@@ -159,10 +159,10 @@ SDK 0.13.0 also serves aggregates. Upgrade notes:
159
159
  `User` cannot.
160
160
  - `aggregate` is reserved for the route and the MCP tool: rename an entity with that name
161
161
  before upgrading.
162
- - Under `signIn: { policy: "open" }`, anyone who signs in holds `member`, so `check` refuses a
163
- `member` whose wildcard (`*:read`, the default, or `*:*`) would let strangers read
164
- warehouse-backed entities through aggregates. Grant those to `member` by name
165
- (`acme_sales:read`), or keep the `invited` policy.
162
+ - Under `signIn: { policy: "open" }`, which only an ontology declaring the built-in `member`
163
+ accepts, anyone who signs in holds `member`, so `check` refuses a `member` whose wildcard
164
+ (`*:read` or `*:*`) would let strangers read warehouse-backed entities through aggregates.
165
+ Grant those to `member` by name (`acme_sales:read`), or keep the `invited` policy.
166
166
 
167
167
  See `docs/ontology-metrics.md`.
168
168
 
@@ -371,10 +371,9 @@ import { Lead, sales } from "./lead";
371
371
 
372
372
  export default defineOntology({
373
373
  entities: [Lead],
374
+ // Every role is the workspace's own: a person holds exactly the roles they were given.
374
375
  roles: [sales],
375
- // What every active app user may do. Without it, members may only read: ["*:read"].
376
- member: { permissions: ["*:read"] },
377
- // Who may become a member by signing in: only invited people (the default), or anyone ("open").
376
+ // Who may become a member by signing in: only invited people (the default).
378
377
  signIn: { policy: "invited" },
379
378
  });
380
379
  ```
@@ -391,8 +390,16 @@ export default defineOntology({
391
390
  held for a member to approve, edit or reject. Every ontology includes them. Text feedback defaults on with built-in `AppFeedback`; files follow the non-feedback-blob policy
392
391
  (or an explicit opt-in) and add `AppFeedbackFile` (see [App feedback](#app-feedback)).
393
392
  - `role(name, { description, permissions })` declares a role: a named set of permissions.
394
- `member` is built in: every active app user holds it, with the permissions of
395
- `defineOntology({ member })`.
393
+ Every role is the workspace's own, named as it likes; `member` and `feedback_reporter` are
394
+ names like any other. A person holds exactly the roles an invitation, a grant
395
+ (`user.grant_roles`, `User.grantRoles`, the CLI or the console) or sign-up gave them, an API
396
+ key the roles it was created with, and a workflow's runs the workflow's role. Give staff a
397
+ role every member of staff holds, such as the starter's `team`, at invitation.
398
+ - `defineOntology({ member: { permissions } })` keeps the earlier built-in `member`: every
399
+ invited or paired user, every workflow's runs and every agent task hold it without a grant,
400
+ people also hold the built-in `feedback_reporter`, and both names are reserved. Listing the
401
+ exported `member` in `roles` without `member:` is an error. New ontologies declare their own
402
+ roles instead.
396
403
  - `.actions((self) => ({ … }))` adds actions. Each action has a description, an input
397
404
  schema and an Effect handler. It requires the permission `<entity>:<action name>`, or the
398
405
  one its `permission` names.
@@ -459,11 +466,11 @@ export default defineOntology({
459
466
  exactly `roles`, declared roles passed as role objects or names, or the channel's own list in
460
467
  `byChannel`; `[]` grants nothing beyond what is later granted or shared. Sign-up writes them as
461
468
  ordinary role assignments in its own transaction, so one person's roles can be revoked or added
462
- to like anyone's. A user sign-up created never holds `member`, the baseline of invited people,
463
- nor the implicit feedback reporter role, and the platform records that they signed up (`_channel_users.signed_up`) whatever roles they
469
+ to like anyone's. A user sign-up created never holds the built-in `member` or feedback
470
+ reporter role of an ontology that declares `member`, and the platform records that they signed up (`_channel_users.signed_up`) whatever roles they
464
471
  hold later: turn limits always count them. A channel not listed admits only invited or paired
465
472
  people; a workspace without `signUp` is internal. `check` refuses in sign-up roles an
466
- undeclared role, `member`, an entity wildcard, and a generated create, update, delete, link or
473
+ undeclared role, the built-in `member`, an entity wildcard, and a generated create, update, delete, link or
467
474
  unlink that is not scoped (`{ permission, where: { createdBy: me } }`); an unscoped read of a
468
475
  stored entity warns for review. Telegram and WhatsApp need a matching `chat.<channel>` adapter.
469
476
  A channel opened both here and by `signIn.channels` or `signIn.policy: "open"` is refused.
@@ -478,7 +485,8 @@ export default defineOntology({
478
485
  - `signIn: { policy }` decides who may become a member by signing in. `invited`, the
479
486
  default, admits only people whose email a member already has, from an invitation or a
480
487
  role grant; anyone else is answered 403 `not_invited`. `open` makes anyone who signs in a
481
- member holding only `member`. The manifest carries the policy. <!-- @legacy ontology.legacy-channel-admission -->
488
+ member holding only the built-in `member`, so `check` refuses it in an ontology that does not
489
+ declare `member`; use `signUp` instead. The manifest carries the policy. <!-- @legacy ontology.legacy-channel-admission -->
482
490
  `signIn.codeLink: true` makes the platform's sign-in code emails also link to the app's
483
491
  `/sign-in` page with the code in the URL fragment; the app SDK's `useSignIn()` fills it in and
484
492
  waits for the person to confirm. Off when omitted; see the app authentication guide.
@@ -590,8 +598,9 @@ export default workflow("remindStaleLeads", {
590
598
  SDK did not compile is logged as `ontology.workflow.not_compiled` when the service starts, and
591
599
  starting it answers 503 `workflow_not_compiled`.
592
600
  - `name` is camelCase and unique; it names the workflow's user. `description` is required.
593
- - `role` is a declared role other than `member`, and not one that grants `*:*`. The runs hold
594
- what it and `member` grant.
601
+ - `role` is a declared role, and not one that grants `*:*`. The runs hold exactly this role,
602
+ so it grants what they read as well as the actions they run; in an ontology that declares
603
+ the built-in `member`, they also hold `member`, which cannot be the workflow's role.
595
604
  - `input` is a `Schema.Struct`; omitted means `{}`. `run` receives the decoded input in
596
605
  TypeScript names, and as its second argument `{ startedBy }`: the trigger, the member, or the
597
606
  platform (with the person it acted for) that started the run.
@@ -622,7 +631,8 @@ export default workflow("remindStaleLeads", {
622
631
  - `connections` lists the connections the steps call directly; each must be in
623
632
  `defineOntology({ connections })`. Connections declared on an action stay that action's.
624
633
  - At most 50 workflows. `check` reports `workflow_role_unknown`, `workflow_role_is_member`,
625
- `workflow_role_grants_nothing` (a warning: with member's grants, the role grants no action),
634
+ `workflow_role_grants_nothing` (a warning: the role, with the built-in `member`'s grants where
635
+ declared, grants no action),
626
636
  `workflow_role_wildcard` (the role grants `*:*`), `workflow_input_invalid`,
627
637
  `workflow_cron_invalid`, `workflow_cron_never_fires` (a warning: no listed month has the
628
638
  day), `workflow_run_missing` (`run` is not a function), `invalid-workflow`, `invalid-property`
@@ -681,8 +691,9 @@ A workflow hands the workspace's agent a prompt with `agentTask` from
681
691
  `@segmentstream/ontology/workflows`, in its `"use workflow"` body, and waits for the
682
692
  agent's final answer without holding compute. It is the agent members reach in chats, with the
683
693
  same instructions, models, tools and sandbox, acting as the workflow's own user: it sees and does
684
- exactly what the workflow's role and `member` grant, and ontology actions run without
685
- confirmation, since no person is present. Keep the role narrow: a prompt may carry untrusted text.
694
+ exactly what the workflow's role grants (and the built-in `member`, where the ontology declares
695
+ it), and ontology actions run without confirmation, since no person is present. Keep the role
696
+ narrow: a prompt may carry untrusted text.
686
697
 
687
698
  ```ts
688
699
  import { agentTask, workflow } from "@segmentstream/ontology/workflows";
@@ -848,8 +859,8 @@ reactivates redeclared ones. A run before the deploy creates a missing user
848
859
  and a user whose roles are not exactly the declared role is refused (`role_mismatch`) until a
849
860
  deploy reconciles it. Runs that are in flight on an older deployment when a deploy changes the
850
861
  workflow's role fail fatally at their next step, since their deployment declares the old role. The
851
- user never holds `member` as a role; every action re-reads its roles in
852
- the action's transaction and refuses any assignment other than the declared role.
862
+ user is assigned the declared role alone, never the built-in `member`; every action re-reads its
863
+ roles in the action's transaction and refuses any assignment other than the declared role.
853
864
 
854
865
  ## Batch writes in actions
855
866
 
@@ -996,11 +1007,11 @@ calls) and reading the web domains its configuration lists. `agent_tool` is no e
996
1007
  `check` refuses any other verb, a scoped grant, and an entity or toolset of the name; only a
997
1008
  permission naming `agent_tool` grants them, never `*:*` or a workload's `*:*`. `agentToolsOf(roles,
998
1009
  principal)` is what the ontology tells the agent a caller holds, as `agent_tools` in every answer
999
- that names whom the agent acts for. While no role, `member` and sign-up roles included, names an
1000
- `agent_tool` permission, it is `["sandbox"]` for everyone, as before these permissions, and `check`
1001
- warns `agent-tools-implicit`; from 2027-02-15 such an ontology grants no agent tool. Guests hold
1002
- what `guest.permissions` grant, never the sandbox and never implicitly, and those permissions count
1003
- for nothing in whether the ontology names agent tools.
1010
+ that names whom the agent acts for. While no role, sign-up roles and the built-in `member`
1011
+ included, names an `agent_tool` permission, it is `["sandbox"]` for everyone, as before these
1012
+ permissions, and `check` warns `agent-tools-implicit`; from 2027-02-15 such an ontology grants no
1013
+ agent tool. Guests hold what `guest.permissions` grant, never the sandbox and never implicitly, and
1014
+ those permissions count for nothing in whether the ontology names agent tools.
1004
1015
 
1005
1016
  - Reads require `<entity>:read`: lists, queries, records, history, both entities of a
1006
1017
  relationship traversal, and every entity a metric query touches. `include` and a filter through a relationship require `read` on
@@ -1008,8 +1019,9 @@ for nothing in whether the ontology names agent tools.
1008
1019
  - Each action requires one permission. The generated `upsert_by_<property>` requires both
1009
1020
  `<entity>:create` and `<entity>:update`.
1010
1021
  - A principal's permissions are the union of its roles' permissions in the ontology.
1011
- Members hold `member` and their assigned roles; an API key holds exactly the roles it was
1012
- created with; a workflow's runs hold the workflow's role and what `member` grants. A role the
1022
+ Members hold exactly their assigned roles; an API key holds exactly the roles it was created
1023
+ with; a workflow's runs hold exactly the workflow's role. In an ontology that declares the
1024
+ built-in `member`, invited and paired members and workflow runs also hold `member`. A role the
1013
1025
  ontology no longer declares grants nothing.
1014
1026
  - The catalog, `describe`, `graph`, `openapi.json` and `me` need only authentication;
1015
1027
  `status`, `sign-in/check` and the `docs` page need none. `?as=me` lists only the actions the caller may run.
@@ -1257,16 +1269,21 @@ lookup for code that holds a SQL client.
1257
1269
 
1258
1270
  ## App feedback
1259
1271
 
1260
- Text feedback is enabled when `feedback` is omitted. Every authenticated human member can
1261
- submit, read their own items and acknowledge answers, including members with no assigned roles.
1262
- It works through the app's REST API or the customer's own OAuth MCP client; an in-app agent,
1263
- pairing and Telegram are optional. Upgrade the ontology SDK and deploy to apply these defaults;
1264
- running deployments and historical manifests do not change retroactively.
1265
-
1266
- The reserved built-in `feedback_reporter` role supplies this authority during human principal
1267
- resolution. It is never stored or assignable, cannot be declared as a workspace role, and cannot
1268
- be used by API keys, services, workflows, hooks or `feedback.builders`. The workspace's `member`
1269
- permissions remain unchanged. OAuth `ontology:read` consent still removes writes.
1272
+ Text feedback is enabled when `feedback` is omitted. The workspace's roles say who may report:
1273
+ a role granting `app_feedback:submit`, `{ permission: "app_feedback:read", where: { reporter: me } }`
1274
+ and `{ permission: "app_feedback:acknowledge", where: { reporter: me } }` lets its holders submit,
1275
+ read their own items and acknowledge answers; with feedback files, `app_feedback_file:attach`
1276
+ and `app_feedback_file:read` scoped to `{ feedback: { reporter: me } }` add their files. The
1277
+ starter's `team` grants the first three. When `feedback` is set and no role grants
1278
+ `app_feedback:submit`, `check` warns `feedback-unreportable`. It works through the app's REST
1279
+ API or the customer's own OAuth MCP client; an in-app agent, pairing and Telegram are optional.
1280
+ Upgrade the ontology SDK and deploy to apply these defaults; running deployments and historical
1281
+ manifests do not change retroactively. OAuth `ontology:read` consent still removes writes.
1282
+
1283
+ An ontology that declares the built-in `member` also gives every invited or paired member the
1284
+ built-in `feedback_reporter` role, with those grants, during human principal resolution. It is
1285
+ never stored or assignable, cannot be declared as a workspace role while `member` is declared,
1286
+ and is not held by API keys, services, workflows, hooks or `feedback.builders`.
1270
1287
 
1271
1288
  Files follow a conservative policy resolved without network calls:
1272
1289
 
@@ -1359,7 +1376,7 @@ task header on any other route are a 403.
1359
1376
 
1360
1377
  | Route | Does |
1361
1378
  | ----------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
1362
- | `GET /api/ontology/agent/tasks/current` | `{ id, workflow, prompt, deadline_at, principal: { id, name, roles, agent_tools } }`; `roles` includes `member` |
1379
+ | `GET /api/ontology/agent/tasks/current` | `{ id, workflow, prompt, deadline_at, principal: { id, name, roles, agent_tools } }`; `roles` is the workflow's role, and `member` where declared |
1363
1380
  | `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 |
1364
1381
 
1365
1382
  Without either header the agent may call only the agent routes:
package/dist/analyze.d.ts CHANGED
@@ -34,7 +34,10 @@ export interface OntologyConfig<Entities extends ReadonlyArray<AnyEntity> = Read
34
34
  readonly hooks?: {
35
35
  readonly role: string;
36
36
  };
37
- /** Business roles. The built-in `member` role is always included. */
37
+ /**
38
+ * The roles people, API keys and workflows hold, each named by the workspace. A person holds the
39
+ * roles an invitation, a grant or sign-up gave them, and nothing else.
40
+ */
38
41
  readonly roles?: ReadonlyArray<Role>;
39
42
  /**
40
43
  * Durable processes written with the Vercel Workflow SDK, each declared with
@@ -50,8 +53,10 @@ export interface OntologyConfig<Entities extends ReadonlyArray<AnyEntity> = Read
50
53
  */
51
54
  readonly triggers?: ReadonlyArray<WorkflowTrigger>;
52
55
  /**
53
- * The built-in role every active app user holds. Its permissions default to `["*:read"]`: members
54
- * read everything and run only what other roles grant them.
56
+ * The earlier built-in `member` role: while it is declared, every invited or paired user, every
57
+ * workflow and every agent task holds it without being granted it, and people also hold the
58
+ * implicit `feedback_reporter`. Without it, the platform builds in no role: declare a role of
59
+ * your own, such as `team`, and grant it to the people and workflows that need it.
55
60
  */
56
61
  readonly member?: MemberOptions;
57
62
  /**
@@ -111,8 +116,9 @@ export interface OntologyConfig<Entities extends ReadonlyArray<AnyEntity> = Read
111
116
  /**
112
117
  * Whose private chats with the agent the workspace's staff work: `{ roles: [client] }`. The agent
113
118
  * registers each private chat of a person holding one of these roles as an `agent_chat` record of
114
- * kind `private`, which `agent_chat:read` within its scope reads with its messages. Absent, no
115
- * private chat is registered and `agent_chat` holds group chats only.
119
+ * kind `private`, which `agent_chat:read` within its scope reads with its messages. With `guest`
120
+ * declared, `"guest"` takes the chats of the website's visitors too. Absent, no private chat is
121
+ * registered and `agent_chat` holds group chats only.
116
122
  */
117
123
  readonly inbox?: InboxOptions<Role | string>;
118
124
  /**
package/dist/analyze.js CHANGED
@@ -12,13 +12,13 @@ import { QUERY_METRICS_ROUTE, LEGACY_MEMBER_NAME, ENTITY_ID, GENERATED_ACTIONS,
12
12
  import { REFERENCE_ANNOTATION, propertyDefinition, propertyOptionNames, unknownPropertyOptions, referenceTarget, } from "./property.js";
13
13
  import { AGENT_TOOL, AGENT_TOOL_VERBS, EXPLICIT_GRANT_ENTITIES, generatedActionPermissions, grants, isAllowed, MEMBER_AGENT_TOOLS, namesAgentTools, normalizePermission, parsePermission, parseWorkflowPermission, permissionOf, READ_VERB, rolesGranting, USER_IDENTITY_VERBS, USER_MEMBER_VERBS, WILDCARD, wildcardEntityCovers, WORKSPACE_SOURCE, WORKSPACE_SOURCE_PERMISSION, } from "./permissions.js";
14
14
  import { ON_DELETE, isRelationship } from "./relationship.js";
15
- import { isRole, member, role } from "./role.js";
15
+ import { implicitMemberOf, implicitRole, isImplicitRole, isRole, member, role, } from "./role.js";
16
16
  import { CHANNEL_PROVIDERS, DEFAULT_SIGN_IN_POLICY, GUEST_BOT_CHECK_SCHEMES, GUEST_CHANNELS, SIGN_UP_CHANNELS, SIGN_UP_CHAT_CHANNELS, isGuestBotCheckScheme, isGuestChannel, isSignInPolicy, isSignUpChannel, websiteOrigin, } from "./sign-in.js";
17
17
  import { BUILT_IN_EMAIL_VALUES, emailOptions, emailValueNames, SIGN_IN_CODE_VALUE, } from "./emails.js";
18
18
  import { AgentChat } from "./agent-chat.js";
19
19
  import { AgentReview } from "./agent-review.js";
20
20
  import { APP_FEEDBACK_ENTITIES } from "./app-feedback.js";
21
- import { feedbackOptions, feedbackRoles, checkFeedbackResponders, } from "./feedback-config.js";
21
+ import { feedbackOptions, feedbackRoles, checkFeedbackReporters, checkFeedbackResponders, } from "./feedback-config.js";
22
22
  import { User } from "./user.js";
23
23
  import { UserIdentity } from "./user-identity.js";
24
24
  import { authoringToWire } from "./authoring.js";
@@ -85,8 +85,7 @@ export function analyze(config, options = {}) {
85
85
  (!isPlainObject(config.hooks) ||
86
86
  Object.keys(config.hooks).some((key) => key !== "role") ||
87
87
  typeof config.hooks.role !== "string" ||
88
- nameToWire(config.hooks.role) === FEEDBACK_REPORTER_ROLE ||
89
- !declaredRoles.some((candidate) => candidate.name === nameToWire(config.hooks.role)))) {
88
+ !declaredRoles.some((candidate) => candidate.name === nameToWire(config.hooks.role) && !isImplicitRole(candidate)))) {
90
89
  report("invalid-permission", "hooks.role", "hooks.role must name a declared ontology role.");
91
90
  }
92
91
  const emails = emailOptions(config.emails, report, (name, path) => camelCaseName(name, path, "agreementReview", "Email", report));
@@ -103,7 +102,7 @@ export function analyze(config, options = {}) {
103
102
  ...(linkEmail === undefined ? {} : { linkEmail }),
104
103
  ...(codeEmail === undefined ? {} : { codeEmail }),
105
104
  };
106
- const inbox = inboxOptions(config.inbox, declaredRoles, report);
105
+ const inbox = inboxOptions(config.inbox, declaredRoles, guest !== undefined, report);
107
106
  const discovery = config.discovery;
108
107
  if (discovery !== undefined &&
109
108
  (!isPlainObject(discovery) ||
@@ -293,7 +292,7 @@ export function analyze(config, options = {}) {
293
292
  // builder grant. Invalid authored scopes must remain errors; generated redundancy needs no warning.
294
293
  checkPermissions(resolved, roles, workflows, report, [
295
294
  ...declaredRoles,
296
- ...roles.filter((candidate) => candidate.name === FEEDBACK_REPORTER_ROLE),
295
+ ...roles.filter((candidate) => candidate.name === FEEDBACK_REPORTER_ROLE && isImplicitRole(candidate)),
297
296
  ...(guest === undefined ? [] : [guest.role]),
298
297
  ], toolsets);
299
298
  checkOpenWarehouseReads({ entities: resolved, roles, signIn, report });
@@ -308,6 +307,11 @@ export function analyze(config, options = {}) {
308
307
  }
309
308
  if (feedback.enabled) {
310
309
  checkFeedbackResponders(roles, report);
310
+ // @legacy ontology.implicit-member
311
+ // Feedback is on by default; only a workspace that turns it on is told nobody can report.
312
+ if (implicitMemberOf(roles) === undefined && config.feedback !== undefined) {
313
+ checkFeedbackReporters(roles.filter((candidate) => !BUILT_IN_GUESTS.has(candidate)), report);
314
+ }
311
315
  }
312
316
  if ((Object.values(signIn.channels ?? {}).includes("open") ||
313
317
  SIGN_UP_CHAT_CHANNELS.some((channel) => signIn.signUp?.channels[channel] !== undefined)) &&
@@ -347,7 +351,9 @@ export function analyze(config, options = {}) {
347
351
  * `inbox`: the wire names of the roles whose private chats join the inbox, each a declared role or
348
352
  * `member`; `undefined` when absent or malformed.
349
353
  */
350
- function inboxOptions(value, declaredRoles, report) {
354
+ function inboxOptions(value, declaredRoles,
355
+ /** Whether the ontology declares `guest`, whose visitors' chats the inbox may take. */
356
+ guests, report) {
351
357
  if (value === undefined) {
352
358
  return undefined;
353
359
  }
@@ -359,6 +365,9 @@ function inboxOptions(value, declaredRoles, report) {
359
365
  return undefined;
360
366
  }
361
367
  const declared = new Set(declaredRoles.map((candidate) => candidate.name));
368
+ if (guests) {
369
+ declared.add(GUEST_ROLE);
370
+ }
362
371
  const roles = [];
363
372
  let valid = true;
364
373
  value.roles.forEach((candidate, index) => {
@@ -368,7 +377,7 @@ function inboxOptions(value, declaredRoles, report) {
368
377
  ? nameToWire(candidate)
369
378
  : undefined;
370
379
  if (name === undefined || !declared.has(name)) {
371
- report("invalid-inbox", `inbox.roles[${index}]`, "Use a role the ontology declares, or member.");
380
+ report("invalid-inbox", `inbox.roles[${index}]`, "Use a role the ontology declares, member, or guest when it declares guest.");
372
381
  valid = false;
373
382
  }
374
383
  else if (!roles.includes(name)) {
@@ -460,7 +469,10 @@ function resolveWorkflows(input) {
460
469
  report("invalid-workflow", "workflows", `An ontology may declare at most ${MAX_WORKFLOWS} workflows; it declares ` +
461
470
  `${input.workflows.length}.`);
462
471
  }
463
- const memberPermissions = roles.find((candidate) => candidate.name === MEMBER_ROLE)?.permissions;
472
+ // @legacy ontology.implicit-member
473
+ // A workflow's runs hold the implicit member's permissions beside their own role's.
474
+ const implicit = implicitMemberOf(roles);
475
+ const memberPermissions = implicit?.permissions;
464
476
  const names = new Set();
465
477
  const resolved = [];
466
478
  input.workflows.forEach((candidate, index) => {
@@ -489,7 +501,9 @@ function resolveWorkflows(input) {
489
501
  }
490
502
  const role = typeof candidate.role === "string" ? nameToWire(candidate.role) : undefined;
491
503
  const declared = roles.find((existing) => existing.name === role);
492
- if (role === FEEDBACK_REPORTER_ROLE) {
504
+ if (declared !== undefined &&
505
+ declared.name === FEEDBACK_REPORTER_ROLE &&
506
+ isImplicitRole(declared)) {
493
507
  report("workflow_role_unknown", `${path}.role`, "feedback_reporter is implicit human authority and cannot be a workflow role.");
494
508
  valid = false;
495
509
  }
@@ -497,14 +511,14 @@ function resolveWorkflows(input) {
497
511
  report("workflow_role_unknown", `${path}.role`, "guest is the role of guests and cannot be a workflow role.");
498
512
  valid = false;
499
513
  }
500
- else if (role === MEMBER_ROLE) {
514
+ else if (declared !== undefined && declared === implicit) {
501
515
  report("workflow_role_is_member", `${path}.role`, "a workflow runs as a declared role of its own; its runs hold member's permissions " +
502
516
  "anyway, so name the role that adds what the workflow does.");
503
517
  valid = false;
504
518
  }
505
519
  else if (declared === undefined) {
506
520
  report("workflow_role_unknown", `${path}.role`, `${JSON.stringify(candidate.role) ?? "undefined"} is not a declared role; a workflow ` +
507
- "runs as one of the ontology's roles, other than member.");
521
+ "runs as one of the ontology's roles.");
508
522
  valid = false;
509
523
  }
510
524
  else if (Array.isArray(declared.permissions) && declared.permissions.includes("*:*")) {
@@ -517,12 +531,13 @@ function resolveWorkflows(input) {
517
531
  ...(Array.isArray(memberPermissions) ? memberPermissions : []),
518
532
  ...(Array.isArray(declared.permissions) ? declared.permissions : []),
519
533
  ])) {
520
- report("workflow_role_grants_nothing", `${path}.role`, `${declared.name}, with member's permissions, grants no action, so the workflow can only ` +
521
- "read; add the actions it runs to the role's permissions.", "warning");
534
+ report("workflow_role_grants_nothing", `${path}.role`, `${declared.name}${implicit === undefined ? "" : ", with member's permissions,"} grants ` +
535
+ "no action, so the workflow can at most read; add the actions it runs to the role's " +
536
+ "permissions.", "warning");
522
537
  }
523
538
  if (input.checkGrants &&
524
539
  declared !== undefined &&
525
- role !== MEMBER_ROLE &&
540
+ declared !== implicit &&
526
541
  (declared.scopes ?? []).length > 0) {
527
542
  const scoped = [...new Set((declared.scopes ?? []).map((scope) => scope.permission))];
528
543
  report("workflow_role_scoped", `${path}.role`, `${declared.name} scopes ${scoped.join(", ")}; bare me is the workflow service user's ID. ` +
@@ -1340,10 +1355,12 @@ function collectEntities(config, builtIns, report) {
1340
1355
  const REMOVED_ALLOW = "allow was removed: each action requires one permission (its permission option, by default " +
1341
1356
  "<entity>:<action name>), and roles grant permissions in their permissions list.";
1342
1357
  /** The built-in `member` role with the ontology's member permissions. */
1358
+ // @legacy ontology.implicit-member
1359
+ /** The implicit `member` while the definition declares `member`; none otherwise. */
1343
1360
  function memberRole(config, report) {
1344
1361
  const options = config.member;
1345
1362
  if (options === undefined) {
1346
- return member;
1363
+ return undefined;
1347
1364
  }
1348
1365
  if (!isPlainObject(options)) {
1349
1366
  report("missing-permissions", "member", 'member takes { permissions: ["*:read", …] }.');
@@ -1352,10 +1369,10 @@ function memberRole(config, report) {
1352
1369
  if ("allow" in options) {
1353
1370
  report("removed-allow", "member.allow", REMOVED_ALLOW);
1354
1371
  }
1355
- return role(MEMBER_ROLE, {
1372
+ return implicitRole(role(MEMBER_ROLE, {
1356
1373
  description: member.description,
1357
1374
  permissions: options.permissions,
1358
- });
1375
+ }));
1359
1376
  }
1360
1377
  /** The sign-in policy, which decides whether a stranger who signs in becomes a member. */
1361
1378
  function signInOptions(config, report) {
@@ -1508,7 +1525,11 @@ function signUpOptions(config, signIn, declaredRoles, report) {
1508
1525
  report("invalid-sign-in", `signUp.${key}`, `Unknown signUp key: ${key}.`);
1509
1526
  }
1510
1527
  }
1511
- const declared = new Set(declaredRoles.map((candidate) => candidate.name).filter((name) => name !== MEMBER_ROLE));
1528
+ const declared = new Set(declaredRoles
1529
+ .filter((candidate) => !isImplicitRole(candidate))
1530
+ .map((candidate) => candidate.name));
1531
+ // @legacy ontology.implicit-member
1532
+ const implicit = implicitMemberOf(declaredRoles) !== undefined;
1512
1533
  const roleNames = (value, path) => {
1513
1534
  if (!Array.isArray(value)) {
1514
1535
  report("invalid-sign-in", path, "Use a list of declared roles; [] grants none.");
@@ -1521,7 +1542,7 @@ function signUpOptions(config, signIn, declaredRoles, report) {
1521
1542
  : typeof candidate === "string"
1522
1543
  ? nameToWire(candidate)
1523
1544
  : undefined;
1524
- if (name === MEMBER_ROLE) {
1545
+ if (implicit && name === MEMBER_ROLE) {
1525
1546
  report("invalid-sign-in", `${path}[${index}]`, "member is the baseline of invited people; sign-up grants declared roles only.");
1526
1547
  }
1527
1548
  else if (name === undefined || !declared.has(name)) {
@@ -1923,18 +1944,27 @@ function checkSignUpAction(input) {
1923
1944
  }
1924
1945
  }
1925
1946
  function collectRoles(config, report) {
1926
- const roles = [memberRole(config, report)];
1947
+ const implicit = memberRole(config, report);
1948
+ const roles = implicit === undefined ? [] : [implicit];
1927
1949
  (config.roles ?? []).forEach((candidate, index) => {
1928
1950
  if (!isRole(candidate)) {
1929
1951
  report("invalid-role", `roles[${index}]`, "is not a role; declare roles with role(name, { description, permissions }).");
1930
1952
  return;
1931
1953
  }
1954
+ // @legacy ontology.implicit-member
1932
1955
  // Listing the built-in role is harmless: its permissions come from defineOntology({ member }).
1933
- if (candidate === member || roles.includes(candidate)) {
1956
+ if (implicit !== undefined && (candidate === member || roles.includes(candidate))) {
1934
1957
  return;
1935
1958
  }
1936
1959
  const path = `roles.${candidate.name}`;
1937
- if (candidate.name === MEMBER_ROLE || candidate.name === FEEDBACK_REPORTER_ROLE) {
1960
+ if (candidate === member) {
1961
+ report("invalid-role", `roles[${index}]`, "the built-in member exists only with defineOntology({ member }); declare a role of " +
1962
+ 'your own, such as role("team", { description, permissions }).');
1963
+ return;
1964
+ }
1965
+ // @legacy ontology.implicit-member
1966
+ if (implicit !== undefined &&
1967
+ (candidate.name === MEMBER_ROLE || candidate.name === FEEDBACK_REPORTER_ROLE)) {
1938
1968
  report("reserved-name", path, `${candidate.name} is a reserved built-in role.`);
1939
1969
  return;
1940
1970
  }
@@ -2826,7 +2856,7 @@ function listed(names) {
2826
2856
  return names.length === 1 ? names[0] : `${names.slice(0, -1).join(", ")} and ${names.at(-1)}`;
2827
2857
  }
2828
2858
  function checkRolePermissions(candidate, verbs, workflows, report) {
2829
- const builtIn = candidate.name === MEMBER_ROLE || BUILT_IN_GUESTS.has(candidate);
2859
+ const builtIn = isImplicitRole(candidate) || BUILT_IN_GUESTS.has(candidate);
2830
2860
  const path = builtIn ? `${candidate.name}.permissions` : `roles.${candidate.name}.permissions`;
2831
2861
  const permissions = candidate.permissions;
2832
2862
  if (!Array.isArray(permissions)) {
@@ -2876,7 +2906,14 @@ function checkOpenWarehouseReads(input) {
2876
2906
  const warehouseBacked = entities
2877
2907
  .filter((candidate) => candidate.entity.definition.source !== undefined)
2878
2908
  .map((candidate) => candidate.name);
2879
- const memberPermissions = roles.find((candidate) => candidate.name === MEMBER_ROLE)?.permissions;
2909
+ const implicit = implicitMemberOf(roles);
2910
+ // @legacy ontology.legacy-channel-admission
2911
+ if (signIn.policy === "open" && implicit === undefined) {
2912
+ report("invalid-sign-in", "signIn.policy", "signIn policy open admits people with the built-in member, which only " +
2913
+ "defineOntology({ member }) declares; use signUp with the roles they get.");
2914
+ return;
2915
+ }
2916
+ const memberPermissions = implicit?.permissions;
2880
2917
  if (signIn.policy !== "open" ||
2881
2918
  warehouseBacked.length === 0 ||
2882
2919
  !Array.isArray(memberPermissions)) {
@@ -2908,7 +2945,7 @@ function checkOpenChannels(input) {
2908
2945
  report("invalid-sign-in", "member", `Open channels require explicit member permissions; ${hint}.`);
2909
2946
  return;
2910
2947
  }
2911
- const permissions = roles.find((candidate) => candidate.name === MEMBER_ROLE)?.permissions;
2948
+ const permissions = implicitMemberOf(roles)?.permissions;
2912
2949
  if (!Array.isArray(permissions)) {
2913
2950
  report("invalid-sign-in", "member.permissions", "Open channels require an explicit permissions array.");
2914
2951
  return;
@@ -2952,7 +2989,12 @@ function checkNewUserAction(input) {
2952
2989
  if (Result.isFailure(Schema.decodeUnknownResult(found.action.input)({}))) {
2953
2990
  fail("onNewUser cannot have required input; it is called with {}.");
2954
2991
  }
2955
- if (!isAllowed(found.permission, { permissions: roles[0]?.permissions ?? [] })) {
2992
+ const member = implicitMemberOf(roles);
2993
+ if (member === undefined) {
2994
+ fail("onNewUser runs with the built-in member, which only defineOntology({ member }) " +
2995
+ "declares; use signUp and onSignUp.");
2996
+ }
2997
+ else if (!isAllowed(found.permission, { permissions: member.permissions ?? [] })) {
2956
2998
  fail("onNewUser must be runnable by member.");
2957
2999
  }
2958
3000
  if (found.action.hints?.idempotent !== true) {
@@ -2979,7 +3021,7 @@ function checkAgentToolGrants(roles, report) {
2979
3021
  report("agent-tools-implicit", "roles", `no role names an ${AGENT_TOOL} permission, so the agent gives everyone it acts for, people ` +
2980
3022
  `who sign up included, its sandbox tools. From ${IMPLICIT_AGENT_SANDBOX_ENDS} only roles ` +
2981
3023
  `grant the agent's own tools: name ${named.slice(0, -1).join(", ")} or ${named.at(-1)} in ` +
2982
- "the roles that may use them, such as member's permissions.", "warning");
3024
+ "the roles that may use them.", "warning");
2983
3025
  }
2984
3026
  /** The member management verbs that act on members a page or an agent must first find. */
2985
3027
  const ROSTER_VERBS = ["invite", "grant_roles"];
@@ -2989,9 +3031,11 @@ const ROSTER_VERBS = ["invite", "grant_roles"];
2989
3031
  */
2990
3032
  function checkRosterReads(roles, report) {
2991
3033
  const permissionsOf = (candidate) => Array.isArray(candidate?.permissions) ? candidate.permissions : [];
2992
- const memberPermissions = permissionsOf(roles.find((candidate) => candidate.name === MEMBER_ROLE));
3034
+ // @legacy ontology.implicit-member
3035
+ const implicit = implicitMemberOf(roles);
3036
+ const memberPermissions = permissionsOf(implicit);
2993
3037
  for (const candidate of roles) {
2994
- const builtIn = candidate.name === MEMBER_ROLE;
3038
+ const builtIn = candidate === implicit;
2995
3039
  const permissions = builtIn
2996
3040
  ? memberPermissions
2997
3041
  : [...permissionsOf(candidate), ...memberPermissions];
@@ -3028,7 +3072,7 @@ function checkPermissions(entities, roles, workflows, report, authoredRoles = ro
3028
3072
  const checkable = parsed !== undefined && verbs.has(parsed.entity);
3029
3073
  if (checkable && rolesGranting(granting, permission).length === 0) {
3030
3074
  report("unreachable-action", `${candidate.name}.actions.${name}`, `no role grants ${permission}, so nobody can run this action; ` +
3031
- "add it to a role's permissions or to member's.", "warning");
3075
+ "add it to the permissions of a role that may run it.", "warning");
3032
3076
  }
3033
3077
  }
3034
3078
  }
@@ -3377,7 +3421,8 @@ function checkScopes(entities, roles, verbs, report) {
3377
3421
  (candidate.unusedScopes ?? []).length > 0)) {
3378
3422
  return;
3379
3423
  }
3380
- const memberRole = roles.find((candidate) => candidate.name === MEMBER_ROLE);
3424
+ // @legacy ontology.implicit-member
3425
+ const memberRole = implicitMemberOf(roles);
3381
3426
  const memberGrants = memberRole === undefined ? [] : unscopedPermissions(memberRole);
3382
3427
  let built;
3383
3428
  // The manifest of the entities, for their query schemas; a definition it cannot be built from
@@ -3395,7 +3440,7 @@ function checkScopes(entities, roles, verbs, report) {
3395
3440
  };
3396
3441
  for (const candidate of roles) {
3397
3442
  const scopes = Array.isArray(candidate.scopes) ? candidate.scopes : [];
3398
- const base = candidate.name === MEMBER_ROLE || BUILT_IN_GUESTS.has(candidate)
3443
+ const base = isImplicitRole(candidate) || BUILT_IN_GUESTS.has(candidate)
3399
3444
  ? candidate.name
3400
3445
  : `roles.${candidate.name}`;
3401
3446
  const unscoped = unscopedPermissions(candidate);
@@ -3414,7 +3459,7 @@ function checkScopes(entities, roles, verbs, report) {
3414
3459
  const permission = scope.permission;
3415
3460
  const own = unscoped.find((granted) => grants(granted, permission));
3416
3461
  // A guest never holds member.
3417
- const fromMember = candidate.name === MEMBER_ROLE || BUILT_IN_GUESTS.has(candidate)
3462
+ const fromMember = candidate === memberRole || BUILT_IN_GUESTS.has(candidate)
3418
3463
  ? undefined
3419
3464
  : memberGrants.find((granted) => grants(granted, permission));
3420
3465
  if (own !== undefined) {
package/dist/chat.d.ts CHANGED
@@ -5,7 +5,8 @@ export interface ChatAttributionSettings {
5
5
  }
6
6
  /**
7
7
  * `inbox` of `defineOntology`: the roles of the people whose private chats with the agent the
8
- * workspace's staff work, as `agent_chat` records of kind `private`.
8
+ * workspace's staff work, as `agent_chat` records of kind `private`: declared roles, `member`, or
9
+ * `guest`, the website's visitors, where the ontology declares `guest`.
9
10
  */
10
11
  export interface InboxOptions<R = unknown> {
11
12
  readonly roles: ReadonlyArray<R>;