@ouispec/contract 0.4.9 → 0.5.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.
@@ -0,0 +1,410 @@
1
+ {
2
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3
+ "$id": "https://schemas.closurestudio.ai/oui/v1/conversation-takeover.json",
4
+ "title": "Conversation takeover",
5
+ "description": "A person on the product's staff takes a live conversation from the agent, answers the customer as themselves, and hands it back: the shapes the realtime server, the agent worker, the product's API, the customer's tab and the staff console exchange.\n\n1. The product's own route checks that this person may take this conversation, then asks the realtime server to hold it (`POST /internal/conversations/{id}/hold`, `TakeOverRequest`). The server keeps one `ConversationHold`, stops any turn of the conversation that is running, and sends `agent:conversation_taken_over` (`ConversationTakenOverEvent`) to the conversation's room.\n2. While the conversation is held, the agent does not answer: a turn that arrives is not run by the model.\n3. The person's messages are stored by the product with `role: 'staff'` and their speaker, and announced (`POST /internal/conversations/{id}/messages`, `AnnounceMessageRequest`) as `agent:conversation_message` (`ConversationMessageEvent`), only while they hold the conversation.\n4. The holder, or the product on its own authority, hands it back (`POST /internal/conversations/{id}/hold/release`, `HandBackRequest`); `agent:conversation_handed_back` (`ConversationHandedBackEvent`) follows, and the agent's next turn reads the whole exchange in its history.\n\nThe realtime server never decides who may take over: its routes take the internal key, and the product calls them after its own check, as it does before it asks for a room token.",
6
+ "$defs": {
7
+ "StaffSpeaker": {
8
+ "description": "A person on the product's staff, as the conversation names them. `displayName` and `role` are shown to the customer; `userId` is what a hand-back and a staff message are checked against. It reaches the customer's tab, so name an id you are content to show (an opaque staff id).",
9
+ "type": "object",
10
+ "properties": {
11
+ "userId": {
12
+ "description": "The staff member's id, as the product's realtime identity names them.",
13
+ "type": "string",
14
+ "minLength": 1,
15
+ "maxLength": 200
16
+ },
17
+ "displayName": {
18
+ "description": "The name the customer sees (\"Jordan\").",
19
+ "type": "string",
20
+ "minLength": 1,
21
+ "maxLength": 80
22
+ },
23
+ "role": {
24
+ "description": "What the customer sees beside the name (\"Toyota of Quillhaven sales\").",
25
+ "type": "string",
26
+ "minLength": 1,
27
+ "maxLength": 80
28
+ }
29
+ },
30
+ "required": [
31
+ "userId",
32
+ "displayName"
33
+ ],
34
+ "additionalProperties": false
35
+ },
36
+ "ConversationHold": {
37
+ "description": "A conversation a person holds: the agent does not answer it until it is handed back. One holder at a time.",
38
+ "type": "object",
39
+ "properties": {
40
+ "conversationId": {
41
+ "type": "string",
42
+ "minLength": 1
43
+ },
44
+ "holder": {
45
+ "$ref": "#/$defs/StaffSpeaker"
46
+ },
47
+ "since": {
48
+ "description": "When it was taken, epoch ms by the realtime server's clock.",
49
+ "type": "number"
50
+ }
51
+ },
52
+ "required": [
53
+ "conversationId",
54
+ "holder",
55
+ "since"
56
+ ],
57
+ "additionalProperties": false
58
+ },
59
+ "TakeoverChange": {
60
+ "description": "A conversation changing hands, as its stored entry and its event say: `taken_over` by a person, `handed_back` to the agent.",
61
+ "enum": [
62
+ "taken_over",
63
+ "handed_back"
64
+ ]
65
+ },
66
+ "HandBackCause": {
67
+ "description": "Who ended a hold: the person who held it (`holder`), or the product on its own authority (`product`: an idle policy, a manager, the end of a shift).",
68
+ "enum": [
69
+ "holder",
70
+ "product"
71
+ ]
72
+ },
73
+ "ConversationMessageRole": {
74
+ "description": "Who wrote a message of the conversation: the customer (`user`), the agent (`assistant`), or a person on the staff (`staff`).",
75
+ "enum": [
76
+ "user",
77
+ "assistant",
78
+ "staff"
79
+ ]
80
+ },
81
+ "ConversationMessage": {
82
+ "description": "A stored message of the conversation, as it is announced to the people watching it.",
83
+ "type": "object",
84
+ "properties": {
85
+ "id": {
86
+ "description": "The product's id for the stored message.",
87
+ "type": "string",
88
+ "minLength": 1,
89
+ "maxLength": 200
90
+ },
91
+ "role": {
92
+ "$ref": "#/$defs/ConversationMessageRole"
93
+ },
94
+ "content": {
95
+ "type": "string",
96
+ "maxLength": 100000
97
+ },
98
+ "createdAt": {
99
+ "description": "When it was stored, ISO 8601.",
100
+ "type": "string",
101
+ "minLength": 1
102
+ },
103
+ "speaker": {
104
+ "description": "Set on a `staff` message: who wrote it.",
105
+ "$ref": "#/$defs/StaffSpeaker"
106
+ }
107
+ },
108
+ "required": [
109
+ "id",
110
+ "role",
111
+ "content",
112
+ "createdAt"
113
+ ],
114
+ "additionalProperties": false
115
+ },
116
+ "ConversationRooms": {
117
+ "description": "Where a conversation's event goes: the conversation's room, which the product names and guards with a room token, and any of the product's own (a team's board).",
118
+ "type": "array",
119
+ "items": {
120
+ "type": "string",
121
+ "minLength": 1
122
+ },
123
+ "minItems": 1,
124
+ "maxItems": 5,
125
+ "uniqueItems": true
126
+ },
127
+ "TakeOverRequest": {
128
+ "description": "`POST /internal/conversations/{conversationId}/hold`, from the product's API after its own check that this person may take this conversation.",
129
+ "type": "object",
130
+ "properties": {
131
+ "holder": {
132
+ "$ref": "#/$defs/StaffSpeaker"
133
+ },
134
+ "rooms": {
135
+ "$ref": "#/$defs/ConversationRooms"
136
+ }
137
+ },
138
+ "required": [
139
+ "holder",
140
+ "rooms"
141
+ ],
142
+ "additionalProperties": false
143
+ },
144
+ "TakeOverResult": {
145
+ "description": "The answer to a take-over: `taken_over` the first time, with the approvals it withdrew; `already` when this holder had it; 409 `held` when someone else holds it.",
146
+ "oneOf": [
147
+ {
148
+ "type": "object",
149
+ "properties": {
150
+ "ok": {
151
+ "const": true
152
+ },
153
+ "change": {
154
+ "enum": [
155
+ "taken_over",
156
+ "already"
157
+ ]
158
+ },
159
+ "hold": {
160
+ "$ref": "#/$defs/ConversationHold"
161
+ },
162
+ "withdrawn": {
163
+ "description": "On `taken_over`: the ids of the conversation's approvals that were waiting, or approved and not yet used, and are now withdrawn (`taken_over`), since the person now answering asked for none of them. Empty when there were none.",
164
+ "type": "array",
165
+ "items": {
166
+ "type": "string"
167
+ }
168
+ }
169
+ },
170
+ "required": [
171
+ "ok",
172
+ "change",
173
+ "hold"
174
+ ],
175
+ "additionalProperties": false
176
+ },
177
+ {
178
+ "type": "object",
179
+ "properties": {
180
+ "ok": {
181
+ "const": false
182
+ },
183
+ "reason": {
184
+ "const": "held"
185
+ },
186
+ "hold": {
187
+ "$ref": "#/$defs/ConversationHold"
188
+ }
189
+ },
190
+ "required": [
191
+ "ok",
192
+ "reason",
193
+ "hold"
194
+ ],
195
+ "additionalProperties": false
196
+ }
197
+ ]
198
+ },
199
+ "HandBackRequest": {
200
+ "description": "`POST /internal/conversations/{conversationId}/hold/release`. With `userId`, only the holder may hand it back; without it, the product releases it on its own authority.",
201
+ "type": "object",
202
+ "properties": {
203
+ "userId": {
204
+ "description": "The staff member handing it back; must be the holder.",
205
+ "type": "string",
206
+ "minLength": 1
207
+ },
208
+ "rooms": {
209
+ "$ref": "#/$defs/ConversationRooms"
210
+ }
211
+ },
212
+ "required": [
213
+ "rooms"
214
+ ],
215
+ "additionalProperties": false
216
+ },
217
+ "HandBackResult": {
218
+ "description": "The answer to a hand-back: `handed_back` with the hold that ended, `not_held` when nobody held it; 409 `not_holder` when someone else holds it.",
219
+ "oneOf": [
220
+ {
221
+ "type": "object",
222
+ "properties": {
223
+ "ok": {
224
+ "const": true
225
+ },
226
+ "change": {
227
+ "const": "handed_back"
228
+ },
229
+ "hold": {
230
+ "$ref": "#/$defs/ConversationHold"
231
+ },
232
+ "by": {
233
+ "$ref": "#/$defs/HandBackCause"
234
+ }
235
+ },
236
+ "required": [
237
+ "ok",
238
+ "change",
239
+ "hold",
240
+ "by"
241
+ ],
242
+ "additionalProperties": false
243
+ },
244
+ {
245
+ "type": "object",
246
+ "properties": {
247
+ "ok": {
248
+ "const": true
249
+ },
250
+ "change": {
251
+ "const": "not_held"
252
+ }
253
+ },
254
+ "required": [
255
+ "ok",
256
+ "change"
257
+ ],
258
+ "additionalProperties": false
259
+ },
260
+ {
261
+ "type": "object",
262
+ "properties": {
263
+ "ok": {
264
+ "const": false
265
+ },
266
+ "reason": {
267
+ "const": "not_holder"
268
+ },
269
+ "hold": {
270
+ "$ref": "#/$defs/ConversationHold"
271
+ }
272
+ },
273
+ "required": [
274
+ "ok",
275
+ "reason",
276
+ "hold"
277
+ ],
278
+ "additionalProperties": false
279
+ }
280
+ ]
281
+ },
282
+ "AnnounceMessageRequest": {
283
+ "description": "`POST /internal/conversations/{conversationId}/messages`: a message the product has stored, for the people watching the conversation. A `staff` message is announced only while its speaker holds the conversation.",
284
+ "type": "object",
285
+ "properties": {
286
+ "message": {
287
+ "$ref": "#/$defs/ConversationMessage"
288
+ },
289
+ "rooms": {
290
+ "$ref": "#/$defs/ConversationRooms"
291
+ }
292
+ },
293
+ "required": [
294
+ "message",
295
+ "rooms"
296
+ ],
297
+ "additionalProperties": false
298
+ },
299
+ "AnnounceMessageResult": {
300
+ "description": "The answer to an announcement: sent, or 409 because its staff speaker does not hold the conversation (`not_held`: nobody does; `not_holder`: someone else does).",
301
+ "oneOf": [
302
+ {
303
+ "type": "object",
304
+ "properties": {
305
+ "ok": {
306
+ "const": true
307
+ }
308
+ },
309
+ "required": [
310
+ "ok"
311
+ ],
312
+ "additionalProperties": false
313
+ },
314
+ {
315
+ "type": "object",
316
+ "properties": {
317
+ "ok": {
318
+ "const": false
319
+ },
320
+ "reason": {
321
+ "enum": [
322
+ "not_held",
323
+ "not_holder"
324
+ ]
325
+ }
326
+ },
327
+ "required": [
328
+ "ok",
329
+ "reason"
330
+ ],
331
+ "additionalProperties": false
332
+ }
333
+ ]
334
+ },
335
+ "ConversationTakenOverEvent": {
336
+ "description": "`agent:conversation_taken_over`, to the conversation's room: a person took it, and the agent stopped answering.",
337
+ "type": "object",
338
+ "properties": {
339
+ "conversationId": {
340
+ "type": "string",
341
+ "minLength": 1
342
+ },
343
+ "hold": {
344
+ "$ref": "#/$defs/ConversationHold"
345
+ },
346
+ "at": {
347
+ "description": "Epoch ms.",
348
+ "type": "number"
349
+ }
350
+ },
351
+ "required": [
352
+ "conversationId",
353
+ "hold",
354
+ "at"
355
+ ],
356
+ "additionalProperties": false
357
+ },
358
+ "ConversationHandedBackEvent": {
359
+ "description": "`agent:conversation_handed_back`, to the conversation's room: the hold ended, and the agent answers again.",
360
+ "type": "object",
361
+ "properties": {
362
+ "conversationId": {
363
+ "type": "string",
364
+ "minLength": 1
365
+ },
366
+ "hold": {
367
+ "description": "The hold that ended.",
368
+ "$ref": "#/$defs/ConversationHold"
369
+ },
370
+ "by": {
371
+ "$ref": "#/$defs/HandBackCause"
372
+ },
373
+ "at": {
374
+ "description": "Epoch ms.",
375
+ "type": "number"
376
+ }
377
+ },
378
+ "required": [
379
+ "conversationId",
380
+ "hold",
381
+ "by",
382
+ "at"
383
+ ],
384
+ "additionalProperties": false
385
+ },
386
+ "ConversationMessageEvent": {
387
+ "description": "`agent:conversation_message`, to the conversation's room: a message the product stored, for the people watching.",
388
+ "type": "object",
389
+ "properties": {
390
+ "conversationId": {
391
+ "type": "string",
392
+ "minLength": 1
393
+ },
394
+ "message": {
395
+ "$ref": "#/$defs/ConversationMessage"
396
+ },
397
+ "at": {
398
+ "description": "Epoch ms.",
399
+ "type": "number"
400
+ }
401
+ },
402
+ "required": [
403
+ "conversationId",
404
+ "message",
405
+ "at"
406
+ ],
407
+ "additionalProperties": false
408
+ }
409
+ }
410
+ }
@@ -201,7 +201,7 @@
201
201
  "pattern": "^[A-Z][A-Za-z0-9]*$"
202
202
  },
203
203
  "rooms": {
204
- "description": "The rooms the event is published to: names from the document's `rooms`, or `turn` for the room of the agent turn it belongs to (the host names that room in each turn).",
204
+ "description": "The rooms the event is published to: names from the document's `rooms`; `turn` for the room of the agent turn it belongs to (the host names that room in each turn); or `conversation` for the room of the conversation it belongs to (the host names that room too).",
205
205
  "type": "array",
206
206
  "items": {
207
207
  "type": "string",