@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
@@ -69,22 +69,26 @@ chats) {
69
69
  const destinationPreviews = previews.settings?.connection === destination ? previews : { ownOrigins: previews.ownOrigins };
70
70
  return (context) => {
71
71
  /**
72
- * A post's destination, requester and exact text. `asAgent` sends it as the agent, without the
73
- * sender attribution, under `agent_chat:send`; the requester is still recorded with it.
72
+ * A message's destination, requester and exact text, in the voice `as` names: as the agent, by
73
+ * default, without the sender attribution, under `agent_chat:send`, the requester still
74
+ * recorded with it; or, with `as: "me"`, signed as the requester, under
75
+ * `agent_chat:post_message`. The voice's own permission is checked here, whichever of the two
76
+ * opened the action.
74
77
  */
75
- const check = (input, approved = true, asAgent = false) => Effect.gen(function* () {
76
- const template = "template" in input ? input.template : undefined;
77
- const buttons = "buttons" in input ? input.buttons : undefined;
78
- // A message is text, or on WhatsApp a template the agent sends; a post is always text.
79
- if ((input.text === undefined) === (template === undefined) || (template && !asAgent)) {
78
+ const check = (input, approved = true) => Effect.gen(function* () {
79
+ const asAgent = input.as !== "me";
80
+ const template = input.template;
81
+ const buttons = input.buttons;
82
+ // A message is text, or on WhatsApp an approved template.
83
+ if ((input.text === undefined) === (template === undefined)) {
80
84
  return yield* new ActionRejected({
81
85
  message: "Give exactly one of text and template.",
82
86
  });
83
87
  }
84
88
  // An approved template has its own buttons, given by their values.
85
- if (buttons !== undefined && (template !== undefined || !asAgent)) {
89
+ if (buttons !== undefined && template !== undefined) {
86
90
  return yield* new ActionRejected({
87
- message: "Buttons go under a text the agent sends; a template's are its own.",
91
+ message: "Buttons go under a text; a template's are its own.",
88
92
  });
89
93
  }
90
94
  const permission = asAgent ? "agent_chat:send" : "agent_chat:post_message";
@@ -101,6 +105,14 @@ chats) {
101
105
  message: "The agent's sessions do not send as the agent: they answer in their chats.",
102
106
  });
103
107
  }
108
+ // A session posts for its member only the exact text they approved in their chat, whose
109
+ // frozen preview binds no template, buttons or files.
110
+ if (context.caller.kind === "runtime" &&
111
+ (template !== undefined || buttons !== undefined || input.files !== undefined)) {
112
+ return yield* new ActionRejected({
113
+ message: "The agent's sessions post only the text a member approved, as written.",
114
+ });
115
+ }
104
116
  const user = yield* context.backend.get({ entity: "user", id: context.principal.id });
105
117
  if (user.active !== true || user.kind !== context.principal.kind) {
106
118
  return yield* new PermissionDenied({ message: "The requester is inactive." });
@@ -205,6 +217,16 @@ chats) {
205
217
  message: "Templates are sent on WhatsApp; this chat's channel takes text.",
206
218
  });
207
219
  }
220
+ // WhatsApp sends an approved template's text as it is: nothing can sign it. In the
221
+ // caller's voice it goes only where their post carries no name, as a member's own reply
222
+ // in the inbox does where the inbox's `attribution` is `none`.
223
+ if (signature !== "") {
224
+ return yield* new ActionRejected({
225
+ message: "A template cannot carry the sender attribution; nothing was sent. Send it as " +
226
+ "the agent, or as text.",
227
+ refusal: "attribution_unsupported",
228
+ });
229
+ }
208
230
  const read = provider.template;
209
231
  const request = {
210
232
  name: template.name,
@@ -574,15 +596,17 @@ chats) {
574
596
  identityToken: context.identityToken,
575
597
  requestId: context.requestId,
576
598
  }),
577
- preview: (input) => check(input, false).pipe(Effect.flatMap(({ compose }) => compose), Effect.map(({ preview }) => preview)),
599
+ preview: (input) => check({ ...input, as: "me" }, false).pipe(Effect.flatMap(({ compose }) => compose), Effect.map(({ preview }) => preview)),
578
600
  validate: (input) => check(input).pipe(Effect.asVoid),
579
- post: (input) => deliver(input, false),
580
- send: (input) => deliver(input, true),
601
+ // @legacy ontology.chat-post-message
602
+ post: (input) => deliver({ ...input, as: "me" }),
603
+ send: (input) => deliver(input),
581
604
  };
582
- /** One delivery: posted with its requester's attribution, or sent as the agent without it. */
583
- function deliver(input, asAgent) {
605
+ /** One delivery: as the agent without attribution, or with `as: "me"` signed as the caller. */
606
+ function deliver(input) {
584
607
  return Effect.gen(function* () {
585
- const checked = yield* check(input, true, asAgent);
608
+ const asAgent = input.as !== "me";
609
+ const checked = yield* check(input);
586
610
  const { target, requester, connection, provider, inbox, compose } = checked;
587
611
  const buttons = "buttons" in checked ? checked.buttons : undefined;
588
612
  const scope = deliveryScopeDigest({
@@ -626,13 +650,12 @@ chats) {
626
650
  });
627
651
  // A post's stored files, as the caller names them. The key binds those names: a retry after
628
652
  // a file changed or went recovers the first attempt's receipt, read before the files are.
629
- const named = "files" in input && input.files !== undefined ? input.files : [];
653
+ const named = input.files ?? [];
630
654
  const references = named.map((file) => [file.entity, file.id.toLowerCase(), file.property ?? "content", ""]);
631
655
  const fingerprint = references.length === 0 || !("preview" in checked) || checked.preview === undefined
632
656
  ? checked.fingerprint
633
657
  : deliveryFingerprint(checked.preview, requester, undefined, buttons, undefined, references);
634
- if (named.length > 0 &&
635
- (("template" in input && input.template !== undefined) || archive === cloud)) {
658
+ if (named.length > 0 && (input.template !== undefined || archive === cloud)) {
636
659
  // @legacy agent.cloud-chat-archive Files go only through the workspace chat store.
637
660
  return yield* new ActionRejected({
638
661
  message: "The post's files cannot be sent (files_unsupported); nothing was sent.",
@@ -642,9 +665,7 @@ chats) {
642
665
  // A message read when it is sent, a template, its files, or the people of a shared
643
666
  // thread's reply, may read differently by the time its key is replayed, or not at all: a
644
667
  // replay recovers the first attempt's receipt before it.
645
- if ((("template" in input && input.template !== undefined) ||
646
- named.length > 0 ||
647
- inbox?.shared === true) &&
668
+ if ((input.template !== undefined || named.length > 0 || inbox?.shared === true) &&
648
669
  archive.find !== undefined) {
649
670
  const found = yield* archive
650
671
  .find({ delivery: { scope, key, fingerprint }, identityToken: context.identityToken })
@@ -692,7 +713,7 @@ chats) {
692
713
  const transport = connections({
693
714
  identityToken: context.identityToken,
694
715
  audit: {
695
- action: asAgent ? "agent_chat.send" : "agent_chat.post_message",
716
+ action: "agent_chat.send",
696
717
  principalId: context.principal.id,
697
718
  requestId: context.requestId,
698
719
  },
@@ -60,6 +60,9 @@ declare const CurrentChatCall_base: Context.ServiceClass<CurrentChatCall, "@segm
60
60
  } | undefined;
61
61
  readonly channel?: string | undefined;
62
62
  readonly message_id?: string | undefined;
63
+ readonly reply_to_message_id?: string | undefined;
64
+ readonly callback_query_id?: string | undefined;
65
+ readonly sender?: string | undefined;
63
66
  readonly attachments?: readonly {
64
67
  readonly kind: "photo" | "document" | "voice" | "audio" | "video" | "video_note" | "sticker" | "animation";
65
68
  readonly file_id: string;
@@ -67,11 +70,8 @@ declare const CurrentChatCall_base: Context.ServiceClass<CurrentChatCall, "@segm
67
70
  readonly file_unique_id?: string | undefined;
68
71
  readonly media_type?: string | undefined;
69
72
  }[] | undefined;
70
- readonly reply_to_message_id?: string | undefined;
71
- readonly callback_query_id?: string | undefined;
72
- readonly sender?: string | undefined;
73
73
  } | {
74
- readonly kind: "private" | "group";
74
+ readonly kind: "group" | "private";
75
75
  readonly provider: "slack" | "whatsapp";
76
76
  readonly chat_id: string;
77
77
  readonly thread_id: string;
@@ -114,6 +114,9 @@ export declare function consumeChatEnvelope(args: Readonly<Record<string, unknow
114
114
  } | undefined;
115
115
  readonly channel?: string | undefined;
116
116
  readonly message_id?: string | undefined;
117
+ readonly reply_to_message_id?: string | undefined;
118
+ readonly callback_query_id?: string | undefined;
119
+ readonly sender?: string | undefined;
117
120
  readonly attachments?: readonly {
118
121
  readonly kind: "photo" | "document" | "voice" | "audio" | "video" | "video_note" | "sticker" | "animation";
119
122
  readonly file_id: string;
@@ -121,11 +124,8 @@ export declare function consumeChatEnvelope(args: Readonly<Record<string, unknow
121
124
  readonly file_unique_id?: string | undefined;
122
125
  readonly media_type?: string | undefined;
123
126
  }[] | undefined;
124
- readonly reply_to_message_id?: string | undefined;
125
- readonly callback_query_id?: string | undefined;
126
- readonly sender?: string | undefined;
127
127
  } | {
128
- readonly kind: "private" | "group";
128
+ readonly kind: "group" | "private";
129
129
  readonly provider: "slack" | "whatsapp";
130
130
  readonly chat_id: string;
131
131
  readonly thread_id: string;
@@ -12,13 +12,13 @@ export declare function chatMessageEvent(message: ChatMessage): {
12
12
  eventId: string;
13
13
  provider: string;
14
14
  chatId: string;
15
- chatType: "channel" | "private" | "group";
15
+ chatType: "channel" | "group" | "private";
16
16
  threadId: string | null;
17
17
  participantIds: readonly string[];
18
18
  senderId: string | null;
19
19
  senderName: string | null;
20
20
  senderIsBot: boolean;
21
- kind: "inbound" | "outbound" | "internal";
21
+ kind: "outbound" | "inbound" | "internal";
22
22
  messageId: string | null;
23
23
  replyToMessageId: string | null;
24
24
  sessionId: string | null;
@@ -42,8 +42,8 @@ export declare function chatMessageEvent(message: ChatMessage): {
42
42
  sequence: string;
43
43
  storedAt: string;
44
44
  id: string;
45
- direction: "inbound" | "outbound" | "internal";
46
- author: "agent" | "human" | "bot";
45
+ direction: "outbound" | "inbound" | "internal";
46
+ author: "agent" | "bot" | "human";
47
47
  sender: {
48
48
  id: string | null;
49
49
  name: string | null;
@@ -59,7 +59,7 @@ export declare function chatMessageEvent(message: ChatMessage): {
59
59
  edited: boolean;
60
60
  deleted: boolean;
61
61
  delivery: "pending" | "read" | "sent" | "failed" | "uncertain" | "delivered" | null;
62
- disposition: "skipped" | "claimed" | "turn" | null;
62
+ disposition: "claimed" | "turn" | "skipped" | null;
63
63
  replaced_by: string | null;
64
64
  };
65
65
  /**
@@ -28,6 +28,8 @@ export function chatRoutes(options) {
28
28
  });
29
29
  const operations = makeOperations(backend, options.built.plan, options.hooks, options.connections, options.replicate, options.chatDelivery);
30
30
  const planned = options.built.plan.entities.find((entity) => entity.name === "agent_chat");
31
+ // @legacy ontology.chat-post-message `chat/actions/post_message`, send as me by its earlier
32
+ // name: `agent_chat/actions/send` serves every message.
31
33
  const action = planned.actions.find((candidate) => candidate.name === "post_message");
32
34
  for (const method of ["list", "history", "search", "actions/post_message"]) {
33
35
  yield* router.add("POST", `/api/ontology/chat/${method}`, (request) => Effect.gen(function* () {
@@ -1,4 +1,44 @@
1
1
  import { Schema } from "effect";
2
+ export declare const ChatSendWire: Schema.encodeKeys<Schema.Struct<{
3
+ readonly chat: Schema.String;
4
+ readonly text: Schema.optionalKey<Schema.String>;
5
+ readonly template: Schema.optionalKey<Schema.Struct<{
6
+ readonly name: Schema.String;
7
+ readonly language: Schema.String;
8
+ readonly parameters: Schema.optionalKey<Schema.$Record<Schema.String, Schema.String>>;
9
+ readonly header: Schema.optionalKey<Schema.Struct<{
10
+ readonly parameters: Schema.optionalKey<Schema.$Record<Schema.String, Schema.String>>;
11
+ readonly media: Schema.optionalKey<Schema.Struct<{
12
+ readonly url: Schema.optionalKey<Schema.String>;
13
+ readonly file: Schema.optionalKey<Schema.Struct<{
14
+ readonly entity: Schema.String;
15
+ readonly id: Schema.String;
16
+ readonly property: Schema.optionalKey<Schema.String>;
17
+ }>>;
18
+ readonly filename: Schema.optionalKey<Schema.String>;
19
+ }>>;
20
+ }>>;
21
+ readonly buttons: Schema.optionalKey<Schema.$Record<Schema.String, Schema.String>>;
22
+ }>>;
23
+ readonly replyTo: Schema.optionalKey<Schema.String>;
24
+ readonly buttons: Schema.optionalKey<Schema.$Array<Schema.$Array<Schema.Union<readonly [Schema.Struct<{
25
+ readonly text: Schema.String;
26
+ readonly url: Schema.String;
27
+ }>, Schema.Struct<{
28
+ readonly text: Schema.String;
29
+ readonly token: Schema.String;
30
+ }>]>>>>;
31
+ readonly files: Schema.optionalKey<Schema.$Array<Schema.Struct<{
32
+ readonly entity: Schema.String;
33
+ readonly id: Schema.String;
34
+ readonly property: Schema.optionalKey<Schema.String>;
35
+ }>>>;
36
+ readonly as: Schema.optionalKey<Schema.Literals<readonly ["agent", "me"]>>;
37
+ readonly idempotencyKey: Schema.String;
38
+ }>, {
39
+ readonly replyTo: "reply_to";
40
+ readonly idempotencyKey: "idempotency_key";
41
+ }>;
2
42
  export declare const ChatPostWire: Schema.encodeKeys<Schema.Struct<{
3
43
  readonly chat: Schema.String;
4
44
  readonly text: Schema.String;
@@ -1,7 +1,9 @@
1
1
  import { Schema } from "effect";
2
- import { ChatPostInput } from "../../chat.js";
2
+ import { ChatPostInput, ChatSendInput } from "../../chat.js";
3
3
  import { CHAT_KINDS } from "../../chat-channel.js";
4
4
  const Id = Schema.String.check(Schema.isMinLength(1), Schema.isMaxLength(512));
5
+ export const ChatSendWire = ChatSendInput.pipe(Schema.encodeKeys({ replyTo: "reply_to", idempotencyKey: "idempotency_key" }));
6
+ // @legacy ontology.chat-post-message The input of post_message, the earlier name of send as me.
5
7
  export const ChatPostWire = ChatPostInput.pipe(Schema.encodeKeys({ replyTo: "reply_to", idempotencyKey: "idempotency_key" }));
6
8
  export const RuntimeChatPostWire = Schema.Struct({
7
9
  chat: ChatPostInput.fields.chat,
@@ -22,8 +22,8 @@ export declare function searchDocuments(documents: ReadonlyArray<SearchDocument>
22
22
  }[];
23
23
  readonly summary_truncated: boolean;
24
24
  readonly entity?: string | undefined;
25
- readonly tools?: readonly string[] | undefined;
26
25
  readonly metrics?: readonly string[] | undefined;
26
+ readonly tools?: readonly string[] | undefined;
27
27
  readonly relevance?: number | undefined;
28
28
  }[];
29
29
  /** Bytewise canonical-name ordering is independent of a function instance's locale. */
@@ -482,6 +482,8 @@ function runTool(server, tool, args, request, preview) {
482
482
  };
483
483
  }
484
484
  case "action": {
485
+ // @legacy ontology.chat-post-message chat_post_message, send as me by its earlier name,
486
+ // answers the flat receipt, and is the tool through which the agent's sessions post.
485
487
  if (target.planned.name === "agent_chat" && target.action.name === "post_message") {
486
488
  yield* decodeArguments(caller.kind === "runtime" ? RuntimeChatPostWire : ChatPostWire, args);
487
489
  const answer = yield* operations.runAction(target.planned, target.action, {
@@ -57,8 +57,13 @@ export interface McpTool {
57
57
  /** The JSON Schema of the tool's `structuredContent`, for the tools that return a known shape. */
58
58
  readonly outputSchema?: JsonSchemaObject;
59
59
  readonly annotations: McpToolAnnotations;
60
- /** Every permission a caller needs to see and run the tool; none for the global tools. */
60
+ /**
61
+ * Every permission a caller needs to see and run the tool, or, with `anyPermission`, one of them;
62
+ * none for the global tools.
63
+ */
61
64
  readonly permissions: ReadonlyArray<string>;
65
+ /** Any one of `permissions` opens the tool: an action several permissions open. */
66
+ readonly anyPermission?: true;
62
67
  /**
63
68
  * For a tool whose input depends on what the caller may read: the caller's input schema, or
64
69
  * `undefined` when the tool can do nothing for them and is not listed. Calls are checked anyway.
@@ -83,7 +88,10 @@ export declare function encodedJsonSchema(schema: Schema.Top): JsonSchemaObject;
83
88
  export declare const ACTION_OPTIONS_ARGUMENT = "_options";
84
89
  /** The `me` tool's marker: tool calls accept the runtime envelope's chat source. */
85
90
  export declare const RUNTIME_SOURCE_META = "segmentstream/runtime-source";
86
- /** The `chat_post_message` tool's marker: the deployment posts exact messages to its chat. */
91
+ /**
92
+ * The `chat_post_message` tool's marker: the deployment posts exact messages to its chat.
93
+ * @legacy ontology.chat-post-message
94
+ */
87
95
  export declare const CHAT_POST_META = "segmentstream/chat-post";
88
96
  /**
89
97
  * The MCP tools of an ontology: `me`, `discover` when it ranks by meaning, opt-in `navigation`,
@@ -2,7 +2,7 @@ import { Schema } from "effect";
2
2
  import { METRIC_QUERY_NAME_PATTERN, isBuiltInUser } from "../../metric-routes.js";
3
3
  import { InvalidOntology } from "../../diagnostics.js";
4
4
  import { GENERATED_UPSERT_PREFIX, humanize, mcpToolName } from "../../names.js";
5
- import { effectivePermissions, isAllowed, permissionOf, READ_VERB, } from "../../permissions.js";
5
+ import { allowsAction, effectivePermissions, isAllowed, permissionOf, READ_VERB, } from "../../permissions.js";
6
6
  import { FIND_CONDITIONS, findToolInput } from "./find-input.js";
7
7
  import { metricDescription, metricsFor, modelMetricDescription, modelMetricsFor, reachesOf, RECORDS_OR_METRIC_QUERIES, } from "../../render.js";
8
8
  import { actionInputJsonSchema } from "../../runtime/generated-actions.js";
@@ -267,7 +267,10 @@ function readTools(planned, schemas, built) {
267
267
  export const ACTION_OPTIONS_ARGUMENT = "_options";
268
268
  /** The `me` tool's marker: tool calls accept the runtime envelope's chat source. */
269
269
  export const RUNTIME_SOURCE_META = "segmentstream/runtime-source";
270
- /** The `chat_post_message` tool's marker: the deployment posts exact messages to its chat. */
270
+ /**
271
+ * The `chat_post_message` tool's marker: the deployment posts exact messages to its chat.
272
+ * @legacy ontology.chat-post-message
273
+ */
271
274
  export const CHAT_POST_META = "segmentstream/chat-post";
272
275
  const ACTION_OPTIONS_SCHEMA = {
273
276
  type: "object",
@@ -299,7 +302,7 @@ function actionToolInput(action) {
299
302
  };
300
303
  }
301
304
  function actionTool(planned, plannedAction) {
302
- const { name, action, permissions } = plannedAction;
305
+ const { name, action, permissions, anyPermission } = plannedAction;
303
306
  const hints = hintsOf(planned, plannedAction);
304
307
  return {
305
308
  name: mcpToolName(planned.name, name),
@@ -314,6 +317,7 @@ function actionTool(planned, plannedAction) {
314
317
  openWorldHint: action.connections.length > 0 && hints.connectionsReadOnly !== true,
315
318
  },
316
319
  permissions,
320
+ ...(anyPermission === undefined ? {} : { anyPermission }),
317
321
  target: { kind: "action", planned, action: plannedAction },
318
322
  };
319
323
  }
@@ -772,6 +776,7 @@ export function mcpTools(built, chatHistory = false, storage = {}, navigation =
772
776
  tools[discover] = { ...tools[discover], description: DISCOVER_BY_MEANING };
773
777
  }
774
778
  }
779
+ // @legacy ontology.chat-post-message chat_post_message, send as me by its earlier name.
775
780
  const post = tools.findIndex((tool) => tool.name === "chat_post_message");
776
781
  if (post >= 0) {
777
782
  const original = tools[post];
@@ -943,6 +948,7 @@ export function mcpTools(built, chatHistory = false, storage = {}, navigation =
943
948
  ...tool,
944
949
  inputSchema: withConfirmation(tool.inputSchema, tool.annotations),
945
950
  // Exact chat posting confirms its own preview of the destination and the posted text.
951
+ // @legacy ontology.chat-post-message
946
952
  ...(tool.target.kind === "action" &&
947
953
  tool.name !== "chat_post_message" &&
948
954
  needsConfirmation(tool.annotations)
@@ -980,7 +986,7 @@ export function visibleTools(tools, caller, provenance = { kind: "unverified" })
980
986
  if ((caller.kind === "guest" && USER_TOOL_TARGETS.has(tool.target.kind)) ||
981
987
  !runtimeAllows(provenance, tool) ||
982
988
  (tool.target.kind === "toolset" && isReadScoped(provenance)) ||
983
- !tool.permissions.every((required) => isAllowed(required, caller))) {
989
+ !allowsAction(tool, caller)) {
984
990
  return [];
985
991
  }
986
992
  const description = tool.descriptionFor?.(caller) ?? tool.description;
@@ -989,6 +995,7 @@ export function visibleTools(tools, caller, provenance = { kind: "unverified" })
989
995
  {
990
996
  ...tool,
991
997
  description,
998
+ // @legacy ontology.chat-post-message
992
999
  ...(tool.name === "chat_post_message" && provenance.kind === "runtime"
993
1000
  ? {
994
1001
  inputSchema: withConfirmation(encodedJsonSchema(RuntimeChatPostWire), tool.annotations),
@@ -14,7 +14,7 @@ import { requireRuntimeOperation } from "./mcp/runtime-policy.js";
14
14
  import { ChatDelivery } from "../chat.js";
15
15
  import { withoutConfirmation } from "./mcp/confirmation.js";
16
16
  import { consumeChatEnvelope, CurrentChatCall } from "./chat/envelope.js";
17
- import { ChatPostWire, RuntimeChatPostWire } from "./chat/schemas.js";
17
+ import { ChatPostWire, ChatSendWire, RuntimeChatPostWire } from "./chat/schemas.js";
18
18
  import { OIDC_TOKEN_HEADER } from "./connections.js";
19
19
  import { InvalidActionInput, RequestId } from "./errors.js";
20
20
  import { recordReads } from "./record-reads.js";
@@ -233,6 +233,7 @@ function runActionOf(backend, plan, hooks, connections, replicate, chatDelivery)
233
233
  "for a task whatever its workflow's role grants; the workflow sends what the task wrote.",
234
234
  });
235
235
  }
236
+ // @legacy ontology.chat-post-message The agent's sessions post through post_message alone.
236
237
  if (planned.name === "agent_chat" && name === "post_message" && caller.kind === "runtime") {
237
238
  const values = yield* Schema.decodeUnknownEffect(RuntimeChatPostWire)(consumed.input, {
238
239
  onExcessProperty: "error",
@@ -333,13 +334,16 @@ function runActionOf(backend, plan, hooks, connections, replicate, chatDelivery)
333
334
  const outcome = yield* delivery === undefined
334
335
  ? run
335
336
  : run.pipe(Effect.provideService(ChatDelivery, delivery));
337
+ // Validating a message checks its destination, sender and exact text, sending nothing.
336
338
  if (call.validateOnly &&
337
339
  outcome.validation.ok &&
338
340
  planned.name === "agent_chat" &&
339
- name === "post_message" &&
341
+ (name === "send" || name === "post_message") &&
340
342
  delivery) {
341
- const decoded = yield* Schema.decodeUnknownEffect(ChatPostWire)(input).pipe(Effect.mapError(() => new ActionRejected({ message: "Invalid exact chat post input." })));
342
- yield* delivery.validate(decoded);
343
+ const decoded = yield* Schema.decodeUnknownEffect(
344
+ // @legacy ontology.chat-post-message post_message, which posts as send with as me.
345
+ name === "send" ? ChatSendWire : ChatPostWire)(input).pipe(Effect.mapError(() => new ActionRejected({ message: "Invalid exact chat post input." })));
346
+ yield* delivery.validate(name === "send" ? decoded : { ...decoded, as: "me" });
343
347
  }
344
348
  const { issues } = outcome.validation;
345
349
  if (!outcome.validation.ok && !call.validateOnly) {
@@ -406,7 +410,8 @@ export function makeOperations(backend, plan, hooks, connections, replicate, cha
406
410
  /** Runs an action as the caller, with the action's after-commit hook and connections. */
407
411
  runAction: runActionOf(backend, plan, hooks, connections, replicate, chatDelivery),
408
412
  /** Calls a toolset's provider tool as the caller, through the toolset's connection. */
409
- runToolsetTool: runToolsetToolOf(connections),
413
+ runToolsetTool: runToolsetToolOf(connections, backend.agents?.web?.recordGuestUsage &&
414
+ ((guestId, costUsd, key) => backend.agents.web.recordGuestUsage({ guestId, costUsd, key }))),
410
415
  /** The caller's user, roles and permissions. It needs no permission. */
411
416
  caller: callerOf(backend, plan.ontology),
412
417
  };
@@ -31,8 +31,10 @@ export interface PlannedAction {
31
31
  readonly name: string;
32
32
  readonly action: AnyAction;
33
33
  readonly generated: boolean;
34
- /** Every permission a principal needs to run it. */
34
+ /** Every permission a principal needs to run it, or, with `anyPermission`, one of them. */
35
35
  readonly permissions: ReadonlyArray<string>;
36
+ /** Any one of `permissions` runs the action, which checks inside what its input needs. */
37
+ readonly anyPermission?: true;
36
38
  /** The entities an authored action declares it writes, by name; absent when it declares none. */
37
39
  readonly writes?: ReadonlyArray<string>;
38
40
  }
@@ -48,11 +48,13 @@ function plannedActions(resolved, generatedActions, report) {
48
48
  generated: true,
49
49
  permissions: generatedActionPermissions(resolved.name, name),
50
50
  }));
51
- const authored = resolved.actions.map(({ name, action, permission, writes }) => ({
51
+ const authored = resolved.actions.map(({ name, action, permission, anyOf, writes }) => ({
52
52
  name,
53
53
  action,
54
54
  generated: false,
55
- permissions: [permission],
55
+ ...(anyOf === undefined
56
+ ? { permissions: [permission] }
57
+ : { permissions: anyOf, anyPermission: true }),
56
58
  ...(writes === undefined ? {} : { writes }),
57
59
  }));
58
60
  const actions = [...generated, ...authored];
@@ -299,7 +299,7 @@ export interface AgentWebStore {
299
299
  * together, apart from the counters of people who signed up. `limits` are kept first, as for
300
300
  * {@link countTurn}. The limit the turn exceeds, or `undefined` when it may run.
301
301
  */
302
- readonly countGuestTurn?: (guestId: string, limits?: ResolveIdentityInput["limits"]) => Effect.Effect<WebTurnLimit | undefined>;
302
+ readonly countGuestTurn?: (guestId: string, limits?: ResolveIdentityInput["limits"], delivery?: string) => Effect.Effect<WebTurnLimit | undefined>;
303
303
  /**
304
304
  * Adds the model cost of a guest's turn, in US dollars, to that day's spend of the guest and of
305
305
  * every guest together, which {@link countGuestTurn} holds against the agent's
@@ -685,6 +685,8 @@ export interface AgentStore {
685
685
  * it has none. Concurrent calls for one chat leave one record.
686
686
  */
687
687
  readonly claimChatPersonaNotice?: (id: string, memberId: string) => Effect.Effect<boolean>;
688
+ /** Recheck the current chat and sender for every runtime guest tool call. */
689
+ readonly channelGuest?: (channel: string, chat: string, sender: string) => Effect.Effect<Principal | undefined>;
688
690
  readonly readGroupAccess?: (key: string) => Effect.Effect<string | null>;
689
691
  readonly readChatPersona?: (key: string) => Effect.Effect<string | null>;
690
692
  readonly seeChat: (input: {
@@ -114,6 +114,7 @@ export interface RuntimeCredential {
114
114
  readonly agentTask?: Redacted.Redacted<string>;
115
115
  /** The grant in `X-SegmentStream-Agent-Grant`; `undefined` without the header. */
116
116
  readonly grant?: string;
117
+ readonly sender?: string;
117
118
  /** The scope in `X-SegmentStream-Agent-Scope`; `undefined` without the header. */
118
119
  readonly scope?: string;
119
120
  /**
@@ -170,6 +170,7 @@ export function runtimeCredential(verify, request) {
170
170
  const provider = request.headers[ACT_AS_PROVIDER_HEADER]?.trim();
171
171
  const agentTask = agentTaskSecret(request);
172
172
  const grant = request.headers[AGENT_GRANT_HEADER]?.trim();
173
+ const sender = request.headers["x-segmentstream-chat-sender"]?.trim();
173
174
  const scope = request.headers[AGENT_SCOPE_HEADER]?.trim();
174
175
  const chat = requestChat(request);
175
176
  return {
@@ -178,6 +179,7 @@ export function runtimeCredential(verify, request) {
178
179
  ...(provider ? { provider } : {}),
179
180
  ...(agentTask === undefined ? {} : { agentTask }),
180
181
  ...(grant ? { grant } : {}),
182
+ ...(sender && sender.length <= 256 ? { sender } : {}),
181
183
  ...(scope ? { scope } : {}),
182
184
  ...(chat === undefined ? {} : { chat }),
183
185
  };
@@ -386,6 +386,7 @@ export declare const Catalog: Schema.decodeTo<Schema.Struct<{
386
386
  readonly name: Schema.String;
387
387
  readonly description: Schema.String;
388
388
  readonly permission: Schema.optionalKey<Schema.String>;
389
+ readonly anyOf: Schema.optionalKey<Schema.$Array<Schema.String>>;
389
390
  readonly input: Schema.$Record<Schema.String, Schema.Codec<Schema.Json, Schema.Json, never, never>>;
390
391
  readonly retryOnDeadlock: Schema.optionalKey<Schema.Boolean>;
391
392
  readonly writes: Schema.optionalKey<Schema.$Array<Schema.String>>;
@@ -463,6 +464,8 @@ export declare const Catalog: Schema.decodeTo<Schema.Struct<{
463
464
  }>>;
464
465
  readonly onSignUp: Schema.optionalKey<Schema.String>;
465
466
  readonly guest: Schema.optionalKey<Schema.encodeKeys<Schema.Struct<{
467
+ readonly openOnInvite: Schema.optionalKey<Schema.$Array<Schema.String>>;
468
+ readonly byChannel: Schema.optionalKey<Schema.$Record<Schema.String, Schema.$Array<Schema.String>>>;
466
469
  readonly channels: Schema.$Array<Schema.String>;
467
470
  readonly origins: Schema.$Array<Schema.String>;
468
471
  readonly botCheck: Schema.optionalKey<Schema.Struct<{
@@ -675,6 +678,7 @@ export declare const Catalog: Schema.decodeTo<Schema.Struct<{
675
678
  readonly name: Schema.String;
676
679
  readonly description: Schema.String;
677
680
  readonly permission: Schema.optionalKey<Schema.String>;
681
+ readonly anyOf: Schema.optionalKey<Schema.$Array<Schema.String>>;
678
682
  readonly input: Schema.$Record<Schema.String, Schema.Codec<Schema.Json, Schema.Json, never, never>>;
679
683
  readonly retryOnDeadlock: Schema.optionalKey<Schema.Boolean>;
680
684
  readonly writes: Schema.optionalKey<Schema.$Array<Schema.String>>;
@@ -777,6 +781,7 @@ export declare const Catalog: Schema.decodeTo<Schema.Struct<{
777
781
  readonly name: Schema.String;
778
782
  readonly description: Schema.String;
779
783
  readonly permission: Schema.optionalKey<Schema.String>;
784
+ readonly anyOf: Schema.optionalKey<Schema.$Array<Schema.String>>;
780
785
  readonly input: Schema.$Record<Schema.String, Schema.Codec<Schema.Json, Schema.Json, never, never>>;
781
786
  readonly retryOnDeadlock: Schema.optionalKey<Schema.Boolean>;
782
787
  readonly writes: Schema.optionalKey<Schema.$Array<Schema.String>>;
@@ -854,6 +859,8 @@ export declare const Catalog: Schema.decodeTo<Schema.Struct<{
854
859
  }>>;
855
860
  readonly onSignUp: Schema.optionalKey<Schema.String>;
856
861
  readonly guest: Schema.optionalKey<Schema.encodeKeys<Schema.Struct<{
862
+ readonly openOnInvite: Schema.optionalKey<Schema.$Array<Schema.String>>;
863
+ readonly byChannel: Schema.optionalKey<Schema.$Record<Schema.String, Schema.$Array<Schema.String>>>;
857
864
  readonly channels: Schema.$Array<Schema.String>;
858
865
  readonly origins: Schema.$Array<Schema.String>;
859
866
  readonly botCheck: Schema.optionalKey<Schema.Struct<{
@@ -1066,6 +1073,7 @@ export declare const Catalog: Schema.decodeTo<Schema.Struct<{
1066
1073
  readonly name: Schema.String;
1067
1074
  readonly description: Schema.String;
1068
1075
  readonly permission: Schema.optionalKey<Schema.String>;
1076
+ readonly anyOf: Schema.optionalKey<Schema.$Array<Schema.String>>;
1069
1077
  readonly input: Schema.$Record<Schema.String, Schema.Codec<Schema.Json, Schema.Json, never, never>>;
1070
1078
  readonly retryOnDeadlock: Schema.optionalKey<Schema.Boolean>;
1071
1079
  readonly writes: Schema.optionalKey<Schema.$Array<Schema.String>>;
@@ -11,7 +11,7 @@ import { nameToWire } from "../authoring-names.js";
11
11
  import { bundledNavigationCatalog } from "../navigation-artifact.js";
12
12
  import { parsePageCatalog } from "../navigation-catalog.js";
13
13
  import { chatRetentionDaysOf, declaredChatRetentionDaysOf, guestOf, signUpOriginsOf, signUpRolesOf, } from "../manifest.js";
14
- import { isAllowed } from "../permissions.js";
14
+ import { allowsAction } from "../permissions.js";
15
15
  import { agentToolsFor } from "../runtime/guests.js";
16
16
  import { implicitMemberOf } from "../role.js";
17
17
  import { sqlServiceRuntime } from "../runtime/service-binding.js";
@@ -130,7 +130,7 @@ function unmatchedRoutes(plan, verifyToken, exchangeSession, verifyRuntime) {
130
130
  const authenticated = yield* withPrincipal(credential, verifyToken, backend, Effect.gen(function* () {
131
131
  const principal = yield* CurrentPrincipal;
132
132
  const caller = yield* currentCaller;
133
- const visible = entity.actions.filter((action) => action.permissions.every((permission) => isAllowed(permission, principal)) &&
133
+ const visible = entity.actions.filter((action) => allowsAction(action, principal) &&
134
134
  runtimeAllows(caller, { entity: entity.name, action: action.name }));
135
135
  const suggestions = suggestNames(match[2], visible.map(({ name }) => name));
136
136
  return toServerResponse(routeNotFound(requestId, suggestions));
@@ -457,16 +457,6 @@ export function createOntologyService(ontology, config) {
457
457
  verifyToken,
458
458
  verifyRuntime,
459
459
  exchangeSession,
460
- ...(!preview &&
461
- ontology.config.publicGroupAction && {
462
- publicGroupAction: {
463
- binding: ontology.config.publicGroupAction,
464
- plan,
465
- hooks,
466
- connections,
467
- replicate,
468
- },
469
- }),
470
460
  visitorWebsites: preview ? { guests: [], signUp: [] } : visitorWebsites,
471
461
  agentTools,
472
462
  guest: preview ? undefined : guest,
@@ -49,4 +49,4 @@ export declare function resultText(result: ToolResult): string;
49
49
  * fixed values replace whatever the caller sent for them; the call goes through the toolset's
50
50
  * connection, audited as `<toolset>.<tool>`.
51
51
  */
52
- export declare function runToolsetToolOf(connections: ConnectionTransportFactory): (toolset: ResolvedToolset, tool: ResolvedTool, call: ToolsetCall) => Effect.Effect<ToolResult, ActionRejected | PermissionDenied | ConnectionError, RequestId | CurrentPrincipal>;
52
+ export declare function runToolsetToolOf(connections: ConnectionTransportFactory, reportCost?: (guestId: string, costUsd: number, key: string) => Effect.Effect<void>): (toolset: ResolvedToolset, tool: ResolvedTool, call: ToolsetCall) => Effect.Effect<ToolResult, ActionRejected | PermissionDenied | ConnectionError, RequestId | CurrentPrincipal>;