@segmentstream/ontology 0.122.0 → 0.124.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 +53 -0
- package/README.md +25 -14
- package/dist/action.d.ts +11 -6
- package/dist/agent-chat.d.ts +30 -15
- package/dist/agent-chat.js +66 -2
- package/dist/analyze.d.ts +4 -0
- package/dist/analyze.js +63 -13
- package/dist/app-feedback.js +6 -5
- package/dist/chat.d.ts +10 -0
- package/dist/index.d.ts +3 -1
- package/dist/index.js +3 -1
- package/dist/manifest.d.ts +60 -7
- package/dist/manifest.js +37 -6
- package/dist/migrate/apply.js +5 -17
- package/dist/migrate/model.d.ts +24 -0
- package/dist/replication/baseline.d.ts +1 -2
- package/dist/replication/baseline.js +3 -2
- package/dist/replication/legacy-baseline.d.ts +1 -2
- package/dist/replication/legacy-baseline.js +3 -6
- package/dist/replication/migrate.d.ts +1 -10
- package/dist/replication/migrate.js +0 -37
- package/dist/replication/model.d.ts +6 -9
- package/dist/replication/model.js +13 -47
- package/dist/replication/schema.js +3 -0
- package/dist/replication/shadow.d.ts +7 -3
- package/dist/replication/shadow.js +9 -9
- package/dist/replication/store.d.ts +6 -2
- package/dist/replication/store.js +21 -46
- package/dist/runtime/agents.js +16 -6
- package/dist/runtime/generated-actions.js +5 -0
- package/dist/runtime/service-binding.d.ts +5 -1
- package/dist/runtime/service-binding.js +14 -5
- package/dist/service/agent/server.js +1 -0
- package/dist/service/chat/delivery.js +3 -0
- package/dist/service/mcp/server.js +5 -5
- package/dist/service/runtime-contract.d.ts +11 -1
- package/dist/service/schemas.d.ts +6 -0
- package/dist/storage/memory.d.ts +100 -0
- package/dist/storage/memory.js +281 -0
- package/dist/storage/sessions.d.ts +2 -2
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,58 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.124.0
|
|
4
|
+
|
|
5
|
+
Staff take an inbox chat over from the agent. `agent_chat.takeOver({ chat })` sets the record's new
|
|
6
|
+
`handledBy` relationship to the member (`agent_chat:take_over`), `agent_chat.handBack({ chat })`
|
|
7
|
+
clears it (`agent_chat:hand_back`), and a chat another member holds is refused until it is handed
|
|
8
|
+
back. `inbox.takeover.channels` names the channels of `chat` where staff take chats over: every one
|
|
9
|
+
of them when absent, none with `[]`; `check` reports `invalid-inbox` for an undeclared channel and
|
|
10
|
+
for `web`, whose visitors' page staff replies do not reach yet. Where takeover is open, the answer
|
|
11
|
+
to the agent's admission says `takeover: true` and the report of a private chat says
|
|
12
|
+
`handled: true` while staff hold it. The generated `update` of a built-in entity no longer takes
|
|
13
|
+
its relationships.
|
|
14
|
+
|
|
15
|
+
## 0.123.0
|
|
16
|
+
|
|
17
|
+
`memoryFileStorage()` keeps an ontology's files in memory, so tests that run actions in process can
|
|
18
|
+
use `uploads.for` inputs, `Files.stage`, `Files.open` and downloads. Build the backend on it with
|
|
19
|
+
`backendLayer(ontology, files.blobStorage)`, or pass `blobStorage: files.blobStorage` with a
|
|
20
|
+
`storageMaintenanceKey` to `createOntologyService`; the database keeps the upload lifecycle, with
|
|
21
|
+
the deployment's permission checks, file policies and quota. `files.upload({ principal, entity,
|
|
22
|
+
property, action, recordId?, filename, contentType, bytes })` returns the ticket and action options
|
|
23
|
+
for the action's `uploads.for` input, `files.read({ principal, entity, id, property })` returns a
|
|
24
|
+
stored file's metadata and bytes, and `files.fetch` answers the store's transfer grants for tests
|
|
25
|
+
that upload over HTTP. See "Testing actions with files" in `docs/ontology.md`.
|
|
26
|
+
|
|
27
|
+
Ontology replication covers every stored business entity, with all of its fields and its
|
|
28
|
+
relationships between stored business entities. The migrator no longer reads or carries
|
|
29
|
+
per-workspace replication exclusions across deployments, and delivery no longer filters events by
|
|
30
|
+
them. A workspace source that still records exclusions from an earlier release is cleared through
|
|
31
|
+
the ordinary policy change: the scopes they withheld are copied into a private candidate and
|
|
32
|
+
published by the usual cutover while existing analytical queries keep working. Nothing changes in
|
|
33
|
+
workspace code.
|
|
34
|
+
|
|
35
|
+
Warehouse SQL does not apply the ontology's permissions: anyone who can query the workspace
|
|
36
|
+
warehouse reads every replicated stored entity.
|
|
37
|
+
|
|
38
|
+
`check` warns `workflow_role_scoped` only when a workflow's role scopes a permission with `me`,
|
|
39
|
+
directly or through a path such as `me.staffMember.division`, and names only those permissions.
|
|
40
|
+
A scope that never names `me`, such as `{ purpose: { in: ["signing", "signed"] } }`, matches the
|
|
41
|
+
same records for the workflow's service user as for anyone else, and no longer warns.
|
|
42
|
+
|
|
43
|
+
`action({ writes })` type-checks an entity named by a string, as `check` and the runtime already
|
|
44
|
+
accepted it: `writes: [self, "note"]` beside handles and thunks such as `() => Note`. A name is
|
|
45
|
+
the entity's authored or snake_case name (`"staffMember"` or `"staff_member"`); since an action
|
|
46
|
+
is declared before its ontology, the type accepts any string and `check` refuses one that names
|
|
47
|
+
no stored entity of the ontology. The manifest and the runtime resolve it to the same entity as
|
|
48
|
+
its handle, so a handler may write it and nothing else it does not declare.
|
|
49
|
+
|
|
50
|
+
## 0.122.1
|
|
51
|
+
|
|
52
|
+
The agent no longer tells a member the builders' responses to app feedback when a chat starts.
|
|
53
|
+
It tells them when they ask about their feedback, reading only their own items: a builder who can
|
|
54
|
+
read everyone's feedback was told other members' responses as their own.
|
|
55
|
+
|
|
3
56
|
## 0.122.0
|
|
4
57
|
|
|
5
58
|
The website's visitors' chats in the inbox: `inbox.roles` may list `guest` where the ontology
|
package/README.md
CHANGED
|
@@ -243,6 +243,13 @@ when omitted. Streams stay within the step; carry tickets and references between
|
|
|
243
243
|
See `docs/ontology.md#file-transfers`
|
|
244
244
|
for the API and recovery rules.
|
|
245
245
|
|
|
246
|
+
Tests that run actions with files in process build the backend on `memoryFileStorage()`:
|
|
247
|
+
`backendLayer(ontology, files.blobStorage)`, or `blobStorage: files.blobStorage` in
|
|
248
|
+
`createOntologyService`. The store keeps the bytes in memory while the database keeps the
|
|
249
|
+
upload lifecycle; `files.upload(...)` returns the ticket and options for an `uploads.for`
|
|
250
|
+
input, and `files.read(...)` reads a stored file back with the reader's permissions. See
|
|
251
|
+
`docs/ontology.md#testing-actions-with-files`.
|
|
252
|
+
|
|
246
253
|
Buffered `get`/`post`/`request` calls receive the provider's response through a streamed
|
|
247
254
|
proxy call and collect up to 64 MiB (`MAXIMUM_CONNECTION_RESPONSE_BYTES`); a larger response
|
|
248
255
|
fails with `invalid_response`. To process a response incrementally, or one larger than that,
|
|
@@ -1327,7 +1334,8 @@ There is no automatic reporter authority in workflows, pipeline workers or admis
|
|
|
1327
1334
|
|
|
1328
1335
|
The MCP server preserves submit in compact listing and adds feedback guidance only when submit
|
|
1329
1336
|
is visible. Attachment guidance appears only when attach is visible. The caller offers once per
|
|
1330
|
-
problem
|
|
1337
|
+
problem and asks approval for the title and summary. It reports and acknowledges a builders'
|
|
1338
|
+
answer only when the member asks, reading only the member's own items.
|
|
1331
1339
|
Builders use `segmentstream ontology feedback list`, `show` and `respond` as their app member.
|
|
1332
1340
|
|
|
1333
1341
|
## Toolsets
|
|
@@ -1381,17 +1389,17 @@ task header on any other route are a 403.
|
|
|
1381
1389
|
|
|
1382
1390
|
Without either header the agent may call only the agent routes:
|
|
1383
1391
|
|
|
1384
|
-
| Route | Caller | Does
|
|
1385
|
-
| ------------------------------------------------------------- | ------ |
|
|
1386
|
-
| `POST /api/ontology/agent/pairings` | agent | `{ provider, external_id, display? }` → `{ code, expires_at }`
|
|
1387
|
-
| `GET /api/ontology/agent/pairings/{code}` | member | `{ provider, display, expires_at }`, for the connect page
|
|
1388
|
-
| `POST /api/ontology/agent/pairings/{code}/approve` | member | Pairs the account with the member → `{ identity }`
|
|
1389
|
-
| `POST /api/ontology/agent/identities/resolve` | agent | Admission and turn limits; see below
|
|
1390
|
-
| `POST /api/ontology/agent/identities/notice` | agent | `{ provider, external_id, sha256, version? }` acknowledges notice delivery: 204
|
|
1391
|
-
| `GET /api/ontology/agent/identities/{provider}/{external_id}` | agent | `{ user: { id, name }, roles, agent_tools }`; 404 unpaired, 403 revoked, inactive
|
|
1392
|
-
| `GET /api/ontology/agent/identities` | member | `{ identities }`: the member's live identities
|
|
1393
|
-
| `DELETE /api/ontology/agent/identities/{id}` | member | Revokes one of them: 204
|
|
1394
|
-
| `POST /api/ontology/agent/chats/seen` | agent | `{ provider, externalId, title, memberId?, leftMemberId?, agentLeft?, migratedFrom? }` → `{ id, title, purpose, whenToUse }` |
|
|
1392
|
+
| Route | Caller | Does |
|
|
1393
|
+
| ------------------------------------------------------------- | ------ | -------------------------------------------------------------------------------------------------------------------------------------- |
|
|
1394
|
+
| `POST /api/ontology/agent/pairings` | agent | `{ provider, external_id, display? }` → `{ code, expires_at }` |
|
|
1395
|
+
| `GET /api/ontology/agent/pairings/{code}` | member | `{ provider, display, expires_at }`, for the connect page |
|
|
1396
|
+
| `POST /api/ontology/agent/pairings/{code}/approve` | member | Pairs the account with the member → `{ identity }` |
|
|
1397
|
+
| `POST /api/ontology/agent/identities/resolve` | agent | Admission and turn limits; see below |
|
|
1398
|
+
| `POST /api/ontology/agent/identities/notice` | agent | `{ provider, external_id, sha256, version? }` acknowledges notice delivery: 204 |
|
|
1399
|
+
| `GET /api/ontology/agent/identities/{provider}/{external_id}` | agent | `{ user: { id, name }, roles, agent_tools }`; 404 unpaired, 403 revoked, inactive |
|
|
1400
|
+
| `GET /api/ontology/agent/identities` | member | `{ identities }`: the member's live identities |
|
|
1401
|
+
| `DELETE /api/ontology/agent/identities/{id}` | member | Revokes one of them: 204 |
|
|
1402
|
+
| `POST /api/ontology/agent/chats/seen` | agent | `{ provider, externalId, title, memberId?, leftMemberId?, agentLeft?, migratedFrom? }` → `{ id, title, purpose, whenToUse, handled? }` |
|
|
1395
1403
|
|
|
1396
1404
|
A pairing code is eight characters without look-alikes (no 0, O, 1, I or L), stored as its
|
|
1397
1405
|
SHA-256, valid ten minutes and used once. Each instance allows a client address 60 new
|
|
@@ -1411,8 +1419,10 @@ database an earlier SDK migrated. Additive migrations also create `_agent_counte
|
|
|
1411
1419
|
display?, username?, notice_version?, notice_sha256?, limits? }` with a verified runtime token.
|
|
1412
1420
|
It returns 200 with `status`:
|
|
1413
1421
|
|
|
1414
|
-
- `created` or `existing`: `{ user: { id, name }, roles, agent_tools, provisioned, notice_due, on_new_user_pending }`.
|
|
1422
|
+
- `created` or `existing`: `{ user: { id, name }, roles, agent_tools, provisioned, notice_due, on_new_user_pending, inbox?, takeover? }`.
|
|
1415
1423
|
`agent_tools` names the agent's own tools the user's roles grant, such as `sandbox`.
|
|
1424
|
+
`inbox: true` asks the agent to report the private chat to `chats/seen`; `takeover: true` asks it to
|
|
1425
|
+
report every message there, and to answer none while the report says `handled: true`.
|
|
1416
1426
|
The optional onboarding hook has already been attempted before this response; pending means retry.
|
|
1417
1427
|
- `pairing_required`: unknown account on an invited channel, in a group, or with `turn: false`.
|
|
1418
1428
|
- `refused`: `{ reason: "blocked" | "inactive" }`; revoked bindings also return `blocked` and never re-create.
|
|
@@ -1515,7 +1525,8 @@ old id of a group that became a supergroup, it moves the old record to `external
|
|
|
1515
1525
|
both are recorded, moves the members and a missing `purpose` and `whenToUse` to the new one and
|
|
1516
1526
|
deletes the old one. `provider`, `externalId`, `title` and `lastMessageAt` are
|
|
1517
1527
|
managed. Members set `purpose` and `whenToUse` with the generated
|
|
1518
|
-
`agent_chat.update`, the chat's only generated action
|
|
1528
|
+
`agent_chat.update`, the chat's only generated action, which sets no relationship: `handledBy`
|
|
1529
|
+
changes only through `agent_chat.takeOver` and `agent_chat.handBack`. Chat read/update permissions remain
|
|
1519
1530
|
`agent_chat:read` and `agent_chat:update`, granted explicitly; wildcard entity grants do not
|
|
1520
1531
|
cover this built-in registry.
|
|
1521
1532
|
|
package/dist/action.d.ts
CHANGED
|
@@ -134,10 +134,10 @@ interface ActionOptions<Input extends Schema.Top> {
|
|
|
134
134
|
readonly retryOnDeadlock?: boolean;
|
|
135
135
|
/**
|
|
136
136
|
* The entities the handler writes, such as `[self, Note]`; a thunk (`() => Note`) names an entity
|
|
137
|
-
* a circular import has not defined yet
|
|
138
|
-
*
|
|
139
|
-
* is declared. `[]` declares an action
|
|
140
|
-
* entity, as before.
|
|
137
|
+
* a circular import has not defined yet, and a name (`"note"`) one the module does not import.
|
|
138
|
+
* The runtime refuses any other write of the handler, the manifest lists them, and agents read
|
|
139
|
+
* them in the action's description, so "what changes what" is declared. `[]` declares an action
|
|
140
|
+
* that writes nothing. Absent, the handler may write any entity, as before.
|
|
141
141
|
*/
|
|
142
142
|
readonly writes?: ReadonlyArray<ActionWriteTarget>;
|
|
143
143
|
/**
|
|
@@ -149,8 +149,13 @@ interface ActionOptions<Input extends Schema.Top> {
|
|
|
149
149
|
*/
|
|
150
150
|
readonly confirm?: (context: ConfirmContext<Input["Type"]>) => Effect.Effect<ActionConfirmation, ActionError, OntologyReads>;
|
|
151
151
|
}
|
|
152
|
-
/**
|
|
153
|
-
|
|
152
|
+
/**
|
|
153
|
+
* An entity an action writes: its handle, a thunk returning it for a circular import, or its name
|
|
154
|
+
* as `entity(name, …)` declares it, in its authored or snake_case spelling (`"staffMember"` or
|
|
155
|
+
* `"staff_member"`). A name is any string here, since an action is declared before the ontology
|
|
156
|
+
* that lists its entities; `check` refuses one that names no stored entity of the ontology.
|
|
157
|
+
*/
|
|
158
|
+
export type ActionWriteTarget = AnyEntity | (() => AnyEntity) | string;
|
|
154
159
|
export interface ActionConfig<Input extends Schema.Top, Result> extends ActionOptions<Input> {
|
|
155
160
|
/**
|
|
156
161
|
* Runs inside the action's transaction. It reads and writes through entity handles (`Lead.get`,
|
package/dist/agent-chat.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Schema } from "effect";
|
|
1
2
|
export declare const TELEGRAM = "telegram";
|
|
2
3
|
/** Existing chat registry and membership storage; delivery lives in the ontology service. */
|
|
3
4
|
export declare const AgentChat: import("./entity.js").Entity<"agent_chat", {
|
|
@@ -5,25 +6,38 @@ export declare const AgentChat: import("./entity.js").Entity<"agent_chat", {
|
|
|
5
6
|
readonly kind: import("./property.js").Property<"group" | "private", true, false>;
|
|
6
7
|
readonly externalId: import("./property.js").Property<string, false, false>;
|
|
7
8
|
readonly title: import("./property.js").Property<string, false, false>;
|
|
8
|
-
readonly recipient:
|
|
9
|
-
readonly threadId:
|
|
10
|
-
readonly lastMessageAt:
|
|
11
|
-
readonly purpose:
|
|
12
|
-
readonly whenToUse:
|
|
9
|
+
readonly recipient: Schema.optionalKey<import("./property.js").Property<string, false, false>>;
|
|
10
|
+
readonly threadId: Schema.optionalKey<import("./property.js").Property<string, false, false>>;
|
|
11
|
+
readonly lastMessageAt: Schema.optionalKey<import("./property.js").Property<string, false, false>>;
|
|
12
|
+
readonly purpose: Schema.optionalKey<import("./property.js").Property<string, false, false>>;
|
|
13
|
+
readonly whenToUse: Schema.optionalKey<import("./property.js").Property<string, false, false>>;
|
|
13
14
|
}, {
|
|
14
15
|
readonly members: import("./relationship.js").ManyRelationship;
|
|
16
|
+
readonly handledBy: import("./relationship.js").OneRelationship<true, false, "user">;
|
|
15
17
|
}, import("./entity.js").InvocableActions<{
|
|
16
|
-
readonly
|
|
17
|
-
readonly chat:
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
18
|
+
readonly takeOver: import("./action.js").Action<Schema.Struct<{
|
|
19
|
+
readonly chat: Schema.Codec<string, string, never, never>;
|
|
20
|
+
}>, {
|
|
21
|
+
chat: string;
|
|
22
|
+
handled_by: string;
|
|
23
|
+
}>;
|
|
24
|
+
readonly handBack: import("./action.js").Action<Schema.Struct<{
|
|
25
|
+
readonly chat: Schema.Codec<string, string, never, never>;
|
|
26
|
+
}>, {
|
|
27
|
+
chat: string;
|
|
28
|
+
handled_by: null;
|
|
29
|
+
}>;
|
|
30
|
+
readonly previewMessage: import("./action.js").Action<Schema.Struct<{
|
|
31
|
+
readonly chat: Schema.String;
|
|
32
|
+
readonly text: Schema.String;
|
|
33
|
+
readonly replyTo: Schema.optionalKey<Schema.String>;
|
|
34
|
+
readonly idempotencyKey: Schema.String;
|
|
21
35
|
}>, import("./chat.js").ChatPreview>;
|
|
22
|
-
readonly postMessage: import("./action.js").Action<
|
|
23
|
-
readonly chat:
|
|
24
|
-
readonly text:
|
|
25
|
-
readonly replyTo:
|
|
26
|
-
readonly idempotencyKey:
|
|
36
|
+
readonly postMessage: import("./action.js").Action<Schema.Struct<{
|
|
37
|
+
readonly chat: Schema.String;
|
|
38
|
+
readonly text: Schema.String;
|
|
39
|
+
readonly replyTo: Schema.optionalKey<Schema.String>;
|
|
40
|
+
readonly idempotencyKey: Schema.String;
|
|
27
41
|
}>, {
|
|
28
42
|
readonly status: "sent" | "uncertain";
|
|
29
43
|
readonly message_id: string | null;
|
|
@@ -46,5 +60,6 @@ export declare const AgentChat: import("./entity.js").Entity<"agent_chat", {
|
|
|
46
60
|
readonly lastMessageAt: string | null;
|
|
47
61
|
readonly purpose: string | null;
|
|
48
62
|
readonly whenToUse: string | null;
|
|
63
|
+
readonly handledById: string | null;
|
|
49
64
|
}>, Readonly<Record<never, never>>, "generated">;
|
|
50
65
|
export type AgentChat = typeof AgentChat.Type;
|
package/dist/agent-chat.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Effect, Option } from "effect";
|
|
1
|
+
import { Effect, Option, Schema } from "effect";
|
|
2
2
|
import { action } from "./action.js";
|
|
3
3
|
import { entity } from "./entity.js";
|
|
4
4
|
import { ActionRejected } from "./errors.js";
|
|
@@ -72,9 +72,73 @@ export const AgentChat = entity("agent_chat", {
|
|
|
72
72
|
description: "Workspace members the agent has seen writing in the chat; a private chat's one member " +
|
|
73
73
|
"is its person.",
|
|
74
74
|
}),
|
|
75
|
+
handledBy: rel.one("user", {
|
|
76
|
+
optional: true,
|
|
77
|
+
inverse: "handledAgentChats",
|
|
78
|
+
onDelete: "setNull",
|
|
79
|
+
phrase: ["is handled by", "handles"],
|
|
80
|
+
description: "The member of staff who took the chat over from the agent: while set, the agent records " +
|
|
81
|
+
"the person's messages and answers none of them. Empty while the agent answers.",
|
|
82
|
+
}),
|
|
75
83
|
},
|
|
76
84
|
indexes: [{ properties: ["provider", "externalId"], unique: true }],
|
|
77
|
-
}).actions(() => ({
|
|
85
|
+
}).actions((self) => ({
|
|
86
|
+
takeOver: action({
|
|
87
|
+
description: "Take a person's private chat over from the agent, as yourself: until a member hands it " +
|
|
88
|
+
"back, the agent records the person's messages and answers none of them, and staff answer " +
|
|
89
|
+
"with postMessage. Refused for a group chat, for a chat on a channel the ontology's " +
|
|
90
|
+
"inbox.takeover does not list, and for a chat another member took over; taking over a " +
|
|
91
|
+
"chat you hold changes nothing.",
|
|
92
|
+
hints: { destructive: false, irreversible: false, idempotent: true },
|
|
93
|
+
input: Schema.Struct({ chat: self.ref }),
|
|
94
|
+
handler: ({ input, principal }) => Effect.gen(function* () {
|
|
95
|
+
const delivery = yield* Effect.serviceOption(ChatDelivery);
|
|
96
|
+
const channels = Option.isSome(delivery) ? delivery.value.takeoverChannels : undefined;
|
|
97
|
+
if (principal.kind !== "member") {
|
|
98
|
+
return yield* new ActionRejected({ message: "Only a member takes a chat over." });
|
|
99
|
+
}
|
|
100
|
+
if (channels === undefined) {
|
|
101
|
+
return yield* new ActionRejected({
|
|
102
|
+
message: "Taking a chat over requires the authenticated ontology service.",
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
const chat = yield* self.get(input.chat, { forUpdate: true });
|
|
106
|
+
if (chat.kind !== "private") {
|
|
107
|
+
return yield* new ActionRejected({
|
|
108
|
+
message: "Only a person's private chat is taken over: in a group the agent answers " +
|
|
109
|
+
"only those who address it.",
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
if (!channels.has(chat.provider)) {
|
|
113
|
+
return yield* new ActionRejected({
|
|
114
|
+
message: `Chats on ${chat.provider} are not taken over: inbox.takeover does not list ` +
|
|
115
|
+
"the channel.",
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
if (chat.handledById !== null && chat.handledById !== principal.id) {
|
|
119
|
+
return yield* new ActionRejected({
|
|
120
|
+
message: "Another member has taken the chat over: hand it back first.",
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
if (chat.handledById === null) {
|
|
124
|
+
yield* self.update(chat, { handledBy: principal.id });
|
|
125
|
+
}
|
|
126
|
+
return { chat: chat.id, handled_by: principal.id };
|
|
127
|
+
}),
|
|
128
|
+
}),
|
|
129
|
+
handBack: action({
|
|
130
|
+
description: "Hand a chat a member took over back to the agent, which answers the person's next " +
|
|
131
|
+
"message with what was said meanwhile in its context. A chat no one holds changes nothing.",
|
|
132
|
+
hints: { destructive: false, irreversible: false, idempotent: true },
|
|
133
|
+
input: Schema.Struct({ chat: self.ref }),
|
|
134
|
+
handler: ({ input }) => Effect.gen(function* () {
|
|
135
|
+
const chat = yield* self.get(input.chat, { forUpdate: true });
|
|
136
|
+
if (chat.handledById !== null) {
|
|
137
|
+
yield* self.update(chat, { handledBy: null });
|
|
138
|
+
}
|
|
139
|
+
return { chat: chat.id, handled_by: null };
|
|
140
|
+
}),
|
|
141
|
+
}),
|
|
78
142
|
previewMessage: action({
|
|
79
143
|
description: "Render an exact chat message with its verified destination and sender attribution, without reserving a key, " +
|
|
80
144
|
"writing history or sending. Requires the same explicit post permission as delivery. " +
|
package/dist/analyze.d.ts
CHANGED
|
@@ -233,6 +233,10 @@ export interface Analysis {
|
|
|
233
233
|
/** The wire names of the roles whose private chats join the inbox, when declared. */
|
|
234
234
|
readonly inbox?: {
|
|
235
235
|
readonly roles: ReadonlyArray<string>;
|
|
236
|
+
/** The channels whose private chats staff may take over from the agent. */
|
|
237
|
+
readonly takeover: {
|
|
238
|
+
readonly channels: ReadonlyArray<string>;
|
|
239
|
+
};
|
|
236
240
|
};
|
|
237
241
|
readonly entities: ReadonlyArray<ResolvedEntity>;
|
|
238
242
|
/** The workspace-owned `member` role and declared roles, then the implicit reporter when enabled. */
|
package/dist/analyze.js
CHANGED
|
@@ -102,7 +102,11 @@ export function analyze(config, options = {}) {
|
|
|
102
102
|
...(linkEmail === undefined ? {} : { linkEmail }),
|
|
103
103
|
...(codeEmail === undefined ? {} : { codeEmail }),
|
|
104
104
|
};
|
|
105
|
-
const inbox = inboxOptions(config.inbox, declaredRoles, guest !== undefined,
|
|
105
|
+
const inbox = inboxOptions(config.inbox, declaredRoles, guest !== undefined, isPlainObject(config.chat)
|
|
106
|
+
? Object.entries(config.chat)
|
|
107
|
+
.filter(([name, channel]) => name !== "attribution" && channel !== undefined)
|
|
108
|
+
.map(([name]) => name)
|
|
109
|
+
: [], report);
|
|
106
110
|
const discovery = config.discovery;
|
|
107
111
|
if (discovery !== undefined &&
|
|
108
112
|
(!isPlainObject(discovery) ||
|
|
@@ -349,21 +353,25 @@ export function analyze(config, options = {}) {
|
|
|
349
353
|
}
|
|
350
354
|
/**
|
|
351
355
|
* `inbox`: the wire names of the roles whose private chats join the inbox, each a declared role or
|
|
352
|
-
* `member
|
|
356
|
+
* `member`, and the channels whose chats staff may take over: those `takeover.channels` lists, or
|
|
357
|
+
* every channel `chat` declares; `undefined` when absent or malformed.
|
|
353
358
|
*/
|
|
354
359
|
function inboxOptions(value, declaredRoles,
|
|
355
360
|
/** Whether the ontology declares `guest`, whose visitors' chats the inbox may take. */
|
|
356
|
-
guests,
|
|
361
|
+
guests,
|
|
362
|
+
/** The names of the channels `chat` declares. */
|
|
363
|
+
chatChannels, report) {
|
|
357
364
|
if (value === undefined) {
|
|
358
365
|
return undefined;
|
|
359
366
|
}
|
|
360
367
|
if (!isPlainObject(value) ||
|
|
361
|
-
Object.keys(value).some((key) => key !== "roles") ||
|
|
368
|
+
Object.keys(value).some((key) => key !== "roles" && key !== "takeover") ||
|
|
362
369
|
!Array.isArray(value.roles) ||
|
|
363
370
|
value.roles.length === 0) {
|
|
364
|
-
report("invalid-inbox", "inbox", "inbox takes { roles: [...] }, at least one role.");
|
|
371
|
+
report("invalid-inbox", "inbox", "inbox takes { roles: [...], takeover?: { channels?: [...] } }, at least one role.");
|
|
365
372
|
return undefined;
|
|
366
373
|
}
|
|
374
|
+
const takeover = takeoverOptions(value.takeover, chatChannels, report);
|
|
367
375
|
const declared = new Set(declaredRoles.map((candidate) => candidate.name));
|
|
368
376
|
if (guests) {
|
|
369
377
|
declared.add(GUEST_ROLE);
|
|
@@ -384,7 +392,43 @@ guests, report) {
|
|
|
384
392
|
roles.push(name);
|
|
385
393
|
}
|
|
386
394
|
});
|
|
387
|
-
return valid ? { roles } : undefined;
|
|
395
|
+
return valid && takeover !== undefined ? { roles, takeover } : undefined;
|
|
396
|
+
}
|
|
397
|
+
/**
|
|
398
|
+
* `inbox.takeover`: the channels whose private chats staff may take over from the agent, each a
|
|
399
|
+
* channel `chat` declares, since staff answer through it; every one of them when `channels` is
|
|
400
|
+
* absent. The website's chat is none of them: staff replies do not reach it yet.
|
|
401
|
+
*/
|
|
402
|
+
function takeoverOptions(value, chatChannels, report) {
|
|
403
|
+
if (value === undefined) {
|
|
404
|
+
return { channels: chatChannels };
|
|
405
|
+
}
|
|
406
|
+
if (!isPlainObject(value) ||
|
|
407
|
+
Object.keys(value).some((key) => key !== "channels") ||
|
|
408
|
+
(value.channels !== undefined && !Array.isArray(value.channels))) {
|
|
409
|
+
report("invalid-inbox", "inbox.takeover", "inbox.takeover takes { channels?: [...] }.");
|
|
410
|
+
return undefined;
|
|
411
|
+
}
|
|
412
|
+
if (value.channels === undefined) {
|
|
413
|
+
return { channels: chatChannels };
|
|
414
|
+
}
|
|
415
|
+
const channels = [];
|
|
416
|
+
let valid = true;
|
|
417
|
+
value.channels.forEach((candidate, index) => {
|
|
418
|
+
const path = `inbox.takeover.channels[${index}]`;
|
|
419
|
+
if (candidate === "web") {
|
|
420
|
+
report("invalid-inbox", path, "The website's chat is not taken over yet: staff replies do not reach it.");
|
|
421
|
+
valid = false;
|
|
422
|
+
}
|
|
423
|
+
else if (typeof candidate !== "string" || !chatChannels.includes(candidate)) {
|
|
424
|
+
report("invalid-inbox", path, "Use a channel chat declares: staff answer a chat they took over through it.");
|
|
425
|
+
valid = false;
|
|
426
|
+
}
|
|
427
|
+
else if (!channels.includes(candidate)) {
|
|
428
|
+
channels.push(candidate);
|
|
429
|
+
}
|
|
430
|
+
});
|
|
431
|
+
return valid ? { channels } : undefined;
|
|
388
432
|
}
|
|
389
433
|
/**
|
|
390
434
|
* Warns where workspace code declares a field by the name an earlier SDK gave it, naming the current
|
|
@@ -535,13 +579,19 @@ function resolveWorkflows(input) {
|
|
|
535
579
|
"no action, so the workflow can at most read; add the actions it runs to the role's " +
|
|
536
580
|
"permissions.", "warning");
|
|
537
581
|
}
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
582
|
+
// Only `me` depends on who runs: a scope on the records' own values, such as
|
|
583
|
+
// `{ purpose: { in: ["signing", "signed"] } }`, matches the same records for the workflow.
|
|
584
|
+
const scopedByMe = input.checkGrants && declared !== undefined && declared !== implicit
|
|
585
|
+
? [
|
|
586
|
+
...new Set((declared.scopes ?? [])
|
|
587
|
+
.filter((scope) => usesMe(scope.where))
|
|
588
|
+
.map((scope) => scope.permission)),
|
|
589
|
+
]
|
|
590
|
+
: [];
|
|
591
|
+
if (declared !== undefined && scopedByMe.length > 0) {
|
|
592
|
+
report("workflow_role_scoped", `${path}.role`, `${declared.name} scopes ${scopedByMe.join(", ")} with me, and bare me is the workflow ` +
|
|
593
|
+
"service user's ID. Paths from me require relationships of that service user; verify " +
|
|
594
|
+
"the scope matches the intended records.", "warning");
|
|
545
595
|
}
|
|
546
596
|
const schema = workflowInputSchema(candidate.input);
|
|
547
597
|
if (typeof schema !== "string" && "fields" in schema) {
|
package/dist/app-feedback.js
CHANGED
|
@@ -24,7 +24,7 @@ export const AppFeedback = entity("app_feedback", {
|
|
|
24
24
|
title: "title",
|
|
25
25
|
description: "Feedback a member sent the app's builders through an agent: something the app cannot do, a " +
|
|
26
26
|
"failure, or a change they want. Each member sees their own; the builders answer with a " +
|
|
27
|
-
"response,
|
|
27
|
+
"response, which the member's agent tells them when they ask.",
|
|
28
28
|
properties: {
|
|
29
29
|
title: p.text({ managed: true, maxLength: 200, description: "What the feedback is about." }),
|
|
30
30
|
body: p.text({
|
|
@@ -94,7 +94,7 @@ export const AppFeedback = entity("app_feedback", {
|
|
|
94
94
|
}),
|
|
95
95
|
respond: action({
|
|
96
96
|
description: "Answer a member's feedback as the app's builders: done or declined, with a response in the " +
|
|
97
|
-
"member's language that says what changed, or why not. Their agent
|
|
97
|
+
"member's language that says what changed, or why not. Their agent tells them when they ask.",
|
|
98
98
|
hints: { destructive: false },
|
|
99
99
|
input: Schema.Struct({
|
|
100
100
|
feedback: self.ref,
|
|
@@ -116,9 +116,10 @@ export const AppFeedback = entity("app_feedback", {
|
|
|
116
116
|
}),
|
|
117
117
|
}),
|
|
118
118
|
acknowledge: action({
|
|
119
|
-
description: "Record that the member has been told the builders' response to their feedback, passing
|
|
120
|
-
"responded_at of the response you reported.
|
|
121
|
-
"
|
|
119
|
+
description: "Record that the member has been told the builders' response to their own feedback, passing " +
|
|
120
|
+
"the responded_at of the response you reported. When they ask about their feedback, find " +
|
|
121
|
+
"their own items (reporter is their user id from me), tell them what was done, then call " +
|
|
122
|
+
"this. " +
|
|
122
123
|
"acknowledged is false when there is no such response, as when the builders answered again " +
|
|
123
124
|
"meanwhile: read the item again and report the newer response.",
|
|
124
125
|
hints: { destructive: false, idempotent: true },
|
package/dist/chat.d.ts
CHANGED
|
@@ -10,6 +10,14 @@ export interface ChatAttributionSettings {
|
|
|
10
10
|
*/
|
|
11
11
|
export interface InboxOptions<R = unknown> {
|
|
12
12
|
readonly roles: ReadonlyArray<R>;
|
|
13
|
+
/**
|
|
14
|
+
* Where staff may take a chat over from the agent, which then records the person's messages and
|
|
15
|
+
* answers none until a member hands it back: `channels` lists channels `chat` declares, `[]` for
|
|
16
|
+
* none; absent, every channel `chat` declares. The website's chat is none of them yet.
|
|
17
|
+
*/
|
|
18
|
+
readonly takeover?: {
|
|
19
|
+
readonly channels?: ReadonlyArray<string>;
|
|
20
|
+
};
|
|
13
21
|
}
|
|
14
22
|
import { Context, Effect, Schema } from "effect";
|
|
15
23
|
import type { ActionError } from "./errors.js";
|
|
@@ -60,6 +68,8 @@ declare const ChatDelivery_base: Context.ServiceClass<ChatDelivery, "@segmentstr
|
|
|
60
68
|
readonly post: (input: ChatPostInput) => Effect.Effect<ChatPostResult, ActionError>;
|
|
61
69
|
/** Sends a reply a member approved, as the agent and without attribution, at most once. */
|
|
62
70
|
readonly sendReview?: (input: ReviewSendInput) => Effect.Effect<ReviewSendResult, ActionError>;
|
|
71
|
+
/** The channels whose private chats staff may take over, as the ontology's inbox lists them. */
|
|
72
|
+
readonly takeoverChannels?: ReadonlySet<string>;
|
|
63
73
|
}>;
|
|
64
74
|
/** Deliver the exact Markdown source through the channel renderer, without invoking an agent. */
|
|
65
75
|
export declare class ChatDelivery extends ChatDelivery_base {
|
package/dist/index.d.ts
CHANGED
|
@@ -24,7 +24,7 @@ export type { ActionsBuilder, AnyEntity, ActionHandle, ActionInvoker, MetricQuer
|
|
|
24
24
|
export { ActionRejected, BatchErrorDetails, Conflict, DeploymentInterrupted, DeploymentSwitching, LimitErrorDetails, NotFound, PermissionDenied, ScopeViolated, } from "./errors.js";
|
|
25
25
|
export type { ActionError } from "./errors.js";
|
|
26
26
|
export { browserAuthenticationCompatible } from "./manifest-compatibility.js";
|
|
27
|
-
export { ActionManifest, actionConnectionKeys, canonicalJson, ConnectionManifest, EntityManifest, EntityPermissionsManifest, decodeManifestDocument, encodeManifest, formatManifest, IndexManifest, isValueMatched, MANIFEST_VERSION, manifestHash, ModelMetricManifest, OntologyManifest, OntologyManifestWire, PropertyManifest, RelationshipManifest, RoleManifest, ActionTriggerManifest, ScopeManifest, CronTriggerManifest, isActionTrigger, isCronTrigger, isWebhookTrigger, OtherTriggerManifest, WebhookTriggerManifest, WorkflowManifest, WorkflowTriggerManifest, SelectOptionManifest, SignInManifest, GuestManifest, guestOf, signInPolicyOf, channelPolicyOf, signUpOriginsOf, inboxRolesOf, signUpRolesOf, } from "./manifest.js";
|
|
27
|
+
export { ActionManifest, actionConnectionKeys, canonicalJson, ConnectionManifest, EntityManifest, EntityPermissionsManifest, decodeManifestDocument, encodeManifest, formatManifest, IndexManifest, isValueMatched, MANIFEST_VERSION, manifestHash, ModelMetricManifest, OntologyManifest, OntologyManifestWire, PropertyManifest, RelationshipManifest, RoleManifest, ActionTriggerManifest, ScopeManifest, CronTriggerManifest, isActionTrigger, isCronTrigger, isWebhookTrigger, OtherTriggerManifest, WebhookTriggerManifest, WorkflowManifest, WorkflowTriggerManifest, SelectOptionManifest, SignInManifest, GuestManifest, guestOf, signInPolicyOf, channelPolicyOf, signUpOriginsOf, inboxRolesOf, takeoverChannelsOf, signUpRolesOf, } from "./manifest.js";
|
|
28
28
|
export { SYSTEM_PROPERTIES } from "./names.js";
|
|
29
29
|
export type { SystemProperty } from "./names.js";
|
|
30
30
|
export { isMe, isMeMarker, MAX_ME_HOPS, me, ME_KEY, MeMarker, mePathOf, meToWire, MeTypeId, } from "./me.js";
|
|
@@ -78,6 +78,8 @@ export type { ActionRequest, AfterCommit, CommittedAction, FoundAction, } from "
|
|
|
78
78
|
export { API_KEY_ITERATIONS, API_KEY_PREFIX, checkSignIn, createApiKey, createServiceUser, findApiKey, generateApiKey, grantMemberRoles, hashApiKeySecret, implicitRoleNamesOf, listApiKeys, listMembers, countUsersWithoutEmailIdentity, countUsersWithoutSegmentStreamIdentity, MEMBER_HISTORY_ACTIONS, parseApiKey, principalsOntology, resolveApiKeyCredential, resolvePrincipalByApiKey, resolvePrincipalByIdentity, reconcileWorkflowUsers, resolveWorkflowUser, revokeApiKey, WORKFLOW_USER_PROVIDER, workflowSubject, revokeMemberRoles, setMemberActive, setMemberBlocked, revokeMemberSessions, setUserRoles, SIGN_IN_RECORD_INTERVAL_MS, updateMemberRoles, workflowRoles, } from "./runtime/principals.js";
|
|
79
79
|
export type { ApiKeyCredential, ApiKeyParts, ApiKeySummary, CreatedApiKey, IdentityClaims, MemberKey, MemberRolesChange, MemberStatus, MemberSummary, PrincipalsManifest, StoredRolesListing, } from "./runtime/principals.js";
|
|
80
80
|
export { backendLayer, postgresLayer, sqlServiceRuntime } from "./runtime/service-binding.js";
|
|
81
|
+
export { memoryFileStorage } from "./storage/memory.js";
|
|
82
|
+
export type { MemoryFileStorage, MemoryFileStorageOptions, MemoryFileUpload, StoredFile, UploadedFile, } from "./storage/memory.js";
|
|
81
83
|
export { makeOntologyRuntime } from "./runtime/sql-runtime.js";
|
|
82
84
|
export type { SqlOntologyRuntime, WriteScope } from "./runtime/sql-runtime.js";
|
|
83
85
|
export { BASE_PATH, deriveApi } from "./service/api.js";
|
package/dist/index.js
CHANGED
|
@@ -13,7 +13,7 @@ export { entity, isEntity } from "./entity.js";
|
|
|
13
13
|
export { isToolset, MCP_TOOL_NAME, TOOLSET_LOCK_VERSION, toolset, ToolsetLock, ToolsetLockTool, } from "./toolset.js";
|
|
14
14
|
export { ActionRejected, BatchErrorDetails, Conflict, DeploymentInterrupted, DeploymentSwitching, LimitErrorDetails, NotFound, PermissionDenied, ScopeViolated, } from "./errors.js";
|
|
15
15
|
export { browserAuthenticationCompatible } from "./manifest-compatibility.js";
|
|
16
|
-
export { ActionManifest, actionConnectionKeys, canonicalJson, ConnectionManifest, EntityManifest, EntityPermissionsManifest, decodeManifestDocument, encodeManifest, formatManifest, IndexManifest, isValueMatched, MANIFEST_VERSION, manifestHash, ModelMetricManifest, OntologyManifest, OntologyManifestWire, PropertyManifest, RelationshipManifest, RoleManifest, ActionTriggerManifest, ScopeManifest, CronTriggerManifest, isActionTrigger, isCronTrigger, isWebhookTrigger, OtherTriggerManifest, WebhookTriggerManifest, WorkflowManifest, WorkflowTriggerManifest, SelectOptionManifest, SignInManifest, GuestManifest, guestOf, signInPolicyOf, channelPolicyOf, signUpOriginsOf, inboxRolesOf, signUpRolesOf, } from "./manifest.js";
|
|
16
|
+
export { ActionManifest, actionConnectionKeys, canonicalJson, ConnectionManifest, EntityManifest, EntityPermissionsManifest, decodeManifestDocument, encodeManifest, formatManifest, IndexManifest, isValueMatched, MANIFEST_VERSION, manifestHash, ModelMetricManifest, OntologyManifest, OntologyManifestWire, PropertyManifest, RelationshipManifest, RoleManifest, ActionTriggerManifest, ScopeManifest, CronTriggerManifest, isActionTrigger, isCronTrigger, isWebhookTrigger, OtherTriggerManifest, WebhookTriggerManifest, WorkflowManifest, WorkflowTriggerManifest, SelectOptionManifest, SignInManifest, GuestManifest, guestOf, signInPolicyOf, channelPolicyOf, signUpOriginsOf, inboxRolesOf, takeoverChannelsOf, signUpRolesOf, } from "./manifest.js";
|
|
17
17
|
export { SYSTEM_PROPERTIES } from "./names.js";
|
|
18
18
|
export { isMe, isMeMarker, MAX_ME_HOPS, me, ME_KEY, MeMarker, mePathOf, meToWire, MeTypeId, } from "./me.js";
|
|
19
19
|
export { check, defineOntology } from "./ontology.js";
|
|
@@ -48,6 +48,8 @@ export { Change, Edit, EditKind, HistoryEntry } from "./runtime/history.js";
|
|
|
48
48
|
export { ActionOutcome, ActionValidation, findAction, PREPARE_TIMEOUT, resolveAction, runAction, } from "./runtime/pipeline.js";
|
|
49
49
|
export { API_KEY_ITERATIONS, API_KEY_PREFIX, checkSignIn, createApiKey, createServiceUser, findApiKey, generateApiKey, grantMemberRoles, hashApiKeySecret, implicitRoleNamesOf, listApiKeys, listMembers, countUsersWithoutEmailIdentity, countUsersWithoutSegmentStreamIdentity, MEMBER_HISTORY_ACTIONS, parseApiKey, principalsOntology, resolveApiKeyCredential, resolvePrincipalByApiKey, resolvePrincipalByIdentity, reconcileWorkflowUsers, resolveWorkflowUser, revokeApiKey, WORKFLOW_USER_PROVIDER, workflowSubject, revokeMemberRoles, setMemberActive, setMemberBlocked, revokeMemberSessions, setUserRoles, SIGN_IN_RECORD_INTERVAL_MS, updateMemberRoles, workflowRoles, } from "./runtime/principals.js";
|
|
50
50
|
export { backendLayer, postgresLayer, sqlServiceRuntime } from "./runtime/service-binding.js";
|
|
51
|
+
// File storage in memory, for tests that run actions with files in process.
|
|
52
|
+
export { memoryFileStorage } from "./storage/memory.js";
|
|
51
53
|
export { makeOntologyRuntime } from "./runtime/sql-runtime.js";
|
|
52
54
|
// The HTTP service derived from the ontology.
|
|
53
55
|
export { BASE_PATH, deriveApi } from "./service/api.js";
|