@segmentstream/ontology 0.181.0 → 0.183.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 (56) hide show
  1. package/CHANGELOG.md +36 -0
  2. package/README.md +23 -15
  3. package/dist/action.d.ts +11 -4
  4. package/dist/agent-chat.d.ts +8 -2
  5. package/dist/agent-chat.js +45 -29
  6. package/dist/agent-draft.d.ts +8 -8
  7. package/dist/analyze.d.ts +7 -9
  8. package/dist/analyze.js +159 -71
  9. package/dist/authoring.js +7 -1
  10. package/dist/chat.d.ts +32 -3
  11. package/dist/chat.js +33 -12
  12. package/dist/index.d.ts +1 -1
  13. package/dist/manifest.d.ts +174 -68
  14. package/dist/manifest.js +33 -2
  15. package/dist/migrate/model.d.ts +94 -50
  16. package/dist/permissions.d.ts +17 -0
  17. package/dist/permissions.js +17 -0
  18. package/dist/render.d.ts +6 -0
  19. package/dist/render.js +25 -10
  20. package/dist/runtime/agent-web.js +47 -26
  21. package/dist/runtime/agents.js +25 -0
  22. package/dist/runtime/guests.d.ts +4 -1
  23. package/dist/runtime/guests.js +24 -5
  24. package/dist/runtime/pipeline.d.ts +3 -3
  25. package/dist/runtime/pipeline.js +11 -4
  26. package/dist/service/agent/server.d.ts +0 -2
  27. package/dist/service/agent/server.js +42 -47
  28. package/dist/service/authentication.js +14 -3
  29. package/dist/service/catalog.js +3 -3
  30. package/dist/service/chat/chat-draft.d.ts +1 -1
  31. package/dist/service/chat/delivery.js +43 -22
  32. package/dist/service/chat/envelope.d.ts +8 -8
  33. package/dist/service/chat/local-reads.d.ts +5 -5
  34. package/dist/service/chat/routes.js +2 -0
  35. package/dist/service/chat/schemas.d.ts +40 -0
  36. package/dist/service/chat/schemas.js +3 -1
  37. package/dist/service/discovery-search.d.ts +1 -1
  38. package/dist/service/mcp/server.js +2 -0
  39. package/dist/service/mcp/tools.d.ts +10 -2
  40. package/dist/service/mcp/tools.js +11 -4
  41. package/dist/service/operations.js +10 -5
  42. package/dist/service/plan.d.ts +3 -1
  43. package/dist/service/plan.js +4 -2
  44. package/dist/service/runtime-contract.d.ts +3 -1
  45. package/dist/service/runtime-identity.d.ts +1 -0
  46. package/dist/service/runtime-identity.js +2 -0
  47. package/dist/service/schemas.d.ts +8 -0
  48. package/dist/service/service.js +2 -12
  49. package/dist/service/toolsets.d.ts +1 -1
  50. package/dist/service/toolsets.js +38 -4
  51. package/dist/sign-in.d.ts +14 -7
  52. package/dist/sign-in.js +4 -3
  53. package/dist/toolset.d.ts +17 -1
  54. package/package.json +1 -1
  55. package/dist/service/agent/public-group-action.d.ts +0 -23
  56. package/dist/service/agent/public-group-action.js +0 -53
package/dist/analyze.js CHANGED
@@ -100,7 +100,7 @@ export function analyze(config, options = {}) {
100
100
  }
101
101
  const emails = emailOptions(config.emails, report, (name, path) => camelCaseName(name, path, "agreementReview", "Email", report));
102
102
  const signInDeclared = signInOptions(config, report);
103
- const guest = guestOptions(config, report);
103
+ const guest = guestOptions(config, declaredRoles, report);
104
104
  const invitationEmail = signInEmailOption(config, emails, report, "invitationEmail");
105
105
  const linkEmail = signInEmailOption(config, emails, report, "linkEmail");
106
106
  const codeEmail = signInEmailOption(config, emails, report, "codeEmail");
@@ -267,10 +267,11 @@ export function analyze(config, options = {}) {
267
267
  }),
268
268
  ...(config.chat.attribution === undefined ? {} : { attribution: config.chat.attribution }),
269
269
  };
270
- // Posting to a chat and sending a reviewed reply both send through the chat connections.
270
+ // Sending to a chat and sending a reviewed reply both send through the chat connections.
271
271
  const sends = {
272
- agent_chat: "post_message",
273
- [AgentDraft.name]: "approve",
272
+ // @legacy ontology.chat-post-message post_message, the earlier name of send.
273
+ agent_chat: ["send", "post_message"],
274
+ [AgentDraft.name]: ["approve"],
274
275
  };
275
276
  // A chat post never reaches a channel whose kind only sends reviewed replies, except a
276
277
  // reply in a private chat the inbox registered, and the ontology sends nothing through a
@@ -283,7 +284,7 @@ export function analyze(config, options = {}) {
283
284
  ? entity
284
285
  : {
285
286
  ...entity,
286
- actions: entity.actions.map((candidate) => candidate.name !== sends[entity.name]
287
+ actions: entity.actions.map((candidate) => !sends[entity.name].includes(candidate.name)
287
288
  ? candidate
288
289
  : {
289
290
  ...candidate,
@@ -323,22 +324,6 @@ export function analyze(config, options = {}) {
323
324
  chat = { ...chat, retentionDays };
324
325
  }
325
326
  }
326
- if (config.publicGroupAction !== undefined) {
327
- const binding = config.publicGroupAction;
328
- const validKeys = isPlainObject(binding) &&
329
- [binding.entity, binding.action, binding.role].every((key) => typeof key === "string" && key.length > 0);
330
- const target = validKeys
331
- ? resolved
332
- .find((item) => item.name === nameToWire(binding.entity))
333
- ?.actions.find((item) => item.name === nameToWire(binding.action))
334
- : undefined;
335
- const role = validKeys
336
- ? roles.find((item) => item.name === nameToWire(binding.role) && !isImplicitRole(item))
337
- : undefined;
338
- if (!target || target.action.confirm || !role?.permissions.includes(target.permission)) {
339
- report("invalid-permission", "publicGroupAction", "Name an authored action without a member confirmation and a role explicitly granting that action.");
340
- }
341
- }
342
327
  checkEntityIdentities(resolved, report);
343
328
  checkMemberNames(resolved, report);
344
329
  const toolsets = resolveToolsets(original.toolsets, resolved, connections, report);
@@ -378,6 +363,17 @@ export function analyze(config, options = {}) {
378
363
  checkAgentToolGrants(roles.filter((candidate) => !BUILT_IN_GUESTS.has(candidate)), report);
379
364
  if (guest !== undefined) {
380
365
  checkGuestPermissions({ entities: resolved, guest: guest.role, report });
366
+ for (const name of new Set(Object.values(guest.resolved.byChannel ?? {}).flat())) {
367
+ const role = roles.find((candidate) => candidate.name === name);
368
+ if (role) {
369
+ checkGuestPermissions({
370
+ entities: resolved,
371
+ guest: role,
372
+ report,
373
+ path: `guest.byChannel (${name})`,
374
+ });
375
+ }
376
+ }
381
377
  }
382
378
  if (feedback.enabled) {
383
379
  checkFeedbackResponders(roles, report);
@@ -601,7 +597,7 @@ function workflowInputSchema(input) {
601
597
  */
602
598
  function grantsSomeAction(entities, permissions) {
603
599
  const holder = { permissions };
604
- return entities.some((entity) => entity.actions.some((candidate) => isAllowed(candidate.permission, holder)) ||
600
+ return entities.some((entity) => entity.actions.some((candidate) => openingPermissions(candidate).some((permission) => isAllowed(permission, holder))) ||
605
601
  Object.entries(entity.permissions).some(([verb, permission]) => verb !== READ_VERB && permission !== undefined && isAllowed(permission, holder)));
606
602
  }
607
603
  /**
@@ -1401,10 +1397,11 @@ function resolveToolsets(declared, entities, connections, report) {
1401
1397
  fail("invalid-toolset", at, `the lock has no tool ${tool}.`);
1402
1398
  }
1403
1399
  else if (!isPlainObject(options) ||
1404
- Object.keys(options).some((key) => key !== "description") ||
1400
+ Object.keys(options).some((key) => key !== "description" && key !== "handle") ||
1401
+ (options.handle !== undefined && typeof options.handle !== "function") ||
1405
1402
  (options.description !== undefined &&
1406
1403
  (typeof options.description !== "string" || options.description.trim() === ""))) {
1407
- fail("invalid-toolset", at, "a tool's options are { description }, a non-empty text.");
1404
+ fail("invalid-toolset", at, "Supply a non-empty description or a tool handler.");
1408
1405
  }
1409
1406
  }
1410
1407
  }
@@ -1422,6 +1419,7 @@ function resolveToolsets(declared, entities, connections, report) {
1422
1419
  tools: locked.tools.map((tool) => ({
1423
1420
  name: tool.name,
1424
1421
  mcpName: mcpToolName(name, tool.name),
1422
+ ...(overrides[tool.name]?.handle && { handle: overrides[tool.name].handle }),
1425
1423
  permission: `${name}:${tool.name}`,
1426
1424
  access: tool.access,
1427
1425
  fixed: tool.fixed,
@@ -1714,38 +1712,13 @@ function signInEmailOption(config, emails, report, key) {
1714
1712
  * `onSignUp` action. Every role must be a declared one other than `member`. A channel opened both
1715
1713
  * here and by the earlier `signIn.channels` or `signIn.policy: "open"` is refused.
1716
1714
  */
1717
- function signUpOptions(config, signIn, declaredRoles, report) {
1718
- const options = config.signUp;
1719
- const hook = config.onSignUp;
1720
- const result = {};
1721
- if (hook !== undefined &&
1722
- (typeof hook !== "string" || !parsePermission(hook) || hook.includes("*"))) {
1723
- report("invalid-sign-in", "onSignUp", "Use an action name: <entity>:<action>.");
1724
- }
1725
- else if (typeof hook === "string") {
1726
- if (options === undefined) {
1727
- report("invalid-sign-in", "onSignUp", "onSignUp runs after sign-up; declare signUp.");
1728
- }
1729
- result.onSignUp = hook;
1730
- }
1731
- if (options === undefined) {
1732
- return result;
1733
- }
1734
- if (!isPlainObject(options)) {
1735
- report("invalid-sign-in", "signUp", 'signUp takes { channels: ["telegram", "whatsapp", "email", "web"], roles: [...] }.');
1736
- return result;
1737
- }
1738
- for (const key of Object.keys(options)) {
1739
- if (!["channels", "roles", "byChannel", "origins"].includes(key)) {
1740
- report("invalid-sign-in", `signUp.${key}`, `Unknown signUp key: ${key}.`);
1741
- }
1742
- }
1715
+ function admissionRoleNames(declaredRoles, report) {
1743
1716
  const declared = new Set(declaredRoles
1744
1717
  .filter((candidate) => !isImplicitRole(candidate))
1745
1718
  .map((candidate) => candidate.name));
1746
1719
  // @legacy ontology.implicit-member
1747
1720
  const implicit = implicitMemberOf(declaredRoles) !== undefined;
1748
- const roleNames = (value, path) => {
1721
+ return (value, path) => {
1749
1722
  if (!Array.isArray(value)) {
1750
1723
  report("invalid-sign-in", path, "Use a list of declared roles; [] grants none.");
1751
1724
  return undefined;
@@ -1758,7 +1731,7 @@ function signUpOptions(config, signIn, declaredRoles, report) {
1758
1731
  ? nameToWire(candidate)
1759
1732
  : undefined;
1760
1733
  if (implicit && name === MEMBER_ROLE) {
1761
- report("invalid-sign-in", `${path}[${index}]`, "member is the baseline of invited people; sign-up grants declared roles only.");
1734
+ report("invalid-sign-in", `${path}[${index}]`, "member is the baseline of invited people; admission grants declared roles only.");
1762
1735
  }
1763
1736
  else if (name === undefined || !declared.has(name)) {
1764
1737
  report("invalid-sign-in", `${path}[${index}]`, "Use a role the ontology declares.");
@@ -1769,6 +1742,34 @@ function signUpOptions(config, signIn, declaredRoles, report) {
1769
1742
  });
1770
1743
  return names;
1771
1744
  };
1745
+ }
1746
+ function signUpOptions(config, signIn, declaredRoles, report) {
1747
+ const options = config.signUp;
1748
+ const hook = config.onSignUp;
1749
+ const result = {};
1750
+ if (hook !== undefined &&
1751
+ (typeof hook !== "string" || !parsePermission(hook) || hook.includes("*"))) {
1752
+ report("invalid-sign-in", "onSignUp", "Use an action name: <entity>:<action>.");
1753
+ }
1754
+ else if (typeof hook === "string") {
1755
+ if (options === undefined) {
1756
+ report("invalid-sign-in", "onSignUp", "onSignUp runs after sign-up; declare signUp.");
1757
+ }
1758
+ result.onSignUp = hook;
1759
+ }
1760
+ if (options === undefined) {
1761
+ return result;
1762
+ }
1763
+ if (!isPlainObject(options)) {
1764
+ report("invalid-sign-in", "signUp", 'signUp takes { channels: ["telegram", "whatsapp", "email", "web"], roles: [...] }.');
1765
+ return result;
1766
+ }
1767
+ for (const key of Object.keys(options)) {
1768
+ if (!["channels", "roles", "byChannel", "origins"].includes(key)) {
1769
+ report("invalid-sign-in", `signUp.${key}`, `Unknown signUp key: ${key}.`);
1770
+ }
1771
+ }
1772
+ const roleNames = admissionRoleNames(declaredRoles, report);
1772
1773
  const channels = [];
1773
1774
  if (!Array.isArray(options.channels) || options.channels.length === 0) {
1774
1775
  report("invalid-sign-in", "signUp.channels", `List the channels strangers may sign up through: ${SIGN_UP_CHANNELS.join(", ")}.`);
@@ -1884,6 +1885,8 @@ const WEBSITE_ORIGIN_HINT = "Use an origin alone, such as https://www.example.co
1884
1885
  const BUILT_IN_GUESTS = new WeakSet();
1885
1886
  /** The guest keys `defineOntology({ guest })` takes. */
1886
1887
  const GUEST_KEYS = [
1888
+ "openOnInvite",
1889
+ "byChannel",
1887
1890
  "channels",
1888
1891
  "origins",
1889
1892
  "permissions",
@@ -1895,7 +1898,7 @@ const GUEST_KEYS = [
1895
1898
  * definition declares `guest`. Every problem is reported; the role is made from the permissions
1896
1899
  * as they are, for the permission checks to report on.
1897
1900
  */
1898
- function guestOptions(config, report) {
1901
+ function guestOptions(config, declaredRoles, report) {
1899
1902
  const options = config.guest;
1900
1903
  if (options === undefined) {
1901
1904
  return undefined;
@@ -1917,7 +1920,12 @@ function guestOptions(config, report) {
1917
1920
  else {
1918
1921
  options.channels.forEach((channel, index) => {
1919
1922
  const path = `guest.channels[${index}]`;
1920
- if (!isGuestChannel(channel)) {
1923
+ const namedKind = typeof channel === "string" && channel.startsWith("channel:")
1924
+ ? chatChannelKind(config.chat, channel.slice(8))
1925
+ : undefined;
1926
+ if (!isGuestChannel(channel) ||
1927
+ (channel.startsWith("channel:") &&
1928
+ !["telegram", "slack", "whatsapp"].includes(namedKind ?? ""))) {
1921
1929
  report("invalid-sign-in", path, `Guests talk to the agent only on ${GUEST_CHANNELS.join(", ")}, not ${String(channel)}.`);
1922
1930
  }
1923
1931
  else if (channels.includes(channel)) {
@@ -1928,11 +1936,58 @@ function guestOptions(config, report) {
1928
1936
  }
1929
1937
  });
1930
1938
  }
1939
+ const openOnInvite = [];
1940
+ if (options.openOnInvite !== undefined) {
1941
+ if (!Array.isArray(options.openOnInvite)) {
1942
+ report("invalid-sign-in", "guest.openOnInvite", "List configured group connections.");
1943
+ }
1944
+ else {
1945
+ for (const channel of options.openOnInvite) {
1946
+ const kind = typeof channel === "string"
1947
+ ? chatChannelKind(config.chat, channel)
1948
+ : undefined;
1949
+ if ((kind !== "slack" && kind !== "telegram") ||
1950
+ !config.chat?.[channel] ||
1951
+ !(channels.includes(kind) || channels.includes(`channel:${channel}`))) {
1952
+ report("invalid-sign-in", "guest.openOnInvite", "Only configured guest group connections may open on an invitation.");
1953
+ }
1954
+ else {
1955
+ openOnInvite.push(channel);
1956
+ }
1957
+ }
1958
+ }
1959
+ }
1960
+ const byChannel = {};
1961
+ if (options.byChannel !== undefined) {
1962
+ if (!isPlainObject(options.byChannel)) {
1963
+ report("invalid-sign-in", "guest.byChannel", "Map a listed channel to its guest roles.");
1964
+ }
1965
+ else {
1966
+ const roleNames = admissionRoleNames(declaredRoles, report);
1967
+ for (const [channel, value] of Object.entries(options.byChannel)) {
1968
+ const path = `guest.byChannel.${channel}`;
1969
+ if (!isGuestChannel(channel) || !channels.includes(channel)) {
1970
+ report("invalid-sign-in", path, "Name a channel listed in guest.channels.");
1971
+ }
1972
+ else {
1973
+ const names = roleNames(value, path);
1974
+ if (names?.includes(MEMBER_ROLE) || names?.includes(GUEST_ROLE)) {
1975
+ report("invalid-sign-in", path, "Guest channel overrides take declared workspace roles.");
1976
+ }
1977
+ byChannel[channel] = names;
1978
+ }
1979
+ }
1980
+ }
1981
+ }
1931
1982
  const origins = [];
1932
- if (!Array.isArray(options.origins) || options.origins.length === 0) {
1983
+ if (channels.includes("web") &&
1984
+ (!Array.isArray(options.origins) || options.origins.length === 0)) {
1933
1985
  report("invalid-sign-in", "guest.origins", "List the websites whose visitors are guests, such as https://www.example.com.");
1934
1986
  }
1935
- else {
1987
+ else if (!channels.includes("web") && options.origins !== undefined) {
1988
+ report("invalid-sign-in", "guest.origins", "Origins apply only to the web channel.");
1989
+ }
1990
+ else if (Array.isArray(options.origins)) {
1936
1991
  options.origins.forEach((candidate, index) => {
1937
1992
  const origin = websiteOrigin(candidate);
1938
1993
  const path = `guest.origins[${index}]`;
@@ -1964,6 +2019,8 @@ function guestOptions(config, report) {
1964
2019
  return {
1965
2020
  resolved: {
1966
2021
  channels,
2022
+ ...(Object.keys(byChannel).length ? { byChannel } : {}),
2023
+ ...(openOnInvite.length ? { openOnInvite } : {}),
1967
2024
  origins,
1968
2025
  ...(botCheck === undefined ? {} : { botCheck }),
1969
2026
  ...(options.confirmations === true ? { confirmations: true } : {}),
@@ -2053,7 +2110,7 @@ function usesMe(value) {
2053
2110
  function checkGuestPermissions(input) {
2054
2111
  const { entities, guest, report } = input;
2055
2112
  const permissions = guest.permissions;
2056
- const path = "guest.permissions";
2113
+ const path = input.path ?? "guest.permissions";
2057
2114
  if (!Array.isArray(permissions)) {
2058
2115
  return;
2059
2116
  }
@@ -2177,7 +2234,7 @@ function checkSignUpAction(input) {
2177
2234
  const permissions = roles
2178
2235
  .filter((candidate) => (granted ?? []).includes(candidate.name))
2179
2236
  .flatMap((candidate) => (Array.isArray(candidate.permissions) ? candidate.permissions : []));
2180
- if (!isAllowed(found.permission, { permissions })) {
2237
+ if (!openingPermissions(found).some((permission) => isAllowed(permission, { permissions }))) {
2181
2238
  fail(`onSignUp must be runnable by the roles ${channel} sign-up grants.`);
2182
2239
  }
2183
2240
  }
@@ -2742,10 +2799,12 @@ function resolveActions(candidate, scope) {
2742
2799
  }
2743
2800
  }
2744
2801
  }
2802
+ const permissions = resolvePermissions(path, permissionOf(candidate.name, name), action, scope);
2745
2803
  actions.push({
2746
2804
  name,
2747
2805
  action,
2748
- permission: resolvePermission(path, permissionOf(candidate.name, name), action, scope),
2806
+ permission: permissions[0],
2807
+ ...(permissions.length > 1 ? { anyOf: permissions } : {}),
2749
2808
  input: resolveInput(path, action.input, scope),
2750
2809
  connections: resolveActionConnections(path, action, scope, scope.builtIns.has(candidate.definition)),
2751
2810
  hints: resolveHints(path, action, report),
@@ -2863,19 +2922,40 @@ function resolveHints(path, action, report) {
2863
2922
  return hints;
2864
2923
  }
2865
2924
  /** The action's own `permission`, which names an entity and a verb without wildcards. */
2866
- function resolvePermission(path, fallback, action, scope) {
2925
+ /**
2926
+ * The permissions that run an action: the one it requires, or, for a list, each of those any one of
2927
+ * which runs it, first to last without repeats. A list runs only an action that writes nothing
2928
+ * itself, a `prepare` without a handler, which checks inside what its input needs.
2929
+ */
2930
+ function resolvePermissions(path, fallback, action, scope) {
2867
2931
  const declared = action.permission;
2868
2932
  if (declared === undefined) {
2869
- return fallback;
2933
+ return [fallback];
2934
+ }
2935
+ if (!Array.isArray(declared)) {
2936
+ return [resolvePermission(`${path}.permission`, declared, fallback, scope)];
2937
+ }
2938
+ if (declared.length === 0) {
2939
+ scope.report("invalid-permission", `${path}.permission`, `name at least one permission, such as ${fallback}, or leave permission out.`);
2940
+ return [fallback];
2941
+ }
2942
+ if (declared.length > 1 && action.transactional) {
2943
+ scope.report("invalid-permission", `${path}.permission`, "several permissions open only an action that writes nothing itself, a prepare without a " +
2944
+ "handler: a scope cannot tell which of them a write is made under. Name one permission.");
2870
2945
  }
2946
+ return [
2947
+ ...new Set(declared.map((entry, index) => resolvePermission(`${path}.permission[${index}]`, entry, fallback, scope))),
2948
+ ];
2949
+ }
2950
+ function resolvePermission(path, declared, fallback, scope) {
2871
2951
  const parsed = parsePermission(declared);
2872
2952
  if (parsed === undefined || parsed.entity === WILDCARD || parsed.verb === WILDCARD) {
2873
- scope.report("invalid-permission", `${path}.permission`, `${JSON.stringify(declared)} is not a permission an action can require; ` +
2953
+ scope.report("invalid-permission", path, `${JSON.stringify(declared)} is not a permission an action can require; ` +
2874
2954
  `write <entity>:<verb> without wildcards, such as ${fallback}.`);
2875
2955
  return fallback;
2876
2956
  }
2877
2957
  if (!scope.entitiesByName.has(parsed.entity)) {
2878
- scope.report("unknown-permission", `${path}.permission`, `${parsed.entity} is not an entity of this ontology.`);
2958
+ scope.report("unknown-permission", path, `${parsed.entity} is not an entity of this ontology.`);
2879
2959
  }
2880
2960
  return permissionOf(parsed.entity, parsed.verb);
2881
2961
  }
@@ -3090,7 +3170,7 @@ function knownVerbs(entities, toolsets = []) {
3090
3170
  verbs.set(candidate.name, own);
3091
3171
  }
3092
3172
  for (const candidate of entities) {
3093
- for (const { permission } of candidate.actions) {
3173
+ for (const permission of candidate.actions.flatMap(openingPermissions)) {
3094
3174
  const parsed = parsePermission(permission);
3095
3175
  if (parsed !== undefined) {
3096
3176
  verbs.get(parsed.entity)?.add(parsed.verb);
@@ -3304,7 +3384,7 @@ function checkNewUserAction(input) {
3304
3384
  fail("onNewUser runs with the built-in member, which only defineOntology({ member }) " +
3305
3385
  "declares; use signUp and onSignUp.");
3306
3386
  }
3307
- else if (!isAllowed(found.permission, { permissions: member.permissions ?? [] })) {
3387
+ else if (!openingPermissions(found).some((permission) => isAllowed(permission, { permissions: member.permissions ?? [] }))) {
3308
3388
  fail("onNewUser must be runnable by member.");
3309
3389
  }
3310
3390
  if (found.action.hints?.idempotent !== true) {
@@ -3376,12 +3456,16 @@ function checkPermissions(entities, roles, workflows, report, authoredRoles = ro
3376
3456
  }));
3377
3457
  // Built-in actions are granted by the workspace's roles when it wants them.
3378
3458
  for (const candidate of entities.filter((entity) => !entity.builtIn)) {
3379
- for (const { name, permission } of candidate.actions) {
3380
- const parsed = parsePermission(permission);
3459
+ for (const action of candidate.actions) {
3460
+ const permissions = openingPermissions(action);
3381
3461
  // An invalid name or permission is already an error; it needs no warning on top.
3382
- const checkable = parsed !== undefined && verbs.has(parsed.entity);
3383
- if (checkable && rolesGranting(granting, permission).length === 0) {
3384
- report("unreachable-action", `${candidate.name}.actions.${name}`, `no role grants ${permission}, so nobody can run this action; ` +
3462
+ const checkable = permissions.every((permission) => {
3463
+ const parsed = parsePermission(permission);
3464
+ return parsed !== undefined && verbs.has(parsed.entity);
3465
+ });
3466
+ if (checkable &&
3467
+ permissions.every((permission) => rolesGranting(granting, permission).length === 0)) {
3468
+ report("unreachable-action", `${candidate.name}.actions.${action.name}`, `no role grants ${permissions.join(" or ")}, so nobody can run this action; ` +
3385
3469
  "add it to the permissions of a role that may run it.", "warning");
3386
3470
  }
3387
3471
  }
@@ -3622,6 +3706,10 @@ function scopeWhere(walk, entityName, where, path, anyRecord = false) {
3622
3706
  return result;
3623
3707
  }
3624
3708
  /** Whether an authored action cannot carry a scope: it writes nothing a scope could check. */
3709
+ /** The permissions any one of which runs an action: its one permission, or each it names. */
3710
+ function openingPermissions(action) {
3711
+ return action.anyOf ?? [action.permission];
3712
+ }
3625
3713
  function writesNothing(candidate) {
3626
3714
  return (candidate.hints?.readOnly === true ||
3627
3715
  (candidate.action.prepare !== undefined && candidate.action.transactional === false));
@@ -3686,7 +3774,7 @@ function checkScope(input) {
3686
3774
  }
3687
3775
  const unscopable = entities
3688
3776
  .flatMap((candidate) => candidate.actions.map((action) => ({ entity: candidate.name, action })))
3689
- .find(({ action }) => action.permission === permission && writesNothing(action));
3777
+ .find(({ action }) => openingPermissions(action).includes(permission) && writesNothing(action));
3690
3778
  if (unscopable !== undefined) {
3691
3779
  report("invalid-scope", path, `${permission} runs ${unscopable.entity}.${unscopable.action.name}, a readOnly or ` +
3692
3780
  "prepare-only action that writes nothing a scope could check; list it as a string, or " +
package/dist/authoring.js CHANGED
@@ -214,7 +214,13 @@ class AuthoringEncoder {
214
214
  const normalized = {
215
215
  ...value,
216
216
  input,
217
- permission: value.permission === undefined ? undefined : permissionToWire(value.permission),
217
+ permission: value.permission === undefined
218
+ ? undefined
219
+ : typeof value.permission === "string"
220
+ ? permissionToWire(value.permission)
221
+ : Array.isArray(value.permission)
222
+ ? value.permission.map((permission) => permissionToWire(permission))
223
+ : value.permission,
218
224
  };
219
225
  if (typeof value.handler === "function") {
220
226
  normalized.handler = (context) => value.handler({ ...context, principal: principalFromWire(context.principal) });
package/dist/chat.d.ts CHANGED
@@ -36,6 +36,10 @@ export interface InboxOptions<R = unknown> {
36
36
  }
37
37
  import { Context, Effect, Schema } from "effect";
38
38
  import type { ActionError } from "./errors.js";
39
+ /**
40
+ * A text post in the caller's own voice, signed with their name, as `agent_chat.previewMessage`
41
+ * renders it: what `agent_chat.send` takes with `as: "me"`, without a template or buttons.
42
+ */
39
43
  export declare const ChatPostInput: Schema.Struct<{
40
44
  readonly chat: Schema.String;
41
45
  readonly text: Schema.String;
@@ -102,7 +106,17 @@ export declare const ChatButtonRows: Schema.$Array<Schema.$Array<Schema.Union<re
102
106
  readonly token: Schema.String;
103
107
  }>]>>>;
104
108
  export type ChatButtonRows = typeof ChatButtonRows.Type;
105
- /** What `agent_chat.send` takes: a post's text, or on WhatsApp an approved template instead. */
109
+ /**
110
+ * Whose voice `agent_chat.send` writes in: `agent`, the default, as the agent, without attribution,
111
+ * under `agent_chat:send`; or `me`, as the caller, signed with their name as the workspace's
112
+ * `chat.attribution` lays it out, under `agent_chat:post_message`. Input never names another sender.
113
+ */
114
+ export declare const ChatVoice: Schema.Literals<readonly ["agent", "me"]>;
115
+ export type ChatVoice = typeof ChatVoice.Type;
116
+ /**
117
+ * What `agent_chat.send` takes: a message's text, or on WhatsApp an approved template instead, in
118
+ * the voice `as` names.
119
+ */
106
120
  export declare const ChatSendInput: Schema.Struct<{
107
121
  readonly chat: Schema.String;
108
122
  readonly text: Schema.optionalKey<Schema.String>;
@@ -132,6 +146,12 @@ export declare const ChatSendInput: Schema.Struct<{
132
146
  readonly text: Schema.String;
133
147
  readonly token: Schema.String;
134
148
  }>]>>>>;
149
+ readonly files: Schema.optionalKey<Schema.$Array<Schema.Struct<{
150
+ readonly entity: Schema.String;
151
+ readonly id: Schema.String;
152
+ readonly property: Schema.optionalKey<Schema.String>;
153
+ }>>>;
154
+ readonly as: Schema.optionalKey<Schema.Literals<readonly ["agent", "me"]>>;
135
155
  readonly idempotencyKey: Schema.String;
136
156
  }>;
137
157
  export type ChatSendInput = typeof ChatSendInput.Type;
@@ -282,10 +302,19 @@ export interface ChatDraftResult {
282
302
  readonly message: string;
283
303
  }
284
304
  declare const ChatDelivery_base: Context.ServiceClass<ChatDelivery, "@segmentstream/ontology/ChatDelivery", {
305
+ /** Renders a text post in the caller's voice, as `send` with `as: "me"` delivers it. */
285
306
  readonly preview: (input: ChatPostInput) => Effect.Effect<ChatPreview, ActionError>;
286
- readonly validate: (input: ChatPostInput) => Effect.Effect<void, ActionError>;
307
+ /** Checks a message as `send` would, in the voice `as` names, without reserving or sending. */
308
+ readonly validate: (input: ChatSendInput) => Effect.Effect<void, ActionError>;
309
+ /**
310
+ * `send` with `as: "me"`, which the earlier name `agent_chat.postMessage` calls.
311
+ * @legacy ontology.chat-post-message
312
+ */
287
313
  readonly post: (input: ChatPostInput) => Effect.Effect<ChatPostResult, ActionError>;
288
- /** Sends as the agent, without the requester's attribution, which the archive still keeps. */
314
+ /**
315
+ * Sends in the voice `as` names: as the agent, by default, without the requester's
316
+ * attribution, which the archive still keeps; or, with `as: "me"`, signed as the requester.
317
+ */
289
318
  readonly send?: (input: ChatSendInput) => Effect.Effect<ChatPostResult, ActionError>;
290
319
  /** Sends a reply a member approved, as the agent and without attribution, at most once. */
291
320
  readonly sendReview?: (input: ReviewSendInput) => Effect.Effect<ReviewSendResult, ActionError>;
package/dist/chat.js CHANGED
@@ -3,22 +3,28 @@ import { Context, Schema } from "effect";
3
3
  import { BLOB_UPLOAD_ANNOTATION, BlobUpload } from "./blob.js";
4
4
  import { CHAT_FILES } from "./files.js";
5
5
  const Identifier = Schema.String.check(Schema.isMinLength(1), Schema.isMaxLength(512));
6
+ /** Stored files a message carries after its text, each a record and its file property. */
7
+ const ChatMessageFiles = Schema.Array(Schema.Struct({
8
+ entity: Identifier,
9
+ id: Identifier,
10
+ property: Schema.optionalKey(Identifier),
11
+ }))
12
+ .check(Schema.isMinLength(1), Schema.isMaxLength(10))
13
+ .annotate({
14
+ description: "Stored files the message carries after its text, each a record and its file property, " +
15
+ "which the caller may read: content by default. Each is sent at the revision read now.",
16
+ });
17
+ /**
18
+ * A text post in the caller's own voice, signed with their name, as `agent_chat.previewMessage`
19
+ * renders it: what `agent_chat.send` takes with `as: "me"`, without a template or buttons.
20
+ */
6
21
  export const ChatPostInput = Schema.Struct({
7
22
  chat: Identifier,
8
23
  text: Schema.String.check(Schema.isMinLength(1), Schema.isMaxLength(4096)).annotate({
9
24
  description: "Markdown source; the platform adds sender attribution after channel rendering.",
10
25
  }),
11
26
  replyTo: Schema.optionalKey(Identifier),
12
- files: Schema.optionalKey(Schema.Array(Schema.Struct({
13
- entity: Identifier,
14
- id: Identifier,
15
- property: Schema.optionalKey(Identifier),
16
- }))
17
- .check(Schema.isMinLength(1), Schema.isMaxLength(10))
18
- .annotate({
19
- description: "Stored files the post carries after its text, each a record and its file property, " +
20
- "which the caller may read: content by default. Each is sent at the revision read now.",
21
- })),
27
+ files: Schema.optionalKey(ChatMessageFiles),
22
28
  idempotencyKey: Identifier,
23
29
  });
24
30
  /** The file of a template's image, video or document header, where it is stored or served. */
@@ -98,11 +104,21 @@ export const ChatButton = Schema.Union([
98
104
  ]);
99
105
  /** A message's buttons by row, as the person sees them; each channel lays them out its own way. */
100
106
  export const ChatButtonRows = Schema.Array(Schema.Array(ChatButton).check(Schema.isMinLength(1), Schema.isMaxLength(8))).check(Schema.isMinLength(1), Schema.isMaxLength(10));
101
- /** What `agent_chat.send` takes: a post's text, or on WhatsApp an approved template instead. */
107
+ /**
108
+ * Whose voice `agent_chat.send` writes in: `agent`, the default, as the agent, without attribution,
109
+ * under `agent_chat:send`; or `me`, as the caller, signed with their name as the workspace's
110
+ * `chat.attribution` lays it out, under `agent_chat:post_message`. Input never names another sender.
111
+ */
112
+ export const ChatVoice = Schema.Literals(["agent", "me"]);
113
+ /**
114
+ * What `agent_chat.send` takes: a message's text, or on WhatsApp an approved template instead, in
115
+ * the voice `as` names.
116
+ */
102
117
  export const ChatSendInput = Schema.Struct({
103
118
  chat: Identifier,
104
119
  text: Schema.optionalKey(Schema.String.check(Schema.isMinLength(1), Schema.isMaxLength(4096)).annotate({
105
- description: "Markdown source, sent as the agent's without attribution.",
120
+ description: "Markdown source, which each channel renders natively; with as me, the platform adds " +
121
+ "the sender attribution after it.",
106
122
  })),
107
123
  template: Schema.optionalKey(ChatTemplate.annotate({
108
124
  description: "On WhatsApp, an approved template in place of text: it reaches a person who last wrote " +
@@ -113,6 +129,11 @@ export const ChatSendInput = Schema.Struct({
113
129
  description: "Buttons under the text, by row: links, and workspace buttons whose press calls the " +
114
130
  "workspace's button action. A channel that cannot show them as given refuses the message.",
115
131
  })),
132
+ files: Schema.optionalKey(ChatMessageFiles),
133
+ as: Schema.optionalKey(ChatVoice.annotate({
134
+ description: "Whose voice the message is in: agent, the default, as the agent, without attribution, " +
135
+ "under agent_chat:send; me, as you, signed with your name, under agent_chat:post_message.",
136
+ })),
116
137
  idempotencyKey: Identifier,
117
138
  });
118
139
  export const ChatPostResult = Schema.Struct({
package/dist/index.d.ts CHANGED
@@ -19,7 +19,7 @@ export { Diagnostic, DIAGNOSTIC_CODES, formatDiagnostics, InvalidOntology } from
19
19
  export type { DiagnosticCode } from "./diagnostics.js";
20
20
  export { entity, isEntity } from "./entity.js";
21
21
  export { isToolset, MCP_TOOL_NAME, TOOLSET_LOCK_VERSION, toolset, ToolsetLock, ToolsetLockTool, } from "./toolset.js";
22
- export type { FixedValue, ResolvedTool, ResolvedToolset, Toolset, ToolsetDefinition, ToolsetToolOptions, } from "./toolset.js";
22
+ export type { FixedValue, ResolvedTool, ResolvedToolset, Toolset, ToolsetDefinition, ToolsetToolOptions, ToolInvocation, ToolHandler, } from "./toolset.js";
23
23
  export type { ActionsBuilder, AnyEntity, ActionHandle, ActionInvoker, MetricQueryGroupKey, AnyStoredEntity, BatchCreateValues, BatchKey, BatchUpdateRecord, BatchUpdateValues, BatchUpsertValues, CreateValues, DraftEntity, Entity, EntityDefinition, EntityRecord, EntityWrites, FreshMetricQueryInput, FreshMetricQueryRow, IndexDefinition, IndexField, InvocableActions, NoActions, Properties, RecordRef, Relationships, SystemFields, UpdateValues, } from "./entity.js";
24
24
  export { ActionRejected, BatchErrorDetails, Conflict, DeploymentInterrupted, DeploymentSwitching, LimitErrorDetails, NotFound, PermissionDenied, ScopeViolated, } from "./errors.js";
25
25
  export type { ActionError } from "./errors.js";