@segmentstream/ontology 0.123.0 → 0.125.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 +21 -0
- package/README.md +17 -13
- package/dist/agent-chat.d.ts +34 -15
- package/dist/agent-chat.js +88 -2
- package/dist/analyze.d.ts +4 -0
- package/dist/analyze.js +50 -6
- package/dist/chat.d.ts +10 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/manifest.d.ts +60 -7
- package/dist/manifest.js +37 -6
- package/dist/migrate/model.d.ts +24 -0
- package/dist/runtime/agents.js +76 -6
- package/dist/runtime/generated-actions.js +5 -0
- package/dist/service/agent/protocol.d.ts +10 -0
- package/dist/service/agent/protocol.js +12 -0
- package/dist/service/agent/server.js +32 -1
- package/dist/service/chat/delivery.js +3 -0
- package/dist/service/runtime-contract.d.ts +35 -1
- package/dist/service/schemas.d.ts +6 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,26 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.125.0
|
|
4
|
+
|
|
5
|
+
The agent hands a person's private chat over to staff. `agent_chat` gains `handoffAt` and
|
|
6
|
+
`handoffReason`, set through the runtime route `POST /api/ontology/agent/chats/handoff` for a
|
|
7
|
+
registered private chat on a channel `inbox.takeover` lists, for its own person only; a second
|
|
8
|
+
handoff keeps the first one's time and reason. While a handoff waits, the report of the chat says
|
|
9
|
+
`handled: true`, so the agent answers none of the person's messages. `takeOver` answers the handoff
|
|
10
|
+
and clears both fields, as does `handBack`, which returns the chat to the agent.
|
|
11
|
+
|
|
12
|
+
## 0.124.0
|
|
13
|
+
|
|
14
|
+
Staff take an inbox chat over from the agent. `agent_chat.takeOver({ chat })` sets the record's new
|
|
15
|
+
`handledBy` relationship to the member (`agent_chat:take_over`), `agent_chat.handBack({ chat })`
|
|
16
|
+
clears it (`agent_chat:hand_back`), and a chat another member holds is refused until it is handed
|
|
17
|
+
back. `inbox.takeover.channels` names the channels of `chat` where staff take chats over: every one
|
|
18
|
+
of them when absent, none with `[]`; `check` reports `invalid-inbox` for an undeclared channel and
|
|
19
|
+
for `web`, whose visitors' page staff replies do not reach yet. Where takeover is open, the answer
|
|
20
|
+
to the agent's admission says `takeover: true` and the report of a private chat says
|
|
21
|
+
`handled: true` while staff hold it. The generated `update` of a built-in entity no longer takes
|
|
22
|
+
its relationships.
|
|
23
|
+
|
|
3
24
|
## 0.123.0
|
|
4
25
|
|
|
5
26
|
`memoryFileStorage()` keeps an ontology's files in memory, so tests that run actions in process can
|
package/README.md
CHANGED
|
@@ -1389,17 +1389,18 @@ task header on any other route are a 403.
|
|
|
1389
1389
|
|
|
1390
1390
|
Without either header the agent may call only the agent routes:
|
|
1391
1391
|
|
|
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 }` |
|
|
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? }` |
|
|
1403
|
+
| `POST /api/ontology/agent/chats/handoff` | agent | `{ provider, externalId, memberId, reason }` → `{ id, handoffAt, handled? }`; 404 for a chat staff do not take over |
|
|
1403
1404
|
|
|
1404
1405
|
A pairing code is eight characters without look-alikes (no 0, O, 1, I or L), stored as its
|
|
1405
1406
|
SHA-256, valid ten minutes and used once. Each instance allows a client address 60 new
|
|
@@ -1419,8 +1420,10 @@ database an earlier SDK migrated. Additive migrations also create `_agent_counte
|
|
|
1419
1420
|
display?, username?, notice_version?, notice_sha256?, limits? }` with a verified runtime token.
|
|
1420
1421
|
It returns 200 with `status`:
|
|
1421
1422
|
|
|
1422
|
-
- `created` or `existing`: `{ user: { id, name }, roles, agent_tools, provisioned, notice_due, on_new_user_pending }`.
|
|
1423
|
+
- `created` or `existing`: `{ user: { id, name }, roles, agent_tools, provisioned, notice_due, on_new_user_pending, inbox?, takeover? }`.
|
|
1423
1424
|
`agent_tools` names the agent's own tools the user's roles grant, such as `sandbox`.
|
|
1425
|
+
`inbox: true` asks the agent to report the private chat to `chats/seen`; `takeover: true` asks it to
|
|
1426
|
+
report every message there, and to answer none while the report says `handled: true`.
|
|
1424
1427
|
The optional onboarding hook has already been attempted before this response; pending means retry.
|
|
1425
1428
|
- `pairing_required`: unknown account on an invited channel, in a group, or with `turn: false`.
|
|
1426
1429
|
- `refused`: `{ reason: "blocked" | "inactive" }`; revoked bindings also return `blocked` and never re-create.
|
|
@@ -1523,7 +1526,8 @@ old id of a group that became a supergroup, it moves the old record to `external
|
|
|
1523
1526
|
both are recorded, moves the members and a missing `purpose` and `whenToUse` to the new one and
|
|
1524
1527
|
deletes the old one. `provider`, `externalId`, `title` and `lastMessageAt` are
|
|
1525
1528
|
managed. Members set `purpose` and `whenToUse` with the generated
|
|
1526
|
-
`agent_chat.update`, the chat's only generated action
|
|
1529
|
+
`agent_chat.update`, the chat's only generated action, which sets no relationship: `handledBy`
|
|
1530
|
+
changes only through `agent_chat.takeOver` and `agent_chat.handBack`. Chat read/update permissions remain
|
|
1527
1531
|
`agent_chat:read` and `agent_chat:update`, granted explicitly; wildcard entity grants do not
|
|
1528
1532
|
cover this built-in registry.
|
|
1529
1533
|
|
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,40 @@ 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
|
|
12
|
-
readonly
|
|
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 handoffAt: Schema.optionalKey<import("./property.js").Property<string, false, false>>;
|
|
13
|
+
readonly handoffReason: Schema.optionalKey<import("./property.js").Property<string, false, false>>;
|
|
14
|
+
readonly purpose: Schema.optionalKey<import("./property.js").Property<string, false, false>>;
|
|
15
|
+
readonly whenToUse: Schema.optionalKey<import("./property.js").Property<string, false, false>>;
|
|
13
16
|
}, {
|
|
14
17
|
readonly members: import("./relationship.js").ManyRelationship;
|
|
18
|
+
readonly handledBy: import("./relationship.js").OneRelationship<true, false, "user">;
|
|
15
19
|
}, import("./entity.js").InvocableActions<{
|
|
16
|
-
readonly
|
|
17
|
-
readonly chat:
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
20
|
+
readonly takeOver: import("./action.js").Action<Schema.Struct<{
|
|
21
|
+
readonly chat: Schema.Codec<string, string, never, never>;
|
|
22
|
+
}>, {
|
|
23
|
+
chat: string;
|
|
24
|
+
handled_by: string;
|
|
25
|
+
}>;
|
|
26
|
+
readonly handBack: import("./action.js").Action<Schema.Struct<{
|
|
27
|
+
readonly chat: Schema.Codec<string, string, never, never>;
|
|
28
|
+
}>, {
|
|
29
|
+
chat: string;
|
|
30
|
+
handled_by: null;
|
|
31
|
+
}>;
|
|
32
|
+
readonly previewMessage: import("./action.js").Action<Schema.Struct<{
|
|
33
|
+
readonly chat: Schema.String;
|
|
34
|
+
readonly text: Schema.String;
|
|
35
|
+
readonly replyTo: Schema.optionalKey<Schema.String>;
|
|
36
|
+
readonly idempotencyKey: Schema.String;
|
|
21
37
|
}>, import("./chat.js").ChatPreview>;
|
|
22
|
-
readonly postMessage: import("./action.js").Action<
|
|
23
|
-
readonly chat:
|
|
24
|
-
readonly text:
|
|
25
|
-
readonly replyTo:
|
|
26
|
-
readonly idempotencyKey:
|
|
38
|
+
readonly postMessage: import("./action.js").Action<Schema.Struct<{
|
|
39
|
+
readonly chat: Schema.String;
|
|
40
|
+
readonly text: Schema.String;
|
|
41
|
+
readonly replyTo: Schema.optionalKey<Schema.String>;
|
|
42
|
+
readonly idempotencyKey: Schema.String;
|
|
27
43
|
}>, {
|
|
28
44
|
readonly status: "sent" | "uncertain";
|
|
29
45
|
readonly message_id: string | null;
|
|
@@ -44,7 +60,10 @@ export declare const AgentChat: import("./entity.js").Entity<"agent_chat", {
|
|
|
44
60
|
readonly recipient: string | null;
|
|
45
61
|
readonly threadId: string | null;
|
|
46
62
|
readonly lastMessageAt: string | null;
|
|
63
|
+
readonly handoffAt: string | null;
|
|
64
|
+
readonly handoffReason: string | null;
|
|
47
65
|
readonly purpose: string | null;
|
|
48
66
|
readonly whenToUse: string | null;
|
|
67
|
+
readonly handledById: string | null;
|
|
49
68
|
}>, Readonly<Record<never, never>>, "generated">;
|
|
50
69
|
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";
|
|
@@ -50,6 +50,22 @@ export const AgentChat = entity("agent_chat", {
|
|
|
50
50
|
label: "Last message",
|
|
51
51
|
description: "When the agent last saw a message in the chat, recorded at most every 15 minutes.",
|
|
52
52
|
}),
|
|
53
|
+
handoffAt: p.timestamp({
|
|
54
|
+
optional: true,
|
|
55
|
+
managed: true,
|
|
56
|
+
label: "Handed off",
|
|
57
|
+
description: "When the agent handed the person over to staff: until a member takes the chat over or " +
|
|
58
|
+
"hands it back, the agent records the person's messages and answers none of them. Empty " +
|
|
59
|
+
"otherwise.",
|
|
60
|
+
}),
|
|
61
|
+
handoffReason: p.text({
|
|
62
|
+
optional: true,
|
|
63
|
+
managed: true,
|
|
64
|
+
maxLength: 1000,
|
|
65
|
+
display: "multiline",
|
|
66
|
+
label: "Handoff reason",
|
|
67
|
+
description: "What the agent said the person needs from staff when it handed them over.",
|
|
68
|
+
}),
|
|
53
69
|
purpose: p.text({
|
|
54
70
|
optional: true,
|
|
55
71
|
maxLength: 64,
|
|
@@ -72,9 +88,79 @@ export const AgentChat = entity("agent_chat", {
|
|
|
72
88
|
description: "Workspace members the agent has seen writing in the chat; a private chat's one member " +
|
|
73
89
|
"is its person.",
|
|
74
90
|
}),
|
|
91
|
+
handledBy: rel.one("user", {
|
|
92
|
+
optional: true,
|
|
93
|
+
inverse: "handledAgentChats",
|
|
94
|
+
onDelete: "setNull",
|
|
95
|
+
phrase: ["is handled by", "handles"],
|
|
96
|
+
description: "The member of staff who took the chat over from the agent: while set, the agent records " +
|
|
97
|
+
"the person's messages and answers none of them. Empty while the agent answers.",
|
|
98
|
+
}),
|
|
75
99
|
},
|
|
76
100
|
indexes: [{ properties: ["provider", "externalId"], unique: true }],
|
|
77
|
-
}).actions(() => ({
|
|
101
|
+
}).actions((self) => ({
|
|
102
|
+
takeOver: action({
|
|
103
|
+
description: "Take a person's private chat over from the agent, as yourself, also when the agent handed " +
|
|
104
|
+
"the person over: until a member hands it back, the agent records the person's messages " +
|
|
105
|
+
"and answers none of them, and staff answer with postMessage. Refused for a group chat, " +
|
|
106
|
+
"for a chat on a channel the ontology's inbox.takeover does not list, and for a chat " +
|
|
107
|
+
"another member took over; taking over a chat you hold changes nothing.",
|
|
108
|
+
hints: { destructive: false, irreversible: false, idempotent: true },
|
|
109
|
+
input: Schema.Struct({ chat: self.ref }),
|
|
110
|
+
handler: ({ input, principal }) => Effect.gen(function* () {
|
|
111
|
+
const delivery = yield* Effect.serviceOption(ChatDelivery);
|
|
112
|
+
const channels = Option.isSome(delivery) ? delivery.value.takeoverChannels : undefined;
|
|
113
|
+
if (principal.kind !== "member") {
|
|
114
|
+
return yield* new ActionRejected({ message: "Only a member takes a chat over." });
|
|
115
|
+
}
|
|
116
|
+
if (channels === undefined) {
|
|
117
|
+
return yield* new ActionRejected({
|
|
118
|
+
message: "Taking a chat over requires the authenticated ontology service.",
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
const chat = yield* self.get(input.chat, { forUpdate: true });
|
|
122
|
+
if (chat.kind !== "private") {
|
|
123
|
+
return yield* new ActionRejected({
|
|
124
|
+
message: "Only a person's private chat is taken over: in a group the agent answers " +
|
|
125
|
+
"only those who address it.",
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
if (!channels.has(chat.provider)) {
|
|
129
|
+
return yield* new ActionRejected({
|
|
130
|
+
message: `Chats on ${chat.provider} are not taken over: inbox.takeover does not list ` +
|
|
131
|
+
"the channel.",
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
if (chat.handledById !== null && chat.handledById !== principal.id) {
|
|
135
|
+
return yield* new ActionRejected({
|
|
136
|
+
message: "Another member has taken the chat over: hand it back first.",
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
// Taking the chat over answers the agent's handoff, if it handed the person over.
|
|
140
|
+
if (chat.handledById === null || chat.handoffAt !== null) {
|
|
141
|
+
yield* self.update(chat, {
|
|
142
|
+
handledBy: principal.id,
|
|
143
|
+
handoffAt: null,
|
|
144
|
+
handoffReason: null,
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
return { chat: chat.id, handled_by: principal.id };
|
|
148
|
+
}),
|
|
149
|
+
}),
|
|
150
|
+
handBack: action({
|
|
151
|
+
description: "Hand a chat a member took over, or the agent handed over to staff, back to the agent, " +
|
|
152
|
+
"which answers the person's next message with what was said meanwhile in its context. A " +
|
|
153
|
+
"chat no one holds and no handoff waits on changes nothing.",
|
|
154
|
+
hints: { destructive: false, irreversible: false, idempotent: true },
|
|
155
|
+
input: Schema.Struct({ chat: self.ref }),
|
|
156
|
+
handler: ({ input }) => Effect.gen(function* () {
|
|
157
|
+
const chat = yield* self.get(input.chat, { forUpdate: true });
|
|
158
|
+
if (chat.handledById !== null || chat.handoffAt !== null) {
|
|
159
|
+
yield* self.update(chat, { handledBy: null, handoffAt: null, handoffReason: null });
|
|
160
|
+
}
|
|
161
|
+
return { chat: chat.id, handled_by: null };
|
|
162
|
+
}),
|
|
163
|
+
}),
|
|
78
164
|
previewMessage: action({
|
|
79
165
|
description: "Render an exact chat message with its verified destination and sender attribution, without reserving a key, " +
|
|
80
166
|
"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
|
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";
|
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";
|
package/dist/manifest.d.ts
CHANGED
|
@@ -91,7 +91,8 @@ import { type ResolvedGuest, type ResolvedSignInOptions, type SignInPolicy } fro
|
|
|
91
91
|
* `channel:<name>`, its people's accounts.
|
|
92
92
|
* Within version 15, the top-level `inbox`, written only when declared, holds the wire names of the
|
|
93
93
|
* `roles` whose people's private chats the agent registers as `agent_chat` records of kind
|
|
94
|
-
* `private
|
|
94
|
+
* `private`, and in `takeover.channels` the channels whose chats staff may take over from the
|
|
95
|
+
* agent. Older readers ignore it, register none and let none be taken over.
|
|
95
96
|
*/
|
|
96
97
|
export declare const MANIFEST_VERSION = 15;
|
|
97
98
|
/** The phrase used for a direction the author did not phrase. */
|
|
@@ -1179,11 +1180,16 @@ export declare const OntologyManifestWire: Schema.encodeKeys<Schema.Struct<{
|
|
|
1179
1180
|
}>>;
|
|
1180
1181
|
}>>;
|
|
1181
1182
|
/**
|
|
1182
|
-
* Whose private chats join the inbox, within version 15: the wire names of their roles
|
|
1183
|
-
*
|
|
1183
|
+
* Whose private chats join the inbox, within version 15: the wire names of their roles, and the
|
|
1184
|
+
* channels whose chats staff may take over from the agent. Written only when declared; absent
|
|
1185
|
+
* registers no private chat, absent `takeover` lets no chat be taken over, and older readers
|
|
1186
|
+
* ignore both.
|
|
1184
1187
|
*/
|
|
1185
1188
|
readonly inbox: Schema.optionalKey<Schema.Struct<{
|
|
1186
1189
|
readonly roles: Schema.$Array<Schema.String>;
|
|
1190
|
+
readonly takeover: Schema.optionalKey<Schema.Struct<{
|
|
1191
|
+
readonly channels: Schema.$Array<Schema.String>;
|
|
1192
|
+
}>>;
|
|
1187
1193
|
}>>;
|
|
1188
1194
|
/**
|
|
1189
1195
|
* The metrics of the model, since version 8. Written only when there are some; absent reads as
|
|
@@ -1595,6 +1601,9 @@ export declare const OntologyManifest: Schema.declareConstructor<{
|
|
|
1595
1601
|
} | undefined;
|
|
1596
1602
|
readonly inbox?: {
|
|
1597
1603
|
readonly roles: readonly string[];
|
|
1604
|
+
readonly takeover?: {
|
|
1605
|
+
readonly channels: readonly string[];
|
|
1606
|
+
} | undefined;
|
|
1598
1607
|
} | undefined;
|
|
1599
1608
|
readonly toolsets?: readonly {
|
|
1600
1609
|
readonly name: string;
|
|
@@ -1912,6 +1921,9 @@ export declare const OntologyManifest: Schema.declareConstructor<{
|
|
|
1912
1921
|
} | undefined;
|
|
1913
1922
|
readonly inbox?: {
|
|
1914
1923
|
readonly roles: readonly string[];
|
|
1924
|
+
readonly takeover?: {
|
|
1925
|
+
readonly channels: readonly string[];
|
|
1926
|
+
} | undefined;
|
|
1915
1927
|
} | undefined;
|
|
1916
1928
|
readonly toolsets?: readonly {
|
|
1917
1929
|
readonly name: string;
|
|
@@ -2194,6 +2206,9 @@ export declare const OntologyManifest: Schema.declareConstructor<{
|
|
|
2194
2206
|
} | undefined;
|
|
2195
2207
|
readonly inbox?: {
|
|
2196
2208
|
readonly roles: readonly string[];
|
|
2209
|
+
readonly takeover?: {
|
|
2210
|
+
readonly channels: readonly string[];
|
|
2211
|
+
} | undefined;
|
|
2197
2212
|
} | undefined;
|
|
2198
2213
|
readonly toolsets?: readonly {
|
|
2199
2214
|
readonly name: string;
|
|
@@ -2546,6 +2561,9 @@ export declare const OntologyManifest: Schema.declareConstructor<{
|
|
|
2546
2561
|
} | undefined;
|
|
2547
2562
|
readonly inbox?: {
|
|
2548
2563
|
readonly roles: readonly string[];
|
|
2564
|
+
readonly takeover?: {
|
|
2565
|
+
readonly channels: readonly string[];
|
|
2566
|
+
} | undefined;
|
|
2549
2567
|
} | undefined;
|
|
2550
2568
|
readonly toolsets?: readonly {
|
|
2551
2569
|
readonly name: string;
|
|
@@ -2891,11 +2909,16 @@ export declare const OntologyManifest: Schema.declareConstructor<{
|
|
|
2891
2909
|
}>>;
|
|
2892
2910
|
}>>;
|
|
2893
2911
|
/**
|
|
2894
|
-
* Whose private chats join the inbox, within version 15: the wire names of their roles
|
|
2895
|
-
*
|
|
2912
|
+
* Whose private chats join the inbox, within version 15: the wire names of their roles, and the
|
|
2913
|
+
* channels whose chats staff may take over from the agent. Written only when declared; absent
|
|
2914
|
+
* registers no private chat, absent `takeover` lets no chat be taken over, and older readers
|
|
2915
|
+
* ignore both.
|
|
2896
2916
|
*/
|
|
2897
2917
|
readonly inbox: Schema.optionalKey<Schema.Struct<{
|
|
2898
2918
|
readonly roles: Schema.$Array<Schema.String>;
|
|
2919
|
+
readonly takeover: Schema.optionalKey<Schema.Struct<{
|
|
2920
|
+
readonly channels: Schema.$Array<Schema.String>;
|
|
2921
|
+
}>>;
|
|
2899
2922
|
}>>;
|
|
2900
2923
|
/**
|
|
2901
2924
|
* The metrics of the model, since version 8. Written only when there are some; absent reads as
|
|
@@ -3322,11 +3345,16 @@ export declare const OntologyManifest: Schema.declareConstructor<{
|
|
|
3322
3345
|
}>>;
|
|
3323
3346
|
}>>;
|
|
3324
3347
|
/**
|
|
3325
|
-
* Whose private chats join the inbox, within version 15: the wire names of their roles
|
|
3326
|
-
*
|
|
3348
|
+
* Whose private chats join the inbox, within version 15: the wire names of their roles, and the
|
|
3349
|
+
* channels whose chats staff may take over from the agent. Written only when declared; absent
|
|
3350
|
+
* registers no private chat, absent `takeover` lets no chat be taken over, and older readers
|
|
3351
|
+
* ignore both.
|
|
3327
3352
|
*/
|
|
3328
3353
|
readonly inbox: Schema.optionalKey<Schema.Struct<{
|
|
3329
3354
|
readonly roles: Schema.$Array<Schema.String>;
|
|
3355
|
+
readonly takeover: Schema.optionalKey<Schema.Struct<{
|
|
3356
|
+
readonly channels: Schema.$Array<Schema.String>;
|
|
3357
|
+
}>>;
|
|
3330
3358
|
}>>;
|
|
3331
3359
|
/**
|
|
3332
3360
|
* The metrics of the model, since version 8. Written only when there are some; absent reads as
|
|
@@ -3730,6 +3758,9 @@ export declare const OntologyManifest: Schema.declareConstructor<{
|
|
|
3730
3758
|
} | undefined;
|
|
3731
3759
|
readonly inbox?: {
|
|
3732
3760
|
readonly roles: readonly string[];
|
|
3761
|
+
readonly takeover?: {
|
|
3762
|
+
readonly channels: readonly string[];
|
|
3763
|
+
} | undefined;
|
|
3733
3764
|
} | undefined;
|
|
3734
3765
|
readonly toolsets?: readonly {
|
|
3735
3766
|
readonly name: string;
|
|
@@ -4047,6 +4078,9 @@ export declare const OntologyManifest: Schema.declareConstructor<{
|
|
|
4047
4078
|
} | undefined;
|
|
4048
4079
|
readonly inbox?: {
|
|
4049
4080
|
readonly roles: readonly string[];
|
|
4081
|
+
readonly takeover?: {
|
|
4082
|
+
readonly channels: readonly string[];
|
|
4083
|
+
} | undefined;
|
|
4050
4084
|
} | undefined;
|
|
4051
4085
|
readonly toolsets?: readonly {
|
|
4052
4086
|
readonly name: string;
|
|
@@ -4370,6 +4404,9 @@ export declare const decodeManifestDocument: (value: unknown) => Effect.Effect<{
|
|
|
4370
4404
|
} | undefined;
|
|
4371
4405
|
readonly inbox?: {
|
|
4372
4406
|
readonly roles: readonly string[];
|
|
4407
|
+
readonly takeover?: {
|
|
4408
|
+
readonly channels: readonly string[];
|
|
4409
|
+
} | undefined;
|
|
4373
4410
|
} | undefined;
|
|
4374
4411
|
readonly toolsets?: readonly {
|
|
4375
4412
|
readonly name: string;
|
|
@@ -4687,6 +4724,9 @@ export declare const decodeManifestDocument: (value: unknown) => Effect.Effect<{
|
|
|
4687
4724
|
} | undefined;
|
|
4688
4725
|
readonly inbox?: {
|
|
4689
4726
|
readonly roles: readonly string[];
|
|
4727
|
+
readonly takeover?: {
|
|
4728
|
+
readonly channels: readonly string[];
|
|
4729
|
+
} | undefined;
|
|
4690
4730
|
} | undefined;
|
|
4691
4731
|
readonly toolsets?: readonly {
|
|
4692
4732
|
readonly name: string;
|
|
@@ -4738,6 +4778,16 @@ export declare function signInPolicyOf(manifest: Pick<OntologyManifest, "signIn"
|
|
|
4738
4778
|
export declare function signUpRolesOf(manifest: Pick<OntologyManifest, "signIn">, channel: string): ReadonlyArray<string> | undefined;
|
|
4739
4779
|
/** The wire names of the roles whose people's private chats join the inbox; empty without one. */
|
|
4740
4780
|
export declare function inboxRolesOf(manifest: Pick<OntologyManifest, "inbox">): ReadonlySet<string>;
|
|
4781
|
+
/** The channels whose private chats staff may take over from the agent; empty without any. */
|
|
4782
|
+
export declare function takeoverChannelsOf(manifest: Pick<OntologyManifest, "inbox">): ReadonlySet<string>;
|
|
4783
|
+
/**
|
|
4784
|
+
* The account providers people write from on the channels staff take chats over on: a platform
|
|
4785
|
+
* channel's kind, whose accounts every channel of the kind shares, and `channel:<name>` for a
|
|
4786
|
+
* workspace channel. Admission names an account's provider, never its channel, so a private chat on
|
|
4787
|
+
* any channel of a listed kind is reported at each message; the report names the channel, and only
|
|
4788
|
+
* a chat on a listed channel is ever held.
|
|
4789
|
+
*/
|
|
4790
|
+
export declare function takeoverProvidersOf(manifest: Pick<OntologyManifest, "inbox" | "chat">): ReadonlySet<string>;
|
|
4741
4791
|
/**
|
|
4742
4792
|
* The websites whose visitors may sign up on `web`, by origin: empty while `web` is closed to
|
|
4743
4793
|
* sign-up. Entries that are not an origin `signUp.origins` accepts are left out.
|
|
@@ -4790,6 +4840,9 @@ export declare function buildManifest(input: {
|
|
|
4790
4840
|
readonly chat?: ChatManifestInput;
|
|
4791
4841
|
readonly inbox?: {
|
|
4792
4842
|
readonly roles: ReadonlyArray<string>;
|
|
4843
|
+
readonly takeover: {
|
|
4844
|
+
readonly channels: ReadonlyArray<string>;
|
|
4845
|
+
};
|
|
4793
4846
|
};
|
|
4794
4847
|
readonly entities: ReadonlyArray<ResolvedEntity>;
|
|
4795
4848
|
readonly roles: ReadonlyArray<Role>;
|
package/dist/manifest.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CHAT_CHANNEL_NAME, CHAT_KINDS } from "./chat-channel.js";
|
|
1
|
+
import { CHAT_CHANNEL_NAME, CHAT_KINDS, channelIdentityProvider, isChatChannelKind, } from "./chat-channel.js";
|
|
2
2
|
import { balancesOf, metricExpression } from "./metric.js";
|
|
3
3
|
import { Effect, Schema, SchemaTransformation } from "effect";
|
|
4
4
|
import { acceptingEarlierManifestNames, withEarlierManifestNames } from "./legacy.js";
|
|
@@ -92,7 +92,8 @@ import { CHANNEL_PROVIDERS, DEFAULT_SIGN_IN_POLICY, isGuestBotCheckScheme, isGue
|
|
|
92
92
|
* `channel:<name>`, its people's accounts.
|
|
93
93
|
* Within version 15, the top-level `inbox`, written only when declared, holds the wire names of the
|
|
94
94
|
* `roles` whose people's private chats the agent registers as `agent_chat` records of kind
|
|
95
|
-
* `private
|
|
95
|
+
* `private`, and in `takeover.channels` the channels whose chats staff may take over from the
|
|
96
|
+
* agent. Older readers ignore it, register none and let none be taken over.
|
|
96
97
|
*/
|
|
97
98
|
export const MANIFEST_VERSION = 15;
|
|
98
99
|
/** The first version whose documents use snake_case names on the wire. */
|
|
@@ -562,10 +563,15 @@ const OntologyManifestModel = Schema.Struct({
|
|
|
562
563
|
})),
|
|
563
564
|
})),
|
|
564
565
|
/**
|
|
565
|
-
* Whose private chats join the inbox, within version 15: the wire names of their roles
|
|
566
|
-
*
|
|
566
|
+
* Whose private chats join the inbox, within version 15: the wire names of their roles, and the
|
|
567
|
+
* channels whose chats staff may take over from the agent. Written only when declared; absent
|
|
568
|
+
* registers no private chat, absent `takeover` lets no chat be taken over, and older readers
|
|
569
|
+
* ignore both.
|
|
567
570
|
*/
|
|
568
|
-
inbox: Schema.optionalKey(Schema.Struct({
|
|
571
|
+
inbox: Schema.optionalKey(Schema.Struct({
|
|
572
|
+
roles: Schema.Array(Schema.String),
|
|
573
|
+
takeover: Schema.optionalKey(Schema.Struct({ channels: Schema.Array(Schema.String) })),
|
|
574
|
+
})),
|
|
569
575
|
/**
|
|
570
576
|
* The metrics of the model, since version 8. Written only when there are some; absent reads as
|
|
571
577
|
* none.
|
|
@@ -664,6 +670,24 @@ export function signUpRolesOf(manifest, channel) {
|
|
|
664
670
|
export function inboxRolesOf(manifest) {
|
|
665
671
|
return new Set(manifest.inbox?.roles ?? []);
|
|
666
672
|
}
|
|
673
|
+
/** The channels whose private chats staff may take over from the agent; empty without any. */
|
|
674
|
+
export function takeoverChannelsOf(manifest) {
|
|
675
|
+
return new Set(manifest.inbox?.takeover?.channels ?? []);
|
|
676
|
+
}
|
|
677
|
+
/**
|
|
678
|
+
* The account providers people write from on the channels staff take chats over on: a platform
|
|
679
|
+
* channel's kind, whose accounts every channel of the kind shares, and `channel:<name>` for a
|
|
680
|
+
* workspace channel. Admission names an account's provider, never its channel, so a private chat on
|
|
681
|
+
* any channel of a listed kind is reported at each message; the report names the channel, and only
|
|
682
|
+
* a chat on a listed channel is ever held.
|
|
683
|
+
*/
|
|
684
|
+
export function takeoverProvidersOf(manifest) {
|
|
685
|
+
const named = manifest.chat?.channels ?? {};
|
|
686
|
+
return new Set([...takeoverChannelsOf(manifest)].flatMap((name) => {
|
|
687
|
+
const kind = isChatChannelKind(name) ? name : named[name]?.kind;
|
|
688
|
+
return kind === undefined ? [] : [channelIdentityProvider(kind, name)];
|
|
689
|
+
}));
|
|
690
|
+
}
|
|
667
691
|
/**
|
|
668
692
|
* The websites whose visitors may sign up on `web`, by origin: empty while `web` is closed to
|
|
669
693
|
* sign-up. Entries that are not an origin `signUp.origins` accepts are left out.
|
|
@@ -1002,7 +1026,14 @@ export function buildManifest(input) {
|
|
|
1002
1026
|
},
|
|
1003
1027
|
...(Object.keys(emails).length > 0 ? { emails } : {}),
|
|
1004
1028
|
...(input.chat === undefined ? {} : { chat: input.chat }),
|
|
1005
|
-
...(input.inbox === undefined
|
|
1029
|
+
...(input.inbox === undefined
|
|
1030
|
+
? {}
|
|
1031
|
+
: {
|
|
1032
|
+
inbox: {
|
|
1033
|
+
roles: [...input.inbox.roles],
|
|
1034
|
+
takeover: { channels: [...input.inbox.takeover.channels] },
|
|
1035
|
+
},
|
|
1036
|
+
}),
|
|
1006
1037
|
...(connections.length > 0
|
|
1007
1038
|
? {
|
|
1008
1039
|
connections: connections.map((candidate) => ({
|
package/dist/migrate/model.d.ts
CHANGED
|
@@ -562,6 +562,9 @@ export declare const MigrationPlan: Schema.Struct<{
|
|
|
562
562
|
} | undefined;
|
|
563
563
|
readonly inbox?: {
|
|
564
564
|
readonly roles: readonly string[];
|
|
565
|
+
readonly takeover?: {
|
|
566
|
+
readonly channels: readonly string[];
|
|
567
|
+
} | undefined;
|
|
565
568
|
} | undefined;
|
|
566
569
|
readonly toolsets?: readonly {
|
|
567
570
|
readonly name: string;
|
|
@@ -879,6 +882,9 @@ export declare const MigrationPlan: Schema.Struct<{
|
|
|
879
882
|
} | undefined;
|
|
880
883
|
readonly inbox?: {
|
|
881
884
|
readonly roles: readonly string[];
|
|
885
|
+
readonly takeover?: {
|
|
886
|
+
readonly channels: readonly string[];
|
|
887
|
+
} | undefined;
|
|
882
888
|
} | undefined;
|
|
883
889
|
readonly toolsets?: readonly {
|
|
884
890
|
readonly name: string;
|
|
@@ -1161,6 +1167,9 @@ export declare const MigrationPlan: Schema.Struct<{
|
|
|
1161
1167
|
} | undefined;
|
|
1162
1168
|
readonly inbox?: {
|
|
1163
1169
|
readonly roles: readonly string[];
|
|
1170
|
+
readonly takeover?: {
|
|
1171
|
+
readonly channels: readonly string[];
|
|
1172
|
+
} | undefined;
|
|
1164
1173
|
} | undefined;
|
|
1165
1174
|
readonly toolsets?: readonly {
|
|
1166
1175
|
readonly name: string;
|
|
@@ -1513,6 +1522,9 @@ export declare const MigrationPlan: Schema.Struct<{
|
|
|
1513
1522
|
} | undefined;
|
|
1514
1523
|
readonly inbox?: {
|
|
1515
1524
|
readonly roles: readonly string[];
|
|
1525
|
+
readonly takeover?: {
|
|
1526
|
+
readonly channels: readonly string[];
|
|
1527
|
+
} | undefined;
|
|
1516
1528
|
} | undefined;
|
|
1517
1529
|
readonly toolsets?: readonly {
|
|
1518
1530
|
readonly name: string;
|
|
@@ -1795,6 +1807,9 @@ export declare const MigrationPlan: Schema.Struct<{
|
|
|
1795
1807
|
}>>;
|
|
1796
1808
|
readonly inbox: Schema.optionalKey<Schema.Struct<{
|
|
1797
1809
|
readonly roles: Schema.$Array<Schema.String>;
|
|
1810
|
+
readonly takeover: Schema.optionalKey<Schema.Struct<{
|
|
1811
|
+
readonly channels: Schema.$Array<Schema.String>;
|
|
1812
|
+
}>>;
|
|
1798
1813
|
}>>;
|
|
1799
1814
|
readonly metrics: Schema.optionalKey<Schema.$Array<Schema.Struct<{
|
|
1800
1815
|
readonly name: Schema.String;
|
|
@@ -2108,6 +2123,9 @@ export declare const MigrationPlan: Schema.Struct<{
|
|
|
2108
2123
|
}>>;
|
|
2109
2124
|
readonly inbox: Schema.optionalKey<Schema.Struct<{
|
|
2110
2125
|
readonly roles: Schema.$Array<Schema.String>;
|
|
2126
|
+
readonly takeover: Schema.optionalKey<Schema.Struct<{
|
|
2127
|
+
readonly channels: Schema.$Array<Schema.String>;
|
|
2128
|
+
}>>;
|
|
2111
2129
|
}>>;
|
|
2112
2130
|
readonly metrics: Schema.optionalKey<Schema.$Array<Schema.Struct<{
|
|
2113
2131
|
readonly name: Schema.String;
|
|
@@ -2469,6 +2487,9 @@ export declare const MigrationPlan: Schema.Struct<{
|
|
|
2469
2487
|
} | undefined;
|
|
2470
2488
|
readonly inbox?: {
|
|
2471
2489
|
readonly roles: readonly string[];
|
|
2490
|
+
readonly takeover?: {
|
|
2491
|
+
readonly channels: readonly string[];
|
|
2492
|
+
} | undefined;
|
|
2472
2493
|
} | undefined;
|
|
2473
2494
|
readonly toolsets?: readonly {
|
|
2474
2495
|
readonly name: string;
|
|
@@ -2786,6 +2807,9 @@ export declare const MigrationPlan: Schema.Struct<{
|
|
|
2786
2807
|
} | undefined;
|
|
2787
2808
|
readonly inbox?: {
|
|
2788
2809
|
readonly roles: readonly string[];
|
|
2810
|
+
readonly takeover?: {
|
|
2811
|
+
readonly channels: readonly string[];
|
|
2812
|
+
} | undefined;
|
|
2789
2813
|
} | undefined;
|
|
2790
2814
|
readonly toolsets?: readonly {
|
|
2791
2815
|
readonly name: string;
|
package/dist/runtime/agents.js
CHANGED
|
@@ -6,7 +6,7 @@ import { AgentChat } from "../agent-chat.js";
|
|
|
6
6
|
import { chatChannelKind } from "../chat-channel.js";
|
|
7
7
|
import { AgentReview } from "../agent-review.js";
|
|
8
8
|
import { AGENT_IDENTITIES_TABLE, AGENT_PAIRINGS_TABLE, CHANNEL_USERS_TABLE, IDENTITY_NOTICES_TABLE, USER_TABLE, } from "../migrate/storage.js";
|
|
9
|
-
import { inboxRolesOf } from "../manifest.js";
|
|
9
|
+
import { inboxRolesOf, takeoverChannelsOf, takeoverProvidersOf } from "../manifest.js";
|
|
10
10
|
import { GUEST_ROLE } from "../names.js";
|
|
11
11
|
import { MAX_QUERY_LIMIT } from "../query.js";
|
|
12
12
|
import { beginReplicationWrite } from "../replication/transaction.js";
|
|
@@ -547,9 +547,70 @@ export function sqlAgentStore(ontology, sql) {
|
|
|
547
547
|
title: String(chat.title),
|
|
548
548
|
purpose: nullableText(chat.purpose),
|
|
549
549
|
whenToUse: nullableText(chat.when_to_use),
|
|
550
|
+
// A member of staff took the chat over, or the agent handed the person over to staff:
|
|
551
|
+
// the agent records the person and answers none.
|
|
552
|
+
...(((chat.handled_by_id ?? null) !== null || (chat.handoff_at ?? null) !== null) &&
|
|
553
|
+
takeoverChannelsOf(ontology.manifest).has(input.provider)
|
|
554
|
+
? { handled: true }
|
|
555
|
+
: {}),
|
|
550
556
|
};
|
|
551
557
|
}));
|
|
552
558
|
}).pipe(Effect.orDie),
|
|
559
|
+
handOffChat: (input) => Effect.gen(function* () {
|
|
560
|
+
// Only a chat staff may take over is handed to them.
|
|
561
|
+
if (!takeoverChannelsOf(ontology.manifest).has(input.provider) ||
|
|
562
|
+
!isRecordId(input.memberId)) {
|
|
563
|
+
return undefined;
|
|
564
|
+
}
|
|
565
|
+
return yield* sql.withTransaction(Effect.gen(function* () {
|
|
566
|
+
yield* beginReplicationWrite(sql);
|
|
567
|
+
yield* rows(`SELECT pg_advisory_xact_lock(hashtext($1))`, [
|
|
568
|
+
`chat:${input.provider}:${input.externalId}`,
|
|
569
|
+
]);
|
|
570
|
+
const runtime = makeOntologyRuntime(ontology, sql, {
|
|
571
|
+
action: `${AgentChat.name}.handoff`,
|
|
572
|
+
actionId: randomUUID(),
|
|
573
|
+
principalId: null,
|
|
574
|
+
});
|
|
575
|
+
const [found] = yield* runtime.find({
|
|
576
|
+
entity: AgentChat.name,
|
|
577
|
+
options: {
|
|
578
|
+
where: { provider: input.provider, external_id: input.externalId, kind: "private" },
|
|
579
|
+
limit: 1,
|
|
580
|
+
forUpdate: true,
|
|
581
|
+
},
|
|
582
|
+
});
|
|
583
|
+
if (found === undefined) {
|
|
584
|
+
return undefined;
|
|
585
|
+
}
|
|
586
|
+
const id = String(found.id);
|
|
587
|
+
// Only the chat's own person is handed over: the agent reports the chat it answers.
|
|
588
|
+
const members = yield* runtime.related({
|
|
589
|
+
entity: AgentChat.name,
|
|
590
|
+
id,
|
|
591
|
+
relationship: "members",
|
|
592
|
+
query: { limit: MAX_QUERY_LIMIT },
|
|
593
|
+
});
|
|
594
|
+
if (!members.items.some((member) => String(member.id) === input.memberId)) {
|
|
595
|
+
return undefined;
|
|
596
|
+
}
|
|
597
|
+
// A member of staff holds the chat already, or a handoff waits: nothing changes, and
|
|
598
|
+
// the first handoff keeps its time and reason.
|
|
599
|
+
if ((found.handled_by_id ?? null) !== null) {
|
|
600
|
+
return { id, handoffAt: null, handled: true };
|
|
601
|
+
}
|
|
602
|
+
if ((found.handoff_at ?? null) !== null) {
|
|
603
|
+
return { id, handoffAt: timestampText(found.handoff_at) };
|
|
604
|
+
}
|
|
605
|
+
const at = new Date().toISOString();
|
|
606
|
+
yield* runtime.update({
|
|
607
|
+
entity: AgentChat.name,
|
|
608
|
+
id,
|
|
609
|
+
values: { handoff_at: at, handoff_reason: input.reason },
|
|
610
|
+
});
|
|
611
|
+
return { id, handoffAt: at };
|
|
612
|
+
}));
|
|
613
|
+
}).pipe(Effect.orDie),
|
|
553
614
|
seeGuestChat: (guestId) => Effect.gen(function* () {
|
|
554
615
|
// Only the visitors' chats of an inbox that takes the guests.
|
|
555
616
|
if (!isRecordId(guestId) || !inboxRolesOf(ontology.manifest).has(GUEST_ROLE)) {
|
|
@@ -694,9 +755,18 @@ export function resolveChannelSignIn(ontology, sql, input) {
|
|
|
694
755
|
*/
|
|
695
756
|
function inInbox(ontology, input, resolution) {
|
|
696
757
|
const roles = inboxRolesOf(ontology.manifest);
|
|
697
|
-
|
|
698
|
-
input.chat
|
|
699
|
-
resolution.member.principal.roles.some((role) => roles.has(role))
|
|
700
|
-
|
|
701
|
-
|
|
758
|
+
if ((resolution.status !== "existing" && resolution.status !== "created") ||
|
|
759
|
+
input.chat !== "private" ||
|
|
760
|
+
!resolution.member.principal.roles.some((role) => roles.has(role))) {
|
|
761
|
+
return resolution;
|
|
762
|
+
}
|
|
763
|
+
// Staff may take chats over on a channel of this account's provider: the agent reports every
|
|
764
|
+
// message, and the report, which names the channel, says whether a member of staff holds the chat.
|
|
765
|
+
return takeoverProvidersOf(ontology.manifest).has(input.provider)
|
|
766
|
+
? { ...resolution, inbox: true, takeover: true }
|
|
767
|
+
: { ...resolution, inbox: true };
|
|
768
|
+
}
|
|
769
|
+
/** A stored timestamp, as the wire carries it. */
|
|
770
|
+
function timestampText(value) {
|
|
771
|
+
return value instanceof Date ? value.toISOString() : String(value);
|
|
702
772
|
}
|
|
@@ -68,6 +68,11 @@ function valueFields(ontology, entity, { mode }) {
|
|
|
68
68
|
: Schema.optionalKey(field.nullable ? Schema.NullOr(value) : value);
|
|
69
69
|
}
|
|
70
70
|
for (const link of entity.links.values()) {
|
|
71
|
+
// A built-in entity's relationships change only through the platform's own actions, such as
|
|
72
|
+
// agent_chat's takeOver: its update takes its unmanaged properties alone.
|
|
73
|
+
if (link.via === "key" && entity.resolved.builtIn) {
|
|
74
|
+
continue;
|
|
75
|
+
}
|
|
71
76
|
if (link.via === "key") {
|
|
72
77
|
const target = reference(link, relationshipDescription(entity, link));
|
|
73
78
|
const required = mode === "create" && !link.optional;
|
|
@@ -127,6 +127,16 @@ export declare const ChatSeenRequest: Schema.Struct<{
|
|
|
127
127
|
readonly recipient: Schema.optionalKey<Schema.String>;
|
|
128
128
|
readonly threadId: Schema.optionalKey<Schema.String>;
|
|
129
129
|
}>;
|
|
130
|
+
/**
|
|
131
|
+
* `POST /api/ontology/agent/chats/handoff`: the agent hands a person's private chat over to staff,
|
|
132
|
+
* saying what the person needs.
|
|
133
|
+
*/
|
|
134
|
+
export declare const ChatHandoffRequest: Schema.Struct<{
|
|
135
|
+
readonly provider: Schema.String;
|
|
136
|
+
readonly externalId: Schema.String;
|
|
137
|
+
readonly memberId: Schema.String;
|
|
138
|
+
readonly reason: Schema.String;
|
|
139
|
+
}>;
|
|
130
140
|
/**
|
|
131
141
|
* `POST /api/ontology/agent/reviews`: a reply the agent held for a member to review, for the member
|
|
132
142
|
* it answers. `key` names the reply, so a report repeated after a failure finds its review.
|
|
@@ -160,6 +160,18 @@ export const ChatSeenRequest = Schema.Struct({
|
|
|
160
160
|
})),
|
|
161
161
|
threadId: Schema.optionalKey(ChatId.annotate({ description: "The thread a reply in the private chat stays in." })),
|
|
162
162
|
});
|
|
163
|
+
/**
|
|
164
|
+
* `POST /api/ontology/agent/chats/handoff`: the agent hands a person's private chat over to staff,
|
|
165
|
+
* saying what the person needs.
|
|
166
|
+
*/
|
|
167
|
+
export const ChatHandoffRequest = Schema.Struct({
|
|
168
|
+
provider: Provider,
|
|
169
|
+
externalId: ChatId.annotate({ description: "The private chat's id on the channel." }),
|
|
170
|
+
memberId: Schema.String.annotate({ description: "The user id of the chat's person." }),
|
|
171
|
+
reason: Schema.String.check(Schema.isMinLength(1), Schema.isMaxLength(1000)).annotate({
|
|
172
|
+
description: "What the person needs from staff, in the agent's words.",
|
|
173
|
+
}),
|
|
174
|
+
});
|
|
163
175
|
/**
|
|
164
176
|
* `POST /api/ontology/agent/reviews`: a reply the agent held for a member to review, for the member
|
|
165
177
|
* it answers. `key` names the reply, so a report repeated after a failure finds its review.
|
|
@@ -13,7 +13,7 @@ import { secretHash } from "../oauth/protocol.js";
|
|
|
13
13
|
import { clientAddress, fixedWindowLimiter, } from "../rate-limit.js";
|
|
14
14
|
import { OntologyBackend } from "../runtime-contract.js";
|
|
15
15
|
import { AGENT_TASK_HEADER, agentTaskSecret, logRuntimeRejection, } from "../runtime-identity.js";
|
|
16
|
-
import { ChatSeenRequest, ReviewRequest, ResolveIdentityRequest, IdentityNoticeRequest, LimitNoticeRequest, PAIRING_TTL_MS, PairingRequest, canonicalPairingCode, identityForWire, memberForWire, newPairingCode, } from "./protocol.js";
|
|
16
|
+
import { ChatHandoffRequest, ChatSeenRequest, ReviewRequest, ResolveIdentityRequest, IdentityNoticeRequest, LimitNoticeRequest, PAIRING_TTL_MS, PairingRequest, canonicalPairingCode, identityForWire, memberForWire, newPairingCode, } from "./protocol.js";
|
|
17
17
|
import { AGENT_TOKEN_LIMIT, BOT_CHECK_LIMIT, introspectAgentToken, issueAgentToken, issueVisitorToken, visitorPreflight, } from "./web-tokens.js";
|
|
18
18
|
import { GUEST_LINK_PATH, guestRoutesPreflight, guestSignUpRoutes, recordGuestUsage, } from "./guest-sign-up.js";
|
|
19
19
|
import { identityToken } from "../operations.js";
|
|
@@ -22,6 +22,7 @@ export const AGENT_PATH = `${BASE_PATH}/agent`;
|
|
|
22
22
|
const PAIRINGS_PATH = `${AGENT_PATH}/pairings`;
|
|
23
23
|
const IDENTITIES_PATH = `${AGENT_PATH}/identities`;
|
|
24
24
|
const CHATS_SEEN_PATH = `${AGENT_PATH}/chats/seen`;
|
|
25
|
+
const CHATS_HANDOFF_PATH = `${AGENT_PATH}/chats/handoff`;
|
|
25
26
|
const REVIEWS_PATH = `${AGENT_PATH}/reviews`;
|
|
26
27
|
/** Where a signed-in member gets an agent token, and where the agent asks whom one stands for. */
|
|
27
28
|
export const AGENT_TOKENS_PATH = `${AGENT_PATH}/tokens`;
|
|
@@ -210,6 +211,7 @@ function resolveChannelIdentity(store, agentTools) {
|
|
|
210
211
|
notice_due: resolution.noticeDue,
|
|
211
212
|
on_new_user_pending: resolution.onNewUserPending,
|
|
212
213
|
...(resolution.inbox === true ? { inbox: true } : {}),
|
|
214
|
+
...(resolution.takeover === true ? { takeover: true } : {}),
|
|
213
215
|
});
|
|
214
216
|
case "limited":
|
|
215
217
|
return json({
|
|
@@ -264,6 +266,34 @@ function completeLimitNotice(store) {
|
|
|
264
266
|
return HttpServerResponse.empty({ status: 204, headers: NO_STORE });
|
|
265
267
|
});
|
|
266
268
|
}
|
|
269
|
+
/**
|
|
270
|
+
* `POST /api/ontology/agent/chats/handoff` (runtime): the agent hands a person's private chat over to
|
|
271
|
+
* staff. The chat must be registered, on a channel `inbox.takeover` lists, and the person's own;
|
|
272
|
+
* anything else answers 404. The answer is the chat's id and when the handoff began, or `handled`
|
|
273
|
+
* when a member of staff holds the chat already.
|
|
274
|
+
*/
|
|
275
|
+
function handOffChat(store) {
|
|
276
|
+
return (request) => Effect.gen(function* () {
|
|
277
|
+
const requestId = yield* RequestId;
|
|
278
|
+
const decoded = Schema.decodeUnknownResult(ChatHandoffRequest)(yield* jsonBody(request), {
|
|
279
|
+
errors: "all",
|
|
280
|
+
onExcessProperty: "error",
|
|
281
|
+
});
|
|
282
|
+
if (Result.isFailure(decoded)) {
|
|
283
|
+
return invalidBody(requestId, schemaIssues(decoded.failure));
|
|
284
|
+
}
|
|
285
|
+
const handed = yield* store.handOffChat(decoded.success);
|
|
286
|
+
if (handed === undefined) {
|
|
287
|
+
return toServerResponse(notFound(requestId, "The chat is not one staff take over."));
|
|
288
|
+
}
|
|
289
|
+
yield* Effect.logInfo("ontology.agent.chat_handed_off").pipe(Effect.annotateLogs({
|
|
290
|
+
requestId,
|
|
291
|
+
provider: decoded.success.provider,
|
|
292
|
+
chatId: decoded.success.externalId,
|
|
293
|
+
}));
|
|
294
|
+
return json(handed);
|
|
295
|
+
});
|
|
296
|
+
}
|
|
267
297
|
/**
|
|
268
298
|
* `POST /api/ontology/agent/chats/seen` (runtime): the agent saw a message in a group chat. The chat
|
|
269
299
|
* is recorded, or its title kept current, a paired writer joins its members and a paired member who
|
|
@@ -483,6 +513,7 @@ export function agentLayer(options) {
|
|
|
483
513
|
})));
|
|
484
514
|
}
|
|
485
515
|
yield* router.add("POST", CHATS_SEEN_PATH, asRuntime(seeChat(store)));
|
|
516
|
+
yield* router.add("POST", CHATS_HANDOFF_PATH, asRuntime(handOffChat(store)));
|
|
486
517
|
yield* router.add("POST", REVIEWS_PATH, asRuntime(holdReply(store)));
|
|
487
518
|
yield* router.add("DELETE", `${IDENTITIES_PATH}/:id`, asMember((_, member) => revokeIdentity(store, member)));
|
|
488
519
|
if (store.web !== undefined && backend.oauth !== undefined) {
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { validateTelegramPreviews } from "../../telegram.js";
|
|
2
|
+
import { takeoverChannelsOf } from "../../manifest.js";
|
|
2
3
|
import { randomUUID } from "node:crypto";
|
|
3
4
|
import { Cause, Effect } from "effect";
|
|
4
5
|
import { chatOperationId, chatPreviewDigest, } from "../../chat.js";
|
|
@@ -43,6 +44,7 @@ agent = {}) {
|
|
|
43
44
|
}
|
|
44
45
|
const attribution = ontology.config.chat?.attribution;
|
|
45
46
|
const separator = attribution?.separator ?? "\n\n";
|
|
47
|
+
const takeoverChannels = takeoverChannelsOf(ontology.manifest);
|
|
46
48
|
const providers = listedChatProviders(ontology.manifest.chat);
|
|
47
49
|
const destination = ontology.manifest.chat?.telegram?.connection;
|
|
48
50
|
const destinationPreviews = previews.settings?.connection === destination ? previews : { ownOrigins: previews.ownOrigins };
|
|
@@ -228,6 +230,7 @@ agent = {}) {
|
|
|
228
230
|
fetch: agent.fetch ?? ((request) => fetch(request)),
|
|
229
231
|
};
|
|
230
232
|
return {
|
|
233
|
+
takeoverChannels,
|
|
231
234
|
sendReview: reviewSender({
|
|
232
235
|
ontology,
|
|
233
236
|
connections,
|
|
@@ -528,6 +528,11 @@ export type AgentResolution = {
|
|
|
528
528
|
* reports the chat (`POST /api/ontology/agent/chats/seen`), which registers it.
|
|
529
529
|
*/
|
|
530
530
|
readonly inbox?: true;
|
|
531
|
+
/**
|
|
532
|
+
* Staff may take the chat over on its channel (`inbox.takeover.channels`): the agent reports
|
|
533
|
+
* every message, and answers it only while the report does not say the chat is `handled`.
|
|
534
|
+
*/
|
|
535
|
+
readonly takeover?: true;
|
|
531
536
|
} | {
|
|
532
537
|
readonly status: "pairing_required";
|
|
533
538
|
} | {
|
|
@@ -544,12 +549,35 @@ declare const IdentityInUse_base: Schema.Class<IdentityInUse, Schema.TaggedStruc
|
|
|
544
549
|
/** An account already belongs to another member; approval must roll back without consuming the code. */
|
|
545
550
|
export declare class IdentityInUse extends IdentityInUse_base {
|
|
546
551
|
}
|
|
547
|
-
/** A
|
|
552
|
+
/** A chat the agent saw, as `POST /api/ontology/agent/chats/seen` answers. */
|
|
548
553
|
export interface SeenChat {
|
|
549
554
|
readonly id: string;
|
|
550
555
|
readonly title: string;
|
|
551
556
|
readonly purpose: string | null;
|
|
552
557
|
readonly whenToUse: string | null;
|
|
558
|
+
/**
|
|
559
|
+
* A person's private chat a member of staff took over: the agent records the message and answers
|
|
560
|
+
* none of it until they hand it back.
|
|
561
|
+
*/
|
|
562
|
+
readonly handled?: true;
|
|
563
|
+
}
|
|
564
|
+
/** A person's private chat the agent hands over to staff (`POST /api/ontology/agent/chats/handoff`). */
|
|
565
|
+
export interface HandoffInput {
|
|
566
|
+
/** The channel's name. */
|
|
567
|
+
readonly provider: string;
|
|
568
|
+
readonly externalId: string;
|
|
569
|
+
/** The chat's person, whom the agent answers there. */
|
|
570
|
+
readonly memberId: string;
|
|
571
|
+
/** What the person needs from staff, in the agent's words. */
|
|
572
|
+
readonly reason: string;
|
|
573
|
+
}
|
|
574
|
+
/** A handoff the ontology recorded, or found waiting. */
|
|
575
|
+
export interface Handoff {
|
|
576
|
+
readonly id: string;
|
|
577
|
+
/** When the agent handed the person over: the first handoff's time, while it waits. */
|
|
578
|
+
readonly handoffAt: string | null;
|
|
579
|
+
/** A member of staff holds the chat already: nothing changed. */
|
|
580
|
+
readonly handled?: true;
|
|
553
581
|
}
|
|
554
582
|
/**
|
|
555
583
|
* Where the app's agent keeps pairing codes and the identities they create: the runtime's agent
|
|
@@ -642,6 +670,12 @@ export interface AgentStore {
|
|
|
642
670
|
* stores that predate the inbox.
|
|
643
671
|
*/
|
|
644
672
|
readonly seeInboxChat?: (input: InboxChatInput) => Effect.Effect<SeenChat | undefined>;
|
|
673
|
+
/**
|
|
674
|
+
* Hands a registered private chat on a channel staff take chats over on to staff: its
|
|
675
|
+
* `handoffAt` and `handoffReason`. Undefined for any other chat, or when `memberId` is not its
|
|
676
|
+
* person.
|
|
677
|
+
*/
|
|
678
|
+
readonly handOffChat: (input: HandoffInput) => Effect.Effect<Handoff | undefined>;
|
|
645
679
|
/**
|
|
646
680
|
* Records a website visitor's chat with the agent, `guest:<id>` on the `web` channel, for the
|
|
647
681
|
* inbox: creates the `agent_chat` of kind `private`, without members, and records when it last
|
|
@@ -547,6 +547,9 @@ export declare const Catalog: Schema.decodeTo<Schema.Struct<{
|
|
|
547
547
|
}>>;
|
|
548
548
|
readonly inbox: Schema.optionalKey<Schema.Struct<{
|
|
549
549
|
readonly roles: Schema.$Array<Schema.String>;
|
|
550
|
+
readonly takeover: Schema.optionalKey<Schema.Struct<{
|
|
551
|
+
readonly channels: Schema.$Array<Schema.String>;
|
|
552
|
+
}>>;
|
|
550
553
|
}>>;
|
|
551
554
|
readonly metrics: Schema.optionalKey<Schema.$Array<Schema.Struct<{
|
|
552
555
|
readonly name: Schema.String;
|
|
@@ -873,6 +876,9 @@ export declare const Catalog: Schema.decodeTo<Schema.Struct<{
|
|
|
873
876
|
}>>>;
|
|
874
877
|
readonly inbox: Schema.toEncoded<Schema.optionalKey<Schema.Struct<{
|
|
875
878
|
readonly roles: Schema.$Array<Schema.String>;
|
|
879
|
+
readonly takeover: Schema.optionalKey<Schema.Struct<{
|
|
880
|
+
readonly channels: Schema.$Array<Schema.String>;
|
|
881
|
+
}>>;
|
|
876
882
|
}>>>;
|
|
877
883
|
readonly metrics: Schema.toEncoded<Schema.optionalKey<Schema.$Array<Schema.Struct<{
|
|
878
884
|
readonly name: Schema.String;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@segmentstream/ontology",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.125.0",
|
|
4
4
|
"description": "Define a SegmentStream workspace app's ontology: entities, relationships, roles and actions, written with Effect.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": "SegmentStream",
|