@segmentstream/ontology 0.182.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.
- package/CHANGELOG.md +32 -0
- package/README.md +23 -15
- package/dist/action.d.ts +11 -4
- package/dist/agent-chat.d.ts +6 -0
- package/dist/agent-chat.js +43 -28
- package/dist/analyze.d.ts +6 -1
- package/dist/analyze.js +51 -19
- package/dist/authoring.js +7 -1
- package/dist/chat.d.ts +32 -3
- package/dist/chat.js +33 -12
- package/dist/manifest.d.ts +64 -0
- package/dist/manifest.js +9 -0
- package/dist/migrate/model.d.ts +16 -0
- package/dist/permissions.d.ts +17 -0
- package/dist/permissions.js +17 -0
- package/dist/render.d.ts +6 -0
- package/dist/render.js +25 -10
- package/dist/runtime/pipeline.d.ts +3 -3
- package/dist/runtime/pipeline.js +11 -4
- package/dist/service/catalog.js +3 -3
- package/dist/service/chat/chat-draft.d.ts +1 -1
- package/dist/service/chat/delivery.js +43 -22
- package/dist/service/chat/routes.js +2 -0
- package/dist/service/chat/schemas.d.ts +40 -0
- package/dist/service/chat/schemas.js +3 -1
- package/dist/service/mcp/server.js +2 -0
- package/dist/service/mcp/tools.d.ts +10 -2
- package/dist/service/mcp/tools.js +11 -4
- package/dist/service/operations.js +8 -4
- package/dist/service/plan.d.ts +3 -1
- package/dist/service/plan.js +4 -2
- package/dist/service/schemas.d.ts +4 -0
- package/dist/service/service.js +2 -2
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,37 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.183.0
|
|
4
|
+
|
|
5
|
+
`agent_chat.send` is the one action that sends a message to a chat, in the voice its new `as`
|
|
6
|
+
names: `as: "agent"`, the default and what `send` did before, as the agent without attribution,
|
|
7
|
+
under `agent_chat:send`; or `as: "me"`, the caller's own message signed through
|
|
8
|
+
`chat.attribution`, exactly as `postMessage` posts it, under `agent_chat:post_message`.
|
|
9
|
+
|
|
10
|
+
- Either permission opens the action, and the delivery checks the voice's own, scoped grants
|
|
11
|
+
included: `agent_chat:send` alone cannot write as oneself, nor `agent_chat:post_message` alone as
|
|
12
|
+
the agent. Existing grants keep their meaning, and input still never names another sender.
|
|
13
|
+
- `files`, `buttons`, `template` and `replyTo` work in both voices. A WhatsApp template cannot
|
|
14
|
+
carry an attribution: in the caller's voice it goes only where their message is unsigned, a
|
|
15
|
+
member's own reply in the inbox under `inbox.attribution: "none"`, and is refused elsewhere with
|
|
16
|
+
`refusal: "attribution_unsupported"` before anything is reserved.
|
|
17
|
+
- `send` lists the chat connections it sends through in the manifest, as `postMessage` does, so a
|
|
18
|
+
preview deployment refuses it as it refuses posting.
|
|
19
|
+
- `previewMessage` is unchanged: it previews a text post in the caller's voice, what `send` with
|
|
20
|
+
`as: "me"` delivers, under `agent_chat:post_message`.
|
|
21
|
+
- An action may name several permissions, `permission: [a, b]`, any one of which runs it, for an
|
|
22
|
+
action whose input chooses what it does and that checks inside, with `isAllowed`, what the
|
|
23
|
+
choice needs. Such an action writes nothing itself (a `prepare` without a handler); `check`
|
|
24
|
+
refuses a list on any other. The manifest writes the list as the action's `anyOf`, with
|
|
25
|
+
`permission` its first, and the catalog, `describe` and MCP offer the action to a holder of any.
|
|
26
|
+
- The starter's guidance for coding agents sends chat messages with `agent_chat.send`.
|
|
27
|
+
|
|
28
|
+
Action required: replace `agent_chat.postMessage(input)` with
|
|
29
|
+
`agent_chat.send({ ...input, as: "me" })`, the MCP tool `chat_post_message` with `chat_send` and
|
|
30
|
+
`as: "me"`, and `POST /api/ontology/chat/actions/post_message` with
|
|
31
|
+
`POST /api/ontology/agent_chat/actions/send` and `"as": "me"` in its input. The earlier names post
|
|
32
|
+
exactly as `send` with `as: "me"` until 2027-05-27, a key spent through one being the same delivery
|
|
33
|
+
through the other; after that date they stop working. `previewMessage` stays.
|
|
34
|
+
|
|
3
35
|
## 0.182.0
|
|
4
36
|
|
|
5
37
|
Guest turns on admitted messaging channels use workspace roles, regular agent personas, and ontology tools. Workspaces select guest roles by channel and can handle authorized provider tools in workspace code. This replaces isolated group responses and their dedicated action and connection bindings.
|
package/README.md
CHANGED
|
@@ -659,9 +659,10 @@ with its input in TypeScript names; so do the workflow's `connections`. Every re
|
|
|
659
659
|
through the same path as the HTTP routes: it is checked against the workflow user's permissions,
|
|
660
660
|
validated, and recorded in history under the workflow user. Batch writes (`createMany`,
|
|
661
661
|
`updateMany`, `upsertMany`) are refused in steps; run an action that writes the batch. In production,
|
|
662
|
-
workflow roles can explicitly grant `agent_chat:post_message`
|
|
663
|
-
|
|
664
|
-
agent
|
|
662
|
+
workflow roles can explicitly grant `agent_chat:post_message` for attributed chat delivery,
|
|
663
|
+
`agent_chat.send` with `as: "me"`, and its destination preview, `previewMessage`, or
|
|
664
|
+
`agent_chat:send` for `send` as the agent. Preview deployments refuse sending; agent tasks cannot
|
|
665
|
+
send to chat on either target.
|
|
665
666
|
|
|
666
667
|
A step calls a model through Vercel AI Gateway with the AI SDK (`ai`), outside `run`: the
|
|
667
668
|
deployment authenticates with its Vercel project identity, so the workspace holds no key. Give
|
|
@@ -730,8 +731,8 @@ async function draftReply(input: { message: string }) {
|
|
|
730
731
|
predates tasks, or the run is outside production), `busy` (the workspace has 10 live tasks; the
|
|
731
732
|
agent was not called) or `agent_failed` (its turn failed, its cost cap included); or
|
|
732
733
|
`{ status: "timed_out" }`. Text beyond 65,536 characters is cut and marked `truncated`.
|
|
733
|
-
- A task cannot post to chat in this release: `agent_chat.
|
|
734
|
-
whatever the role grants. The answer reaches people through the workflow's later steps.
|
|
734
|
+
- A task cannot post to chat in this release: `agent_chat.send` is refused for a task in either
|
|
735
|
+
voice, as is its earlier name `post_message`, whatever the role grants. The answer reaches people through the workflow's later steps.
|
|
735
736
|
- At least once: a start step retried after the agent accepted the task hands it over again, and
|
|
736
737
|
the agent ends the earlier session. Write prompts and later steps that tolerate a repeat.
|
|
737
738
|
- Tasks run only in production, where the agent's runtime tokens are valid. Locally and in
|
|
@@ -1543,8 +1544,13 @@ its id, with their files as the chat's attachments, for a caller with `agent_cha
|
|
|
1543
1544
|
`agent_chat:read` and `agent_chat:update`, granted explicitly; wildcard entity grants do not
|
|
1544
1545
|
cover this built-in registry.
|
|
1545
1546
|
|
|
1546
|
-
|
|
1547
|
-
`ChatDelivery
|
|
1547
|
+
`agent_chat.send` (MCP `chat_send`) sends exact text directly through the ontology service's
|
|
1548
|
+
`ChatDelivery`, as the agent by default, under `agent_chat:send`, or with `as: "me"` in the
|
|
1549
|
+
caller's own voice, signed through `chat.attribution`, under `agent_chat:post_message`. Either
|
|
1550
|
+
grant opens the action, and the delivery checks the voice's own, scopes included; input never
|
|
1551
|
+
names another sender. Its earlier name for `as: "me"`, `postMessage` (MCP `chat_post_message`,
|
|
1552
|
+
`POST /api/ontology/chat/actions/post_message`), works the same until 2027-05-27. <!-- @legacy ontology.chat-post-message --> Nothing it
|
|
1553
|
+
sends starts an agent turn. Configure a declared provider connection:
|
|
1548
1554
|
|
|
1549
1555
|
```ts
|
|
1550
1556
|
const telegram = connection("telegram", { description: "Workspace Telegram bot." });
|
|
@@ -1556,8 +1562,8 @@ defineOntology({
|
|
|
1556
1562
|
});
|
|
1557
1563
|
```
|
|
1558
1564
|
|
|
1559
|
-
Grant `agent_chat:post_message` explicitly (`agent_chat:*`
|
|
1560
|
-
`agent_chat:send_message` grant does not grant posting. The old send action, instruction relay,
|
|
1565
|
+
Grant `agent_chat:post_message` and `agent_chat:send` explicitly (`agent_chat:*` covers both).
|
|
1566
|
+
The former `agent_chat:send_message` grant does not grant posting. The old send action, instruction relay,
|
|
1561
1567
|
`AgentChannel`/`AgentMessage` exports and agent-origin configuration have been removed.
|
|
1562
1568
|
Older ontology definitions still expose reads; posting requires the provider mapping.
|
|
1563
1569
|
|
|
@@ -1614,7 +1620,8 @@ Paired private chats have stable handles `telegram:private:<member UUID>`, and
|
|
|
1614
1620
|
Posting permission
|
|
1615
1621
|
allows target discovery independently of history. `user_find` still requires `user:read`.
|
|
1616
1622
|
|
|
1617
|
-
External OAuth/service clients
|
|
1623
|
+
External OAuth/service clients post in their own voice with
|
|
1624
|
+
`chat_send({ chat, text, reply_to?, files?, buttons?, idempotency_key, as: "me" })`.
|
|
1618
1625
|
Attribution comes from verified authentication and stored names. The workspace can set
|
|
1619
1626
|
`chat.attribution: { template, separator }`; defaults are `{name}` and `\n\n`.
|
|
1620
1627
|
The delivered plain text is `text + separator + attribution`, preserving Unicode, whitespace and
|
|
@@ -1639,12 +1646,13 @@ participants it names. A posting service cannot read member chats. They read the
|
|
|
1639
1646
|
`reason` beside the archive's fields, and the platform's chat archive before; `after`, a revision,
|
|
1640
1647
|
reads the chat's changes since. `chat.retentionDays` (1–3650, 365 by default) sets how long the
|
|
1641
1648
|
workspace keeps them. The canonical
|
|
1642
|
-
REST facade is `/api/ontology/chat/{list,history,search
|
|
1643
|
-
|
|
1644
|
-
|
|
1649
|
+
REST facade is `/api/ontology/chat/{list,history,search}`, and `send` is
|
|
1650
|
+
`POST /api/ontology/agent_chat/actions/send`, with the standard
|
|
1651
|
+
`{ input, options?: { validate_only? } }` envelope and action response.
|
|
1652
|
+
Validation checks eligibility, the voice's permission and exact text without reserving or sending.
|
|
1645
1653
|
|
|
1646
|
-
`chat_get` and `chat_update` use the registry implementations.
|
|
1647
|
-
|
|
1654
|
+
`chat_get` and `chat_update` use the registry implementations. The agent's sessions post
|
|
1655
|
+
through `chat_post_message` with the agent SDK's application-owned
|
|
1648
1656
|
`_segmentstream` protocol; the model sees only `{ chat, text, reply_to? }`. Authenticated tools/list
|
|
1649
1657
|
advertises `segmentstream/chat-post: 1` only with a configured provider. Deploy the updated agent
|
|
1650
1658
|
first, then the archive migration/backend, then enable ontology delivery.
|
package/dist/action.d.ts
CHANGED
|
@@ -66,10 +66,11 @@ export interface Action<Input extends Schema.Top = Schema.Top, Result = unknown>
|
|
|
66
66
|
readonly description: string;
|
|
67
67
|
readonly input: Input;
|
|
68
68
|
/**
|
|
69
|
-
* The permission a principal needs to run the action, as `action({ permission })` set it
|
|
70
|
-
* is not set, the action requires
|
|
69
|
+
* The permission a principal needs to run the action, as `action({ permission })` set it, or the
|
|
70
|
+
* permissions any one of which runs it. When it is not set, the action requires
|
|
71
|
+
* `<entity>:<action name>`, for example `lead:changeStatus`.
|
|
71
72
|
*/
|
|
72
|
-
readonly permission: string | undefined;
|
|
73
|
+
readonly permission: string | ReadonlyArray<string> | undefined;
|
|
73
74
|
/** How the action behaves, as `action({ hints })` set it; see {@link ActionHints}. */
|
|
74
75
|
readonly hints: ActionHints | undefined;
|
|
75
76
|
/** See `action({ retryOnDeadlock })`. Absent or false means the handler runs at most once. */
|
|
@@ -115,8 +116,14 @@ interface ActionOptions<Input extends Schema.Top> {
|
|
|
115
116
|
* The permission a principal needs to run the action. It defaults to `<entity>:<action name>`;
|
|
116
117
|
* set it only to share one permission between actions, for example two actions behind `lead:edit`.
|
|
117
118
|
* Roles grant it in their `permissions`.
|
|
119
|
+
*
|
|
120
|
+
* A list names several permissions, any one of which runs the action: for an action whose input
|
|
121
|
+
* chooses what it does, each choice needing its own permission, which the action checks inside
|
|
122
|
+
* with `isAllowed`, as `agent_chat.send` checks `agent_chat:send` for `as: "agent"` and
|
|
123
|
+
* `agent_chat:post_message` for `as: "me"`. Such an action writes nothing itself, a `prepare`
|
|
124
|
+
* without a handler: a scope could not tell which of the permissions a write was made under.
|
|
118
125
|
*/
|
|
119
|
-
readonly permission?: string
|
|
126
|
+
readonly permission?: string | ReadonlyArray<string>;
|
|
120
127
|
/**
|
|
121
128
|
* How the action behaves, for the agents that run it over MCP. Set `destructive: false` for an
|
|
122
129
|
* routine reversible action, `irreversible: true` for an effect without a complete undo, and
|
package/dist/agent-chat.d.ts
CHANGED
|
@@ -130,6 +130,12 @@ export declare const AgentChat: import("./entity.js").Entity<"agent_chat", {
|
|
|
130
130
|
readonly text: Schema.String;
|
|
131
131
|
readonly token: Schema.String;
|
|
132
132
|
}>]>>>>;
|
|
133
|
+
readonly files: Schema.optionalKey<Schema.$Array<Schema.Struct<{
|
|
134
|
+
readonly entity: Schema.String;
|
|
135
|
+
readonly id: Schema.String;
|
|
136
|
+
readonly property: Schema.optionalKey<Schema.String>;
|
|
137
|
+
}>>>;
|
|
138
|
+
readonly as: Schema.optionalKey<Schema.Literals<readonly ["agent", "me"]>>;
|
|
133
139
|
readonly idempotencyKey: Schema.String;
|
|
134
140
|
}>, {
|
|
135
141
|
readonly status: "sent" | "uncertain";
|
package/dist/agent-chat.js
CHANGED
|
@@ -198,7 +198,7 @@ export const AgentChat = entity("agent_chat", {
|
|
|
198
198
|
takeOver: action({
|
|
199
199
|
description: "Take a person's private chat over from the agent, as yourself, also when the agent handed " +
|
|
200
200
|
"the person over: until a member hands it back, the agent records the person's messages " +
|
|
201
|
-
"and answers none of them, and staff answer with
|
|
201
|
+
"and answers none of them, and staff answer with send as me. Refused for a group chat, " +
|
|
202
202
|
"for a chat on a channel the ontology's inbox.takeover does not list, and for a chat " +
|
|
203
203
|
"another member took over; taking over a chat you hold changes nothing.",
|
|
204
204
|
hints: { destructive: false, irreversible: false, idempotent: true },
|
|
@@ -307,9 +307,11 @@ export const AgentChat = entity("agent_chat", {
|
|
|
307
307
|
}),
|
|
308
308
|
}),
|
|
309
309
|
previewMessage: action({
|
|
310
|
-
description: "Render an exact
|
|
311
|
-
"
|
|
312
|
-
"
|
|
310
|
+
description: "Render an exact text message in your own voice, as send with as me delivers it, with its " +
|
|
311
|
+
"verified destination and sender attribution, without reserving a key, writing history or " +
|
|
312
|
+
"sending. Requires agent_chat:post_message, as sending in your voice does. A preview is " +
|
|
313
|
+
"not authorization to send.",
|
|
314
|
+
// A preview shows what only your voice adds, the attribution, so only it is previewed.
|
|
313
315
|
permission: "agent_chat:post_message",
|
|
314
316
|
input: ChatPostInput,
|
|
315
317
|
connections: [],
|
|
@@ -349,22 +351,33 @@ export const AgentChat = entity("agent_chat", {
|
|
|
349
351
|
}),
|
|
350
352
|
}),
|
|
351
353
|
send: action({
|
|
352
|
-
description: "Send a message to
|
|
353
|
-
"person reads it as the agent's,
|
|
354
|
-
"
|
|
355
|
-
"
|
|
356
|
-
"
|
|
357
|
-
"
|
|
358
|
-
"
|
|
359
|
-
"(
|
|
360
|
-
"
|
|
361
|
-
"
|
|
362
|
-
"
|
|
363
|
-
"
|
|
364
|
-
"
|
|
365
|
-
"
|
|
366
|
-
"
|
|
367
|
-
"
|
|
354
|
+
description: "Send a message to an eligible chat ID or exact title, in one of two voices. as agent, the " +
|
|
355
|
+
"default, needs agent_chat:send: the person reads it as the agent's, without sender " +
|
|
356
|
+
"attribution, and the chat store keeps who asked for it, as for a workflow or a member that " +
|
|
357
|
+
"writes first, such as a follow-up the workspace decides on. as me needs " +
|
|
358
|
+
"agent_chat:post_message: you write as yourself, and the platform adds your name as the " +
|
|
359
|
+
"sender attribution, except in your own reply in the inbox where its attribution is none. " +
|
|
360
|
+
"Nothing else chooses the sender. text is Markdown (bold, italic, code, lists, " +
|
|
361
|
+
"[text](url)); each channel renders it natively and degrades constructs it can't show. " +
|
|
362
|
+
"Ambiguous titles require an explicit ID; a scoped grant names the chat by its agent_chat " +
|
|
363
|
+
"record. Confirm the full final text, attribution and destination before calling. The " +
|
|
364
|
+
"agent's tasks cannot call it, and its sessions do not send as the agent: a task's workflow " +
|
|
365
|
+
"sends what the task wrote. Reuse the same idempotency key on replay; an uncertain " +
|
|
366
|
+
"operation is never resent. A message the provider refuses spends its key and says why in " +
|
|
367
|
+
"refusal: outside_reply_window (on WhatsApp the person last wrote more than 24 hours ago), " +
|
|
368
|
+
"recipient_unreachable or recipient_opted_out. On WhatsApp, template sends an approved " +
|
|
369
|
+
"template in place of text, which reaches a person outside the 24 hours, with its body's, " +
|
|
370
|
+
"header's and buttons' values; give exactly one of text and template. A template cannot " +
|
|
371
|
+
"carry an attribution: as me it is refused with refusal attribution_unsupported unless your " +
|
|
372
|
+
"message is unsigned. buttons puts rows of buttons under a text: links ({ text, url }) and " +
|
|
373
|
+
"workspace buttons ({ text, token }), whose press calls the workspace's button action with " +
|
|
374
|
+
"{ token } as the member who pressed it. A channel that cannot show them as given refuses " +
|
|
375
|
+
"the message with refusal buttons_unsupported before spending the key: WhatsApp shows one " +
|
|
376
|
+
"link, or up to three workspace buttons with labels of at most 20 characters, under at most " +
|
|
377
|
+
"1,024 characters. files sends stored files after the text in the same delivery; files a " +
|
|
378
|
+
"channel cannot send are refused before the key is spent.",
|
|
379
|
+
// Each voice needs its own permission, which the delivery checks: either opens the action.
|
|
380
|
+
permission: ["agent_chat:send", "agent_chat:post_message"],
|
|
368
381
|
input: ChatSendInput,
|
|
369
382
|
hints: { destructive: false, irreversible: true, idempotent: true },
|
|
370
383
|
connections: [],
|
|
@@ -372,29 +385,31 @@ export const AgentChat = entity("agent_chat", {
|
|
|
372
385
|
const delivery = yield* Effect.serviceOption(ChatDelivery);
|
|
373
386
|
if (Option.isNone(delivery) || delivery.value.send === undefined) {
|
|
374
387
|
return yield* new ActionRejected({
|
|
375
|
-
message: "Sending
|
|
388
|
+
message: "Sending a message requires the authenticated ontology service.",
|
|
376
389
|
});
|
|
377
390
|
}
|
|
378
391
|
return yield* delivery.value.send(input);
|
|
379
392
|
}),
|
|
380
393
|
}),
|
|
394
|
+
// @legacy ontology.chat-post-message
|
|
381
395
|
postMessage: action({
|
|
382
|
-
description: "Post to an eligible chat ID or exact title. text is Markdown
|
|
383
|
-
"[text](url)); each channel renders it natively and degrades
|
|
384
|
-
"The exact Markdown source is posted; the platform adds the
|
|
385
|
-
"Ambiguous titles require an explicit ID. Confirm the full final text,
|
|
386
|
-
"before calling. Reuse the same idempotency key on replay; an
|
|
396
|
+
description: "Post to an eligible chat ID or exact title, as send with as me does. text is Markdown " +
|
|
397
|
+
"(bold, italic, code, lists, [text](url)); each channel renders it natively and degrades " +
|
|
398
|
+
"constructs it can't show. The exact Markdown source is posted; the platform adds the " +
|
|
399
|
+
"sender attribution. Ambiguous titles require an explicit ID. Confirm the full final text, " +
|
|
400
|
+
"attribution and destination before calling. Reuse the same idempotency key on replay; an " +
|
|
401
|
+
"uncertain operation is never resent.",
|
|
387
402
|
input: ChatPostInput,
|
|
388
403
|
hints: { destructive: false, irreversible: true, idempotent: true },
|
|
389
404
|
connections: [],
|
|
390
405
|
prepare: ({ input }) => Effect.gen(function* () {
|
|
391
406
|
const delivery = yield* Effect.serviceOption(ChatDelivery);
|
|
392
|
-
if (Option.isNone(delivery)) {
|
|
407
|
+
if (Option.isNone(delivery) || delivery.value.send === undefined) {
|
|
393
408
|
return yield* new ActionRejected({
|
|
394
409
|
message: "Chat delivery requires the authenticated ontology service.",
|
|
395
410
|
});
|
|
396
411
|
}
|
|
397
|
-
return yield* delivery.value.
|
|
412
|
+
return yield* delivery.value.send({ ...input, as: "me" });
|
|
398
413
|
}),
|
|
399
414
|
}),
|
|
400
415
|
}));
|
package/dist/analyze.d.ts
CHANGED
|
@@ -177,8 +177,13 @@ export interface ResolvedRelationship {
|
|
|
177
177
|
export interface ResolvedAction {
|
|
178
178
|
readonly name: string;
|
|
179
179
|
readonly action: Action;
|
|
180
|
-
/**
|
|
180
|
+
/**
|
|
181
|
+
* The permission the action requires: its `permission`, or `<entity>:<action name>`; for an action
|
|
182
|
+
* several permissions open, the first of them.
|
|
183
|
+
*/
|
|
181
184
|
readonly permission: string;
|
|
185
|
+
/** For an action several permissions open, each of them, any one of which runs it. */
|
|
186
|
+
readonly anyOf?: ReadonlyArray<string>;
|
|
182
187
|
/** The input as JSON Schema, or `undefined` when it could not be generated. */
|
|
183
188
|
readonly input: JsonSchemaObject | undefined;
|
|
184
189
|
/** The keys of the connections the action's `prepare` calls, in declaration order. */
|
package/dist/analyze.js
CHANGED
|
@@ -267,10 +267,11 @@ export function analyze(config, options = {}) {
|
|
|
267
267
|
}),
|
|
268
268
|
...(config.chat.attribution === undefined ? {} : { attribution: config.chat.attribution }),
|
|
269
269
|
};
|
|
270
|
-
//
|
|
270
|
+
// Sending to a chat and sending a reviewed reply both send through the chat connections.
|
|
271
271
|
const sends = {
|
|
272
|
-
|
|
273
|
-
|
|
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) =>
|
|
287
|
+
actions: entity.actions.map((candidate) => !sends[entity.name].includes(candidate.name)
|
|
287
288
|
? candidate
|
|
288
289
|
: {
|
|
289
290
|
...candidate,
|
|
@@ -596,7 +597,7 @@ function workflowInputSchema(input) {
|
|
|
596
597
|
*/
|
|
597
598
|
function grantsSomeAction(entities, permissions) {
|
|
598
599
|
const holder = { permissions };
|
|
599
|
-
return entities.some((entity) => entity.actions.some((candidate) =>
|
|
600
|
+
return entities.some((entity) => entity.actions.some((candidate) => openingPermissions(candidate).some((permission) => isAllowed(permission, holder))) ||
|
|
600
601
|
Object.entries(entity.permissions).some(([verb, permission]) => verb !== READ_VERB && permission !== undefined && isAllowed(permission, holder)));
|
|
601
602
|
}
|
|
602
603
|
/**
|
|
@@ -2233,7 +2234,7 @@ function checkSignUpAction(input) {
|
|
|
2233
2234
|
const permissions = roles
|
|
2234
2235
|
.filter((candidate) => (granted ?? []).includes(candidate.name))
|
|
2235
2236
|
.flatMap((candidate) => (Array.isArray(candidate.permissions) ? candidate.permissions : []));
|
|
2236
|
-
if (!
|
|
2237
|
+
if (!openingPermissions(found).some((permission) => isAllowed(permission, { permissions }))) {
|
|
2237
2238
|
fail(`onSignUp must be runnable by the roles ${channel} sign-up grants.`);
|
|
2238
2239
|
}
|
|
2239
2240
|
}
|
|
@@ -2798,10 +2799,12 @@ function resolveActions(candidate, scope) {
|
|
|
2798
2799
|
}
|
|
2799
2800
|
}
|
|
2800
2801
|
}
|
|
2802
|
+
const permissions = resolvePermissions(path, permissionOf(candidate.name, name), action, scope);
|
|
2801
2803
|
actions.push({
|
|
2802
2804
|
name,
|
|
2803
2805
|
action,
|
|
2804
|
-
permission:
|
|
2806
|
+
permission: permissions[0],
|
|
2807
|
+
...(permissions.length > 1 ? { anyOf: permissions } : {}),
|
|
2805
2808
|
input: resolveInput(path, action.input, scope),
|
|
2806
2809
|
connections: resolveActionConnections(path, action, scope, scope.builtIns.has(candidate.definition)),
|
|
2807
2810
|
hints: resolveHints(path, action, report),
|
|
@@ -2919,19 +2922,40 @@ function resolveHints(path, action, report) {
|
|
|
2919
2922
|
return hints;
|
|
2920
2923
|
}
|
|
2921
2924
|
/** The action's own `permission`, which names an entity and a verb without wildcards. */
|
|
2922
|
-
|
|
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) {
|
|
2923
2931
|
const declared = action.permission;
|
|
2924
2932
|
if (declared === undefined) {
|
|
2925
|
-
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.");
|
|
2926
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) {
|
|
2927
2951
|
const parsed = parsePermission(declared);
|
|
2928
2952
|
if (parsed === undefined || parsed.entity === WILDCARD || parsed.verb === WILDCARD) {
|
|
2929
|
-
scope.report("invalid-permission",
|
|
2953
|
+
scope.report("invalid-permission", path, `${JSON.stringify(declared)} is not a permission an action can require; ` +
|
|
2930
2954
|
`write <entity>:<verb> without wildcards, such as ${fallback}.`);
|
|
2931
2955
|
return fallback;
|
|
2932
2956
|
}
|
|
2933
2957
|
if (!scope.entitiesByName.has(parsed.entity)) {
|
|
2934
|
-
scope.report("unknown-permission",
|
|
2958
|
+
scope.report("unknown-permission", path, `${parsed.entity} is not an entity of this ontology.`);
|
|
2935
2959
|
}
|
|
2936
2960
|
return permissionOf(parsed.entity, parsed.verb);
|
|
2937
2961
|
}
|
|
@@ -3146,7 +3170,7 @@ function knownVerbs(entities, toolsets = []) {
|
|
|
3146
3170
|
verbs.set(candidate.name, own);
|
|
3147
3171
|
}
|
|
3148
3172
|
for (const candidate of entities) {
|
|
3149
|
-
for (const
|
|
3173
|
+
for (const permission of candidate.actions.flatMap(openingPermissions)) {
|
|
3150
3174
|
const parsed = parsePermission(permission);
|
|
3151
3175
|
if (parsed !== undefined) {
|
|
3152
3176
|
verbs.get(parsed.entity)?.add(parsed.verb);
|
|
@@ -3360,7 +3384,7 @@ function checkNewUserAction(input) {
|
|
|
3360
3384
|
fail("onNewUser runs with the built-in member, which only defineOntology({ member }) " +
|
|
3361
3385
|
"declares; use signUp and onSignUp.");
|
|
3362
3386
|
}
|
|
3363
|
-
else if (!
|
|
3387
|
+
else if (!openingPermissions(found).some((permission) => isAllowed(permission, { permissions: member.permissions ?? [] }))) {
|
|
3364
3388
|
fail("onNewUser must be runnable by member.");
|
|
3365
3389
|
}
|
|
3366
3390
|
if (found.action.hints?.idempotent !== true) {
|
|
@@ -3432,12 +3456,16 @@ function checkPermissions(entities, roles, workflows, report, authoredRoles = ro
|
|
|
3432
3456
|
}));
|
|
3433
3457
|
// Built-in actions are granted by the workspace's roles when it wants them.
|
|
3434
3458
|
for (const candidate of entities.filter((entity) => !entity.builtIn)) {
|
|
3435
|
-
for (const
|
|
3436
|
-
const
|
|
3459
|
+
for (const action of candidate.actions) {
|
|
3460
|
+
const permissions = openingPermissions(action);
|
|
3437
3461
|
// An invalid name or permission is already an error; it needs no warning on top.
|
|
3438
|
-
const checkable =
|
|
3439
|
-
|
|
3440
|
-
|
|
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; ` +
|
|
3441
3469
|
"add it to the permissions of a role that may run it.", "warning");
|
|
3442
3470
|
}
|
|
3443
3471
|
}
|
|
@@ -3678,6 +3706,10 @@ function scopeWhere(walk, entityName, where, path, anyRecord = false) {
|
|
|
3678
3706
|
return result;
|
|
3679
3707
|
}
|
|
3680
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
|
+
}
|
|
3681
3713
|
function writesNothing(candidate) {
|
|
3682
3714
|
return (candidate.hints?.readOnly === true ||
|
|
3683
3715
|
(candidate.action.prepare !== undefined && candidate.action.transactional === false));
|
|
@@ -3742,7 +3774,7 @@ function checkScope(input) {
|
|
|
3742
3774
|
}
|
|
3743
3775
|
const unscopable = entities
|
|
3744
3776
|
.flatMap((candidate) => candidate.actions.map((action) => ({ entity: candidate.name, action })))
|
|
3745
|
-
.find(({ action }) => action.permission
|
|
3777
|
+
.find(({ action }) => openingPermissions(action).includes(permission) && writesNothing(action));
|
|
3746
3778
|
if (unscopable !== undefined) {
|
|
3747
3779
|
report("invalid-scope", path, `${permission} runs ${unscopable.entity}.${unscopable.action.name}, a readOnly or ` +
|
|
3748
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
|
|
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
|
-
/**
|
|
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
|
-
|
|
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
|
-
/**
|
|
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(
|
|
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
|
-
/**
|
|
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,
|
|
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({
|