@segmentstream/ontology 0.119.0 → 0.121.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 (43) hide show
  1. package/CHANGELOG.md +32 -0
  2. package/README.md +55 -38
  3. package/dist/analyze.d.ts +8 -3
  4. package/dist/analyze.js +71 -31
  5. package/dist/diagnostics.d.ts +3 -3
  6. package/dist/diagnostics.js +1 -0
  7. package/dist/errors.d.ts +6 -0
  8. package/dist/errors.js +6 -0
  9. package/dist/feedback-config.d.ts +10 -1
  10. package/dist/feedback-config.js +46 -20
  11. package/dist/index.d.ts +3 -3
  12. package/dist/index.js +2 -2
  13. package/dist/manifest.d.ts +29 -9
  14. package/dist/manifest.js +12 -5
  15. package/dist/permissions.d.ts +1 -1
  16. package/dist/permissions.js +1 -1
  17. package/dist/role.d.ts +22 -3
  18. package/dist/role.js +42 -6
  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/server.js +1 -0
  34. package/dist/service/agent/tasks.d.ts +2 -0
  35. package/dist/service/agent/tasks.js +7 -4
  36. package/dist/service/chat/delivery.js +2 -0
  37. package/dist/service/errors.js +4 -3
  38. package/dist/service/runtime-contract.d.ts +5 -0
  39. package/dist/service/schemas.js +2 -0
  40. package/dist/service/service.js +2 -0
  41. package/dist/storage/authorization.js +9 -6
  42. package/dist/workflow.d.ts +7 -3
  43. package/package.json +1 -1
@@ -303,6 +303,7 @@ agent = {}) {
303
303
  if (reserve.status === "failed") {
304
304
  return yield* new ActionRejected({
305
305
  message: "This operation was refused. Its idempotency key is consumed.",
306
+ keyConsumed: true,
306
307
  });
307
308
  }
308
309
  return {
@@ -382,6 +383,7 @@ agent = {}) {
382
383
  if (outcome.status === "failed") {
383
384
  return yield* new ActionRejected({
384
385
  message: "The provider refused the message. This operation key is consumed.",
386
+ keyConsumed: true,
385
387
  });
386
388
  }
387
389
  return {
@@ -490,16 +490,17 @@ export function expectedFailure(error, requestId) {
490
490
  };
491
491
  }
492
492
  if (Predicate.isTagged(error, "ActionRejected")) {
493
- const message = String(error.message);
493
+ const { message, keyConsumed } = error;
494
494
  return {
495
495
  status: 422,
496
496
  body: {
497
497
  error: "action_rejected",
498
- detail: message,
498
+ detail: String(message),
499
499
  requestId,
500
- issues: [{ path: [], message }],
500
+ issues: [{ path: [], message: String(message) }],
501
501
  ...batchDetails(error),
502
502
  ...limitDetails(error),
503
+ ...(keyConsumed === true ? { key_consumed: true } : {}),
503
504
  },
504
505
  };
505
506
  }
@@ -516,6 +516,11 @@ export type AgentResolution = {
516
516
  readonly status: "existing" | "created";
517
517
  readonly member: AgentMember;
518
518
  readonly provisioned: boolean;
519
+ /**
520
+ * The person's turns count against the per-sender and workspace turn limits: everyone sign-up
521
+ * created, and an open channel's user while they hold no role but the earlier `member`.
522
+ */
523
+ readonly counted: boolean;
519
524
  readonly noticeDue: boolean;
520
525
  readonly onNewUserPending: boolean;
521
526
  /**
@@ -612,6 +612,8 @@ export const ErrorSchemas = {
612
612
  issues: Schema.Array(ValidationIssue),
613
613
  batch: Schema.optionalKey(BatchErrorDetails),
614
614
  limit: Schema.optionalKey(LimitErrorWire),
615
+ // The idempotency key is spent on an operation that did not happen: retry with a new one.
616
+ key_consumed: Schema.optionalKey(Schema.Literal(true)),
615
617
  }),
616
618
  rateLimited: errorBody("RateLimited", 429, ["rate_limited"]),
617
619
  internal: errorBody("InternalError", 500, ["internal_error"]),
@@ -12,6 +12,7 @@ import { parsePageCatalog } from "../navigation-catalog.js";
12
12
  import { guestOf, signUpOriginsOf, signUpRolesOf } from "../manifest.js";
13
13
  import { isAllowed } from "../permissions.js";
14
14
  import { agentToolsFor } from "../runtime/guests.js";
15
+ import { implicitMemberOf } from "../role.js";
15
16
  import { sqlServiceRuntime } from "../runtime/service-binding.js";
16
17
  import { neonSignInLinks, segmentstreamSignInLinks } from "../runtime/sign-in-links.js";
17
18
  import { memberFileRoutes } from "./member-file-routes.js";
@@ -432,6 +433,7 @@ export function createOntologyService(ontology, config) {
432
433
  workspaceId: config.workspaceId,
433
434
  engine: config.workflowEngine ?? vercelWorkflowEngine,
434
435
  agentTools,
436
+ implicitMember: implicitMemberOf(ontology.roles) !== undefined,
435
437
  });
436
438
  const attachments = preview
437
439
  ? Layer.empty
@@ -1,8 +1,9 @@
1
1
  import { Effect } from "effect";
2
2
  import { missingPermission, permissionsOf, principalScopes } from "../permissions.js";
3
3
  import { PermissionDenied } from "../errors.js";
4
- import { MEMBER_ROLE, FEEDBACK_REPORTER_ROLE, toSnakeCase } from "../names.js";
5
- import { rolesOf } from "../runtime/principals.js";
4
+ import { FEEDBACK_REPORTER_ROLE, toSnakeCase } from "../names.js";
5
+ import { implicitRoleNames } from "../role.js";
6
+ import { rolesOf, workflowRoles } from "../runtime/principals.js";
6
7
  import { PIPELINE_WORKER_PROVIDER } from "../runtime/workload.js";
7
8
  import { WORKFLOW_USER_PROVIDER, workflowOfSubject } from "../runtime/workflow-users.js";
8
9
  /** Re-read user and roles in the same transaction that authorizes a storage operation. */
@@ -24,9 +25,10 @@ workflowPrincipal) {
24
25
  const users = yield* sql.unsafe(`SELECT kind::text, active, identity_provider, identity_subject FROM "user" WHERE id = $1::uuid FOR SHARE`, [principalId]);
25
26
  const user = users[0];
26
27
  const roles = yield* sql.unsafe(`SELECT role FROM "_user_roles" WHERE user_id = $1::uuid FOR SHARE`, [principalId]);
28
+ const reserved = implicitRoleNames(ontology.roles);
27
29
  const held = roles
28
30
  .map((row) => String(row.role))
29
- .filter((name) => toSnakeCase(name) !== FEEDBACK_REPORTER_ROLE);
31
+ .filter((name) => !(reserved.length > 0 && toSnakeCase(name) === FEEDBACK_REPORTER_ROLE));
30
32
  // Reuse human principal resolution rather than reconstructing implicit authority here. The
31
33
  // result rechecks required permissions and is the reader for scoped file reads; the caller's
32
34
  // consent-narrowed principal still governs the rest of the operation.
@@ -41,8 +43,9 @@ workflowPrincipal) {
41
43
  user?.kind === "service" &&
42
44
  user.identity_provider === PIPELINE_WORKER_PROVIDER &&
43
45
  user.identity_subject === `pipeline-workers:${execution.workspaceId}`;
44
- // A workflow's runs hold what member and the declared workflow's role grant. The database
45
- // must assign exactly that role: an extra or stale assignment widens nothing and is refused.
46
+ // A workflow's runs hold what the declared workflow's role grants (and the implicit member's,
47
+ // while the ontology declares one). The database must assign exactly that role: an extra or
48
+ // stale assignment widens nothing and is refused.
46
49
  const workflowUser = user?.kind === "service" && user.identity_provider === WORKFLOW_USER_PROVIDER;
47
50
  // The user's subject must be exactly the principal's, workspace id included.
48
51
  const workflow = workflowUser &&
@@ -55,7 +58,7 @@ workflowPrincipal) {
55
58
  execution === undefined &&
56
59
  held.length === 1 &&
57
60
  held[0] === workflow.role;
58
- const liveHeld = workflowUser && workflow ? [MEMBER_ROLE, workflow.role] : (member?.roles ?? held);
61
+ const liveHeld = workflowUser && workflow ? workflowRoles(ontology, workflow.role) : (member?.roles ?? held);
59
62
  const permissions = worker
60
63
  ? ["*:*"]
61
64
  : workflowUser && !declaredWorkflow
@@ -22,7 +22,10 @@ export declare const MAX_ACTION_TRIGGERS = 20;
22
22
  export interface TriggerRuns {
23
23
  /** The action the trigger runs, as its handle: `Lead.actions.notify`. */
24
24
  readonly runs?: AnyActionHandle;
25
- /** The declared role, other than `member`, the runs hold with member's; required with `runs`. */
25
+ /**
26
+ * The declared role the runs hold, required with `runs`: exactly its permissions, with the
27
+ * built-in `member`'s while the ontology declares one.
28
+ */
26
29
  readonly role?: string;
27
30
  }
28
31
  /**
@@ -264,8 +267,9 @@ export interface WorkflowOptions<S extends AnyInputSchema | undefined = undefine
264
267
  /** Required, like every declaration: what the workflow does and why. */
265
268
  readonly description: string;
266
269
  /**
267
- * The declared role, other than `member`, whose permissions the workflow's runs hold together
268
- * with member's. Its runs act as the workflow's own service user.
270
+ * The declared role whose permissions the workflow's runs hold: exactly its permissions, with
271
+ * the built-in `member`'s while the ontology declares one. Its runs act as the workflow's own
272
+ * service user.
269
273
  */
270
274
  readonly role: string;
271
275
  /** A `Schema.Struct` of the workflow's input. Omitted means `{}`. */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@segmentstream/ontology",
3
- "version": "0.119.0",
3
+ "version": "0.121.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",