@ouispec/agent-realtime 0.17.0 → 0.19.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (61) hide show
  1. package/README.md +9 -2
  2. package/dist/approvals/client-event.d.ts +1 -0
  3. package/dist/approvals/client-event.d.ts.map +1 -1
  4. package/dist/approvals/client-event.js +29 -6
  5. package/dist/approvals/client-event.js.map +1 -1
  6. package/dist/approvals/routes.d.ts +2 -0
  7. package/dist/approvals/routes.d.ts.map +1 -1
  8. package/dist/approvals/routes.js +4 -0
  9. package/dist/approvals/routes.js.map +1 -1
  10. package/dist/approvals/schemas.d.ts +2 -1
  11. package/dist/approvals/schemas.d.ts.map +1 -1
  12. package/dist/approvals/schemas.js +7 -1
  13. package/dist/approvals/schemas.js.map +1 -1
  14. package/dist/approvals/store.d.ts +34 -2
  15. package/dist/approvals/store.d.ts.map +1 -1
  16. package/dist/approvals/store.js +137 -24
  17. package/dist/approvals/store.js.map +1 -1
  18. package/dist/client-events/builtin.d.ts.map +1 -1
  19. package/dist/client-events/builtin.js +4 -0
  20. package/dist/client-events/builtin.js.map +1 -1
  21. package/dist/config.js +3 -2
  22. package/dist/config.js.map +1 -1
  23. package/dist/conversations/holds.d.ts +62 -0
  24. package/dist/conversations/holds.d.ts.map +1 -0
  25. package/dist/conversations/holds.js +80 -0
  26. package/dist/conversations/holds.js.map +1 -0
  27. package/dist/conversations/routes.d.ts +42 -0
  28. package/dist/conversations/routes.d.ts.map +1 -0
  29. package/dist/conversations/routes.js +186 -0
  30. package/dist/conversations/routes.js.map +1 -0
  31. package/dist/events/declared.js +1 -1
  32. package/dist/events/declared.js.map +1 -1
  33. package/dist/events/server-sent.d.ts +4 -0
  34. package/dist/events/server-sent.d.ts.map +1 -0
  35. package/dist/events/server-sent.js +19 -0
  36. package/dist/events/server-sent.js.map +1 -0
  37. package/dist/http/routes.d.ts +5 -0
  38. package/dist/http/routes.d.ts.map +1 -1
  39. package/dist/http/routes.js +14 -0
  40. package/dist/http/routes.js.map +1 -1
  41. package/dist/index.d.ts +9 -4
  42. package/dist/index.d.ts.map +1 -1
  43. package/dist/index.js +7 -3
  44. package/dist/index.js.map +1 -1
  45. package/dist/redis-waits.d.ts +3 -2
  46. package/dist/redis-waits.d.ts.map +1 -1
  47. package/dist/redis-waits.js +19 -12
  48. package/dist/redis-waits.js.map +1 -1
  49. package/dist/server.d.ts +6 -2
  50. package/dist/server.d.ts.map +1 -1
  51. package/dist/server.js +24 -6
  52. package/dist/server.js.map +1 -1
  53. package/dist/turns/routes.d.ts +4 -2
  54. package/dist/turns/routes.d.ts.map +1 -1
  55. package/dist/turns/routes.js +6 -3
  56. package/dist/turns/routes.js.map +1 -1
  57. package/dist/turns/stops.d.ts +19 -5
  58. package/dist/turns/stops.d.ts.map +1 -1
  59. package/dist/turns/stops.js +24 -10
  60. package/dist/turns/stops.js.map +1 -1
  61. package/package.json +5 -4
package/README.md CHANGED
@@ -9,6 +9,7 @@ The realtime server for agent turns and UI actions. One implementation serves ev
9
9
  - **Signs and checks room tokens.** A room token admits one user to one room.
10
10
  - **Checks client events.** It accepts only the client events it declares, and puts each one through a chain: rate limit, size cap, schema, then authorization against the verified identity.
11
11
  - **Restricts relays.** A client can relay only allow-listed events, and only into rooms its socket has joined.
12
+ - **Keeps conversation holds.** A person on the staff can take a conversation from the agent and hand it back: while they hold it, every turn of it stops (`taken_over`) on every channel, every approval of it that was waiting is withdrawn, and only they speak for the business in it.
12
13
 
13
14
  ## What the product supplies
14
15
 
@@ -66,9 +67,13 @@ All of them require the `x-api-key` header.
66
67
  | `POST /internal/approvals/redeem` `{ token, userId, conversationId }` | Atomic single use. `200 { call, receipt? }` returns exactly the stored call, and its receipt when this server has receipt keys and the call is a host or API tool's. `403` for a token this environment did not sign, another user's or conversation's, or one not for the stored call; `410` for an expired or already used one, with no receipt. |
67
68
  | `GET /internal/approvals/:id?userId=` | Where an approval of this user's stands: `pending`, `approved` or `declined` (remembered for 30 minutes). |
68
69
  | `POST /internal/approvals/:id/settle` `{ userId, conversationId, confirm? }` | Whether an approval a conversation still shows as waiting expired with nobody deciding it. Always `200 { approvalId, outcome, expiresAt? }`: `claimed` (it expired without having run, and this caller holds the claim to store that, for two minutes; `decided: "approved"` when the user had approved it and it was never used), `already` (another turn holds the claim, or it is stored), `open` (pending, or approved and not yet used), `unknown` (declined, used, another user's or conversation's, or not remembered). With `confirm: true`, the caller has stored it and the claim becomes permanent: `confirmed`. |
69
- | `POST /internal/approvals/:id/settle` `{ userId, conversationId, expire }` | Expires an approval now instead of at its time limit, saying why: `expire` is `superseded` (the user sent a new message while its card waited) or `stopped` (the turn that asked was stopped). `200 { approvalId, outcome }`: `withdrawn` (it was pending, or approved and not yet used, and is now gone: a decision is refused and its token answers `used`), `settled` (it had already ended), `unknown`. A later settle then answers `claimed` with `withdrawn: "superseded" \| "stopped"`. |
70
+ | `POST /internal/approvals/:id/settle` `{ userId, conversationId, expire }` | Expires an approval now instead of at its time limit, saying why: `expire` is `superseded` (the user sent a new message while its card waited), `stopped` (the turn that asked was stopped) or `taken_over` (a person on the staff took the conversation over). `200 { approvalId, outcome }`: `withdrawn` (it was pending, or approved and not yet used, and is now gone: a decision is refused and its token answers `used`), `settled` (it had already ended), `unknown`. A later settle then answers `claimed` with `withdrawn` set to that reason. |
70
71
  | `POST /internal/turns/:turnId/stop` `{ userId, reason }` | Asks that a turn stop, for its user: `reason` is `superseded` (a newer message runs instead) or `user_stop`. Your API calls it after checking the turn is the user's. `200 { ok, stop: "requested" \| "already", record }`; the first request stands. |
71
- | `GET /internal/turns/:turnId/stop?userId=&waitMs=` | The stop asked for on a turn by its user, which the turn's worker holds open for as long as the turn runs. `200` carries `{ turnId, by, reason, at }`; `204` means none yet. A wait lasts at most 25 s. The record is kept 30 minutes. |
72
+ | `GET /internal/turns/:turnId/stop?userId=&waitMs=&conversationId=` | The stop asked for on a turn by its user, which the turn's worker holds open for as long as the turn runs. With `conversationId`, a person holding the conversation is a stop too (`reason: "taken_over"`). `200` carries `{ turnId, by, reason, at }`; `204` means none yet. A wait lasts at most 25 s. The record is kept 30 minutes. |
73
+ | `GET /internal/conversations/:id/hold` | Who holds a conversation: `200` with `{ conversationId, holder, since }`, `204` when the agent answers it. |
74
+ | `POST /internal/conversations/:id/hold` `{ holder, rooms }` | Takes a conversation over for `holder` (`{ userId, displayName, role? }`), after your API's own check that this person may. `200 { ok, change: "taken_over" \| "already", hold, withdrawn? }`; `409 { ok: false, reason: "held", hold }` when someone else holds it. On `taken_over` every turn of the conversation stops, every approval of it still waiting, or approved and not yet used, is withdrawn (`taken_over`; their ids are `withdrawn`), and `agent:conversation_taken_over` goes to `rooms`. |
75
+ | `POST /internal/conversations/:id/hold/release` `{ userId?, rooms }` | Hands it back: with `userId` only the holder may (`409 not_holder`); without, your product releases it on its own authority. `200 { ok, change: "handed_back", hold, by }` or `{ ok, change: "not_held" }`; `agent:conversation_handed_back` goes to `rooms`. |
76
+ | `POST /internal/conversations/:id/messages` `{ message, rooms }` | Announces a stored message of the conversation (`agent:conversation_message`): the customer's and the agent's for the staff watching, a staff member's only while they hold it (`409`). `/api/emit` refuses the three conversation events. |
72
77
  | `GET /internal/events/settlements/:kind/:id?waitMs=` | How a job of a declared kind ended: `{ kind, role, event, id, payload }`, with `role` `completion` or `failure`. `204` means not yet; `400` an undeclared kind; `404` a server without `events`. A wait lasts at most 25 s. |
73
78
  | `GET /health` | Returns `200` with connection and pending-wait counts. No key needed. |
74
79
  | `GET /.well-known/oui-approval-jwks.json` | The approval receipt keys, public parts only, as a JWKS. No key needed, any origin, `Cache-Control: public, max-age=3600`. `404` on a server without receipt keys. |
@@ -79,6 +84,8 @@ All of them require the `x-api-key` header.
79
84
  2. The user clicks the approval card. Their socket sends `approval:decide { approvalId, decision }`, a declared client event. The store checks that the socket's verified user is the approval's own. An approval's token is answered only to that socket, in the ack: `{ ok: true, decision: 'approve', token, argsHash, expiresAt }`.
80
85
  3. The next turn carries the token outside the message text. The worker redeems it, and the store returns the stored call exactly once.
81
86
 
87
+ **An action on the person's page approved by voice, on the phone or in chat**. The worker stores a UI action's approval with its turn's `room`, which must be one of your `roomPolicy`'s rooms. When the engine decides `approve` on `voice`, `phone` or `chat`, the same script that approves it writes a single-use grant, and the store pushes `agent:approval_granted { approvalId, grantId, argsHash, expiresAt, conversationId, room, channel }` to that room, and nowhere else. The grant lasts two minutes (`APPROVAL_GRANT_TTL_MS`), or until the approval expires if that is sooner. A tab on the conversation claims it with `approval:claim { approvalId, grantId }` on its own socket: only the first claim, from a socket of the approval's user that is in the grant's room, before it expires, is answered with the grant (`{ ok: true, approvalId, argsHash, expiresAt, channel }`). Later claims are refused `used`, another user's or one from outside the room `forbidden`, a late one `expired`, and one for a withdrawn approval `unknown`. A decline in any conversation channel pushes `agent:approval_declined { approvalId, conversationId, channel }` to the room, for the card. `/api/emit` and a client's relay refuse both events. An approve on `sms`, or of a UI action stored without a room, is refused `channel`.
88
+
82
89
  An approval nobody decides sends nothing when it expires, so a later turn settles it. The store remembers, for 30 days, that an approval was asked for and is still undecided; a decline or a redemption removes that memory in the same step. Once the approval's own keys have lapsed in Redis, `POST /internal/approvals/:id/settle` answers that it expired undecided, and gives the claim to store that to one caller at a time. Expiry is Redis's clock: neither this server's nor the caller's is consulted. Approvals stored before this memory existed are answered `unknown`.
83
90
 
84
91
  An approval can also be withdrawn before its time is up (`settle` with `expire`): when the user sends a new message while its card waits, or the turn that asked for it is stopped. That is one script with the decision and the redemption, so exactly one of them happens. From then it is an expiry like any other, settled by a later turn, which is told why: it was withdrawn, not left to time out. One the user had approved keeps that they did.
@@ -1,4 +1,5 @@
1
1
  import { type ClientEvent } from '../client-events/chain.js';
2
2
  import type { ApprovalStore } from './store.js';
3
3
  export declare function createApprovalDecideEvent(approvals: () => ApprovalStore): ClientEvent;
4
+ export declare function createApprovalClaimEvent(approvals: () => ApprovalStore): ClientEvent;
4
5
  //# sourceMappingURL=client-event.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"client-event.d.ts","sourceRoot":"","sources":["../../src/approvals/client-event.ts"],"names":[],"mappings":"AAOA,OAAO,EAAqB,KAAK,WAAW,EAAE,MAAM,2BAA2B,CAAC;AAChF,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAGhD,wBAAgB,yBAAyB,CAAC,SAAS,EAAE,MAAM,aAAa,GAAG,WAAW,CAcrF"}
1
+ {"version":3,"file":"client-event.d.ts","sourceRoot":"","sources":["../../src/approvals/client-event.ts"],"names":[],"mappings":"AAkBA,OAAO,EAAqB,KAAK,WAAW,EAAE,MAAM,2BAA2B,CAAC;AAChF,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAGhD,wBAAgB,yBAAyB,CAAC,SAAS,EAAE,MAAM,aAAa,GAAG,WAAW,CAcrF;AAED,wBAAgB,wBAAwB,CAAC,SAAS,EAAE,MAAM,aAAa,GAAG,WAAW,CAiBpF"}
@@ -1,12 +1,17 @@
1
1
  /**
2
- * `approval:decide`: the user's click on the approval card,
3
- * on their own authenticated socket. The decider is the socket's verified
4
- * identity, never one the payload names, and an approval's token is answered
5
- * only to this socket, in the event's ack.
2
+ * The approval card's events, on the person's own authenticated socket:
3
+ *
4
+ * - `approval:decide`: the user's click on the approval card. The decider is
5
+ * the socket's verified identity, never one the payload names, and an
6
+ * approval's token is answered only to this socket, in the event's ack.
7
+ * - `approval:claim`: the tab takes the grant the store pushed to its room
8
+ * when the person approved an action on their page by voice, on the phone or
9
+ * in chat. The claimer is the socket's verified identity, in the
10
+ * rooms the server holds it in; only the first claim gets the grant.
6
11
  */
7
- import { APPROVAL_DECIDE_EVENT } from '@ouispec/agent-core';
12
+ import { APPROVAL_CLAIM_EVENT, APPROVAL_DECIDE_EVENT, } from '@ouispec/agent-core';
8
13
  import { defineClientEvent } from '../client-events/chain.js';
9
- import { decidePayloadSchema } from './schemas.js';
14
+ import { claimPayloadSchema, decidePayloadSchema } from './schemas.js';
10
15
  export function createApprovalDecideEvent(approvals) {
11
16
  return defineClientEvent({
12
17
  name: APPROVAL_DECIDE_EVENT,
@@ -22,4 +27,22 @@ export function createApprovalDecideEvent(approvals) {
22
27
  },
23
28
  });
24
29
  }
30
+ export function createApprovalClaimEvent(approvals) {
31
+ return defineClientEvent({
32
+ name: APPROVAL_CLAIM_EVENT,
33
+ schema: claimPayloadSchema,
34
+ maxBytes: 1024,
35
+ // One per tab per approval; a burst is a script.
36
+ rate: { perSecond: 2, burst: 5 },
37
+ refusal: (reason) => ({ ok: false, reason: 'invalid', error: reason }),
38
+ handle: async ({ socket, user }, payload, ack) => {
39
+ const result = await approvals().claim(payload.approvalId, payload.grantId, {
40
+ userId: user.userId,
41
+ socketId: socket.id,
42
+ rooms: [...socket.rooms],
43
+ });
44
+ ack?.(result);
45
+ },
46
+ });
47
+ }
25
48
  //# sourceMappingURL=client-event.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"client-event.js","sourceRoot":"","sources":["../../src/approvals/client-event.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EAAE,qBAAqB,EAAoD,MAAM,qBAAqB,CAAC;AAC9G,OAAO,EAAE,iBAAiB,EAAoB,MAAM,2BAA2B,CAAC;AAEhF,OAAO,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AAEnD,MAAM,UAAU,yBAAyB,CAAC,SAA8B;IACtE,OAAO,iBAAiB,CAAwB;QAC9C,IAAI,EAAE,qBAAqB;QAC3B,MAAM,EAAE,mBAAmB;QAC3B,QAAQ,EAAE,IAAI;QACd,wCAAwC;QACxC,IAAI,EAAE,EAAE,SAAS,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE;QAChC,0FAA0F;QAC1F,OAAO,EAAE,CAAC,MAAM,EAAmB,EAAE,CAAC,CAAC,EAAE,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC;QACvF,MAAM,EAAE,KAAK,EAAE,EAAE,IAA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CAAC,QAAQ,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC;YAChI,GAAG,EAAE,CAAC,MAAM,CAAC,CAAC;QAChB,CAAC;KACF,CAAC,CAAC;AACL,CAAC;AAED,MAAM,UAAU,wBAAwB,CAAC,SAA8B;IACrE,OAAO,iBAAiB,CAAuB;QAC7C,IAAI,EAAE,oBAAoB;QAC1B,MAAM,EAAE,kBAAkB;QAC1B,QAAQ,EAAE,IAAI;QACd,iDAAiD;QACjD,IAAI,EAAE,EAAE,SAAS,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE;QAChC,OAAO,EAAE,CAAC,MAAM,EAAmB,EAAE,CAAC,CAAC,EAAE,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC;QACvF,MAAM,EAAE,KAAK,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE,OAAO,EAAE,GAAG,EAAE,EAAE;YAC/C,MAAM,MAAM,GAAG,MAAM,SAAS,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,UAAU,EAAE,OAAO,CAAC,OAAO,EAAE;gBAC1E,MAAM,EAAE,IAAI,CAAC,MAAM;gBACnB,QAAQ,EAAE,MAAM,CAAC,EAAE;gBACnB,KAAK,EAAE,CAAC,GAAG,MAAM,CAAC,KAAK,CAAC;aACzB,CAAC,CAAC;YACH,GAAG,EAAE,CAAC,MAAM,CAAC,CAAC;QAChB,CAAC;KACF,CAAC,CAAC;AACL,CAAC"}
@@ -18,6 +18,8 @@ import type { ApprovalStore } from './store.js';
18
18
  export interface ApprovalRouteDeps {
19
19
  approvals: ApprovalStore;
20
20
  isInternalKey: (presented: string | undefined) => boolean;
21
+ /** The product's room names: the room stored with an action on the person's page must be one. */
22
+ isValidRoom: (room: string) => boolean;
21
23
  }
22
24
  export declare function approvalRouter(deps: ApprovalRouteDeps): Router;
23
25
  //# sourceMappingURL=routes.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"routes.d.ts","sourceRoot":"","sources":["../../src/approvals/routes.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,OAAO,EAAE,MAAM,EAA+B,MAAM,SAAS,CAAC;AAU9D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAGhD,MAAM,WAAW,iBAAiB;IAChC,SAAS,EAAE,aAAa,CAAC;IACzB,aAAa,EAAE,CAAC,SAAS,EAAE,MAAM,GAAG,SAAS,KAAK,OAAO,CAAC;CAC3D;AAkBD,wBAAgB,cAAc,CAAC,IAAI,EAAE,iBAAiB,GAAG,MAAM,CAqG9D"}
1
+ {"version":3,"file":"routes.d.ts","sourceRoot":"","sources":["../../src/approvals/routes.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,OAAO,EAAE,MAAM,EAA+B,MAAM,SAAS,CAAC;AAU9D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAGhD,MAAM,WAAW,iBAAiB;IAChC,SAAS,EAAE,aAAa,CAAC;IACzB,aAAa,EAAE,CAAC,SAAS,EAAE,MAAM,GAAG,SAAS,KAAK,OAAO,CAAC;IAC1D,iGAAiG;IACjG,WAAW,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC;CACxC;AAkBD,wBAAgB,cAAc,CAAC,IAAI,EAAE,iBAAiB,GAAG,MAAM,CAyG9D"}
@@ -60,6 +60,10 @@ export function approvalRouter(deps) {
60
60
  const body = accept(req, res, pendingApprovalSchema);
61
61
  if (!body)
62
62
  return;
63
+ if (body.room !== undefined && !deps.isValidRoom(body.room)) {
64
+ res.status(400).json({ error: `room "${body.room}" is not a room this product uses`, reason: 'invalid' });
65
+ return;
66
+ }
63
67
  const result = await deps.approvals.create(body);
64
68
  if (!result.ok) {
65
69
  res.status(result.reason === 'decided' ? 409 : 400).json({ error: result.error, reason: result.reason });
@@ -1 +1 @@
1
- {"version":3,"file":"routes.js","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C,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,gCAAgC,EAAE,MAAM,EAAE,SAAS,EAAE,CAAC,CAAC;YACrF,OAAO;QACT,CAAC;QACD,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IACnB,CAAC,CAAC,CAAC;IAEH,OAAO,MAAM,CAAC;AAChB,CAAC"}
@@ -1,7 +1,8 @@
1
- /** The shapes the approval endpoints and the `approval:decide` event accept. Unknown keys are refused. */
1
+ /** The shapes the approval endpoints and the `approval:decide` and `approval:claim` events accept. Unknown keys are refused. */
2
2
  import Joi from 'joi';
3
3
  export declare const pendingApprovalSchema: Joi.ObjectSchema<any>;
4
4
  export declare const decidePayloadSchema: Joi.ObjectSchema<any>;
5
+ export declare const claimPayloadSchema: Joi.ObjectSchema<any>;
5
6
  export declare const internalDecideSchema: Joi.ObjectSchema<any>;
6
7
  export declare const redeemSchema: Joi.ObjectSchema<any>;
7
8
  //# sourceMappingURL=schemas.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"schemas.d.ts","sourceRoot":"","sources":["../../src/approvals/schemas.ts"],"names":[],"mappings":"AAAA,0GAA0G;AAC1G,OAAO,GAAG,MAAM,KAAK,CAAC;AAMtB,eAAO,MAAM,qBAAqB,uBAkChC,CAAC;AAEH,eAAO,MAAM,mBAAmB,uBAG9B,CAAC;AAEH,eAAO,MAAM,oBAAoB,uBAM/B,CAAC;AAEH,eAAO,MAAM,YAAY,uBAIvB,CAAC"}
1
+ {"version":3,"file":"schemas.d.ts","sourceRoot":"","sources":["../../src/approvals/schemas.ts"],"names":[],"mappings":"AAAA,gIAAgI;AAChI,OAAO,GAAG,MAAM,KAAK,CAAC;AAMtB,eAAO,MAAM,qBAAqB,uBAoChC,CAAC;AAEH,eAAO,MAAM,mBAAmB,uBAG9B,CAAC;AAEH,eAAO,MAAM,kBAAkB,uBAG7B,CAAC;AAEH,eAAO,MAAM,oBAAoB,uBAM/B,CAAC;AAEH,eAAO,MAAM,YAAY,uBAIvB,CAAC"}
@@ -1,4 +1,4 @@
1
- /** The shapes the approval endpoints and the `approval:decide` event accept. Unknown keys are refused. */
1
+ /** The shapes the approval endpoints and the `approval:decide` and `approval:claim` events accept. Unknown keys are refused. */
2
2
  import Joi from 'joi';
3
3
  import { APPROVAL_CHANNELS, APPROVAL_PREVIEW_LIMITS as L, ARGS_HASH_PATTERN } from '@ouispec/agent-core';
4
4
  const id = Joi.string().min(1).max(200);
@@ -12,6 +12,8 @@ export const pendingApprovalSchema = Joi.object({
12
12
  accountId: id,
13
13
  tool: id.required(),
14
14
  toolKind: Joi.string().valid('ui', 'backend'),
15
+ // The room of the turn that asked, for an action on the person's page; the route checks it is one of the product's.
16
+ room: Joi.string().min(1).max(200),
15
17
  operationId: id,
16
18
  // An origin; the store checks it is exactly one.
17
19
  audience: Joi.string().max(2048).pattern(/^https?:\/\/[^/?#]+$/),
@@ -40,6 +42,10 @@ export const decidePayloadSchema = Joi.object({
40
42
  approvalId: id.required(),
41
43
  decision: Joi.string().valid('approve', 'decline').required(),
42
44
  });
45
+ export const claimPayloadSchema = Joi.object({
46
+ approvalId: id.required(),
47
+ grantId: id.required(),
48
+ });
43
49
  export const internalDecideSchema = Joi.object({
44
50
  userId: id.required(),
45
51
  decision: Joi.string().valid('approve', 'decline').required(),
@@ -1 +1 @@
1
- {"version":3,"file":"schemas.js","sourceRoot":"","sources":["../../src/approvals/schemas.ts"],"names":[],"mappings":"AAAA,0GAA0G;AAC1G,OAAO,GAAG,MAAM,KAAK,CAAC;AACtB,OAAO,EAAE,iBAAiB,EAAE,uBAAuB,IAAI,CAAC,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAEzG,MAAM,EAAE,GAAG,GAAG,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;AACxC,MAAM,IAAI,GAAG,CAAC,GAAW,EAAE,EAAE,CAAC,GAAG,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KAAK,EAAE,GAAG,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,QAAQ,EAAE;IACxC,MAAM,EAAE,EAAE,CAAC,QAAQ,EAAE;IACrB,cAAc,EAAE,EAAE,CAAC,QAAQ,EAAE;CAC9B,CAAC,CAAC"}
@@ -1,4 +1,4 @@
1
- import { type ApprovalChannel, type ApprovalDecideResult, type ApprovalDecision, type ApprovalOwner, type ApprovalRedeemResult, type ApprovalRefusal, type ApprovalSettlement, type ApprovalStatus, type ApprovalWithdrawal, type ApprovalWithdrawReason, type PendingApprovalInput } from '@ouispec/agent-core';
1
+ import { type ApprovalChannel, type ApprovalClaimResult, type ApprovalDecideResult, type ApprovalDeclinedEvent, type ApprovalGrantedEvent, type ApprovalDecision, type ApprovalOwner, type ApprovalRedeemResult, type ApprovalRefusal, type ApprovalSettlement, type ApprovalStatus, type ApprovalWithdrawal, type ApprovalWithdrawReason, type PendingApprovalInput } from '@ouispec/agent-core';
2
2
  import type { RealtimeLogger } from '../logger.js';
3
3
  import type { ApprovalTokenSigner } from './token.js';
4
4
  import type { ApprovalReceiptSigner } from './receipt.js';
@@ -14,12 +14,24 @@ export interface ApprovalStore {
14
14
  argsHash: string;
15
15
  expiresAt: number;
16
16
  } | ApprovalRefusal>;
17
- /** The user's decision. An approval's token is returned only here, to the decider. */
17
+ /**
18
+ * The user's decision. An approval's token is returned only here, to the
19
+ * decider. An action on the person's page approved on `voice`, `phone` or
20
+ * `chat` also gets a single-use grant, pushed to the room stored with it
21
+ * (`agent:approval_granted`); declined in any conversation channel, the
22
+ * decline is pushed there (`agent:approval_declined`).
23
+ */
18
24
  decide(approvalId: string, by: {
19
25
  userId: string;
20
26
  decision: ApprovalDecision;
21
27
  channel: ApprovalChannel;
22
28
  }): Promise<ApprovalDecideResult>;
29
+ /**
30
+ * A tab takes the grant pushed to its room: answered with the grant only for
31
+ * the first claim, from a socket of the approval's user that is in the
32
+ * grant's room, before the grant expires.
33
+ */
34
+ claim(approvalId: string, grantId: string, claimer: ApprovalClaimer): Promise<ApprovalClaimResult>;
23
35
  /** Atomic single use: the stored call, for a valid, unexpired, unused token of this user and conversation. */
24
36
  redeem(token: string, caller: {
25
37
  userId: string;
@@ -46,6 +58,19 @@ export interface ApprovalStore {
46
58
  * as any expiry (`settleExpired`), and is told it was withdrawn.
47
59
  */
48
60
  withdraw(approvalId: string, owner: ApprovalOwner, reason: ApprovalWithdrawReason): Promise<ApprovalWithdrawal>;
61
+ /**
62
+ * Withdraw every approval of a conversation that is still waiting, or
63
+ * approved and not yet used, whoever's turn asked for it: a person on the
64
+ * staff took the conversation over, and did not ask for any of them. Each
65
+ * as `withdraw` does it. Resolves with the ids withdrawn.
66
+ */
67
+ withdrawOpen(conversationId: string, reason: ApprovalWithdrawReason): Promise<string[]>;
68
+ }
69
+ /** Who claims a pushed grant: the socket's verified user, the socket, and the rooms it is in now. */
70
+ export interface ApprovalClaimer {
71
+ userId: string;
72
+ socketId: string;
73
+ rooms: readonly string[];
49
74
  }
50
75
  /** How long a decline is remembered for the turn that follows it. */
51
76
  export declare const DECLINED_TTL_SEC: number;
@@ -60,6 +85,13 @@ export interface ApprovalStoreOptions {
60
85
  signer: ApprovalReceiptSigner;
61
86
  defaultAudience: string;
62
87
  };
88
+ /**
89
+ * Sends a server event to a room: how a grant or a decline reaches the tab
90
+ * of an action on the person's page decided in a conversation channel. The
91
+ * realtime server passes its socket.io server's. Without it, nothing is
92
+ * pushed, and an action on the person's page is approved only on its card.
93
+ */
94
+ push?: (room: string, event: string, payload: ApprovalGrantedEvent | ApprovalDeclinedEvent) => void;
63
95
  }
64
96
  export declare function createApprovalStore(redis: ApprovalRedis, signer: ApprovalTokenSigner, logger: RealtimeLogger, options?: ApprovalStoreOptions): ApprovalStore;
65
97
  //# sourceMappingURL=store.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"store.d.ts","sourceRoot":"","sources":["../../src/approvals/store.ts"],"names":[],"mappings":"AAkCA,OAAO,EAOL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AC3B,MAAM,EAAE,cAAc,EACtB,OAAO,GAAE,oBAAyB,GACjC,aAAa,CA6Wf"}
@@ -7,7 +7,10 @@
7
7
  * approval:{id}:state → hash: status (pending | approved), userId,
8
8
  * conversationId, tool, argsHash, expiresAt, the
9
9
  * receipt's audience (fixed here, empty for none),
10
- * and once approved the token's jti and the channel
10
+ * the tool's kind (`ui` for an action on the
11
+ * person's page) and, for one, the room of the
12
+ * turn that asked; once approved the token's jti
13
+ * and the channel
11
14
  * approval:declined:{id} → what the next turn tells the model, 30 min
12
15
  * approval:{id}:seen → that it was asked for and has not run or been
13
16
  * declined (userId, conversationId, expiresAt,
@@ -20,9 +23,22 @@
20
23
  * having run: undecided, or approved and unused.
21
24
  * approval:{id}:settled → a turn's claim to store that expiry: a two
22
25
  * minute lease, permanent once confirmed
26
+ * approval:{id}:grant → for an action on the person's page approved
27
+ * by voice, on the phone or in chat: the
28
+ * single-use grant pushed to its room (grantId,
29
+ * userId, conversationId, room, argsHash,
30
+ * expiresAt, channel, and the claiming socket once
31
+ * claimed), written in the script that approves
32
+ * it, until the grant expires
33
+ * approval:conversation:{conversationId}
34
+ * → set of the conversation's approval ids, kept as
35
+ * long as its longest-lived approval: what a
36
+ * take-over withdraws (`withdrawOpen`). An id
37
+ * whose approval has gone is removed then.
23
38
  *
24
- * Each decision and each redemption is one Lua script, so two instances can
25
- * never both approve one call, or both redeem one token. The stored call is
39
+ * Each decision, each claim and each redemption is one Lua script, so two
40
+ * instances can never both approve one call, both hand one grant to a tab, or
41
+ * both redeem one token. The stored call is
26
42
  * kept as the worker wrote it and never re-encoded inside Redis: Lua's JSON
27
43
  * would round numbers and turn `[]` into `{}`, and the redeemed call must be
28
44
  * exactly the one the user approved.
@@ -32,7 +48,7 @@
32
48
  * chosen at redemption. A UI action gets none.
33
49
  */
34
50
  import crypto from 'node:crypto';
35
- import { APPROVAL_WITHDRAW_REASONS, approvalReceiptAudience, argsHash as hashOf, EXPIRED_APPROVAL_MEMORY_MS, EXPIRY_CLAIM_LEASE_MS, MAX_APPROVAL_TTL_MS, } from '@ouispec/agent-core';
51
+ import { APPROVAL_GRANT_TTL_MS, APPROVAL_PUSH_EVENTS, APPROVAL_WITHDRAW_REASONS, approvalReceiptAudience, approvesUIByReadback, argsHash as hashOf, EXPIRED_APPROVAL_MEMORY_MS, EXPIRY_CLAIM_LEASE_MS, MAX_APPROVAL_TTL_MS, } from '@ouispec/agent-core';
36
52
  /** How long a decline is remembered for the turn that follows it. */
37
53
  export const DECLINED_TTL_SEC = 30 * 60;
38
54
  const recordKey = (id) => `approval:${id}`;
@@ -41,36 +57,72 @@ const declinedKey = (id) => `approval:declined:${id}`;
41
57
  const seenKey = (id) => `approval:${id}:seen`;
42
58
  const settledKey = (id) => `approval:${id}:settled`;
43
59
  const withdrawnKey = (id) => `approval:${id}:withdrawn`;
44
- // KEYS: record, state, declined, seen, settled, withdrawn. ARGV: record JSON, ttl ms, userId, conversationId, tool,
45
- // argsHash, expiresAt, seen JSON, seen ttl ms, receipt audience ('' for none).
60
+ const grantKey = (id) => `approval:${id}:grant`;
61
+ const conversationKey = (conversationId) => `approval:conversation:${conversationId}`;
62
+ // KEYS: record, state, declined, seen, settled, withdrawn, conversation. ARGV: record JSON, ttl ms, userId,
63
+ // conversationId, tool, argsHash, expiresAt, seen JSON, seen ttl ms, receipt audience ('' for none), tool kind,
64
+ // approval id, room ('' for none).
46
65
  // A new approval supersedes an old decline under the same id, an old expiry's settlement, and an old withdrawal.
66
+ // The conversation's set of approvals lasts as long as its longest-lived one.
47
67
  const CREATE = `
48
68
  if redis.call('EXISTS', KEYS[1]) == 1 or redis.call('EXISTS', KEYS[2]) == 1 then return 'exists' end
49
69
  redis.call('DEL', KEYS[3], KEYS[5], KEYS[6])
50
70
  redis.call('SET', KEYS[4], ARGV[8], 'PX', ARGV[9])
51
71
  redis.call('SET', KEYS[1], ARGV[1], 'PX', ARGV[2])
52
- redis.call('HSET', KEYS[2], 'status', 'pending', 'userId', ARGV[3], 'conversationId', ARGV[4], 'tool', ARGV[5], 'argsHash', ARGV[6], 'expiresAt', ARGV[7], 'audience', ARGV[10])
72
+ redis.call('HSET', KEYS[2], 'status', 'pending', 'userId', ARGV[3], 'conversationId', ARGV[4], 'tool', ARGV[5], 'argsHash', ARGV[6], 'expiresAt', ARGV[7], 'audience', ARGV[10], 'toolKind', ARGV[11], 'room', ARGV[13])
53
73
  redis.call('PEXPIRE', KEYS[2], ARGV[2])
74
+ redis.call('SADD', KEYS[7], ARGV[12])
75
+ if redis.call('PTTL', KEYS[7]) < tonumber(ARGV[2]) then redis.call('PEXPIRE', KEYS[7], ARGV[2]) end
54
76
  return 'ok'`;
55
- // KEYS: state, record, declined, seen. ARGV: userId, decision, now ms, jti, channel, declined ttl s, declined JSON,
56
- // seen JSON once approved.
77
+ // KEYS: state, record, declined, seen, grant. ARGV: userId, decision, now ms, jti, channel, declined ttl s, declined
78
+ // JSON, seen JSON once approved, whether this channel may approve an action on the person's page by its readback
79
+ // ('1' or '0'), grant id, grant ttl ms.
57
80
  // A decline decides it: it is no longer something that can expire. An approval is recorded in the
58
81
  // memory (same TTL), so if the approved call is never run its expiry is not told as "undecided".
82
+ // An action on the person's page is approved by its card, or by its readback on a channel that may: then
83
+ // only with the room stored with it, where the single-use grant is written for the tab to claim. The grant lasts
84
+ // until the approval expires or its own ttl runs out, whichever is first. Answers the room for the store to push to.
59
85
  const DECIDE = `
60
86
  if redis.call('EXISTS', KEYS[1]) == 0 then return {'unknown'} end
61
- local s = redis.call('HMGET', KEYS[1], 'status', 'userId', 'expiresAt')
87
+ local s = redis.call('HMGET', KEYS[1], 'status', 'userId', 'expiresAt', 'toolKind', 'room', 'conversationId', 'argsHash')
62
88
  if s[2] ~= ARGV[1] then return {'forbidden'} end
63
89
  if s[1] ~= 'pending' then return {'decided'} end
64
- if tonumber(ARGV[3]) >= tonumber(s[3]) then return {'expired'} end
90
+ local now = tonumber(ARGV[3])
91
+ if now >= tonumber(s[3]) then return {'expired'} end
92
+ local onPage = s[4] == 'ui' and ARGV[5] ~= 'ui'
93
+ local room = s[5] or ''
94
+ if ARGV[2] == 'approve' and onPage and (ARGV[9] ~= '1' or room == '') then return {'channel'} end
65
95
  local record = redis.call('GET', KEYS[2])
66
96
  if ARGV[2] == 'approve' then
67
97
  redis.call('HSET', KEYS[1], 'status', 'approved', 'jti', ARGV[4], 'channel', ARGV[5])
68
98
  if redis.call('EXISTS', KEYS[4]) == 1 then redis.call('SET', KEYS[4], ARGV[8], 'KEEPTTL') end
69
- return {'approved', record}
99
+ if not onPage then return {'approved', record} end
100
+ local until_ = math.min(now + tonumber(ARGV[11]), tonumber(s[3]))
101
+ redis.call('DEL', KEYS[5])
102
+ redis.call('HSET', KEYS[5], 'grantId', ARGV[10], 'userId', s[2], 'conversationId', s[6], 'room', room, 'argsHash', s[7], 'expiresAt', tostring(until_), 'channel', ARGV[5], 'claimed', '')
103
+ -- Kept a minute past its end, so a late or replayed claim is told why.
104
+ redis.call('PEXPIRE', KEYS[5], until_ - now + 60000)
105
+ return {'approved', record, room, tostring(until_)}
70
106
  end
71
107
  redis.call('DEL', KEYS[1], KEYS[2], KEYS[4])
72
108
  redis.call('SET', KEYS[3], ARGV[7], 'EX', ARGV[6])
109
+ if onPage then return {'declined', record, room} end
73
110
  return {'declined', record}`;
111
+ // KEYS: grant. ARGV: grant id, userId, now ms, socket id, the socket's rooms (JSON array).
112
+ // The first claim from the approval's user, on a socket in the grant's room, before it expires, takes it. The grant
113
+ // is kept until it expires, so a replayed claim is refused as used.
114
+ const CLAIM = `
115
+ if redis.call('EXISTS', KEYS[1]) == 0 then return {'unknown'} end
116
+ local g = redis.call('HMGET', KEYS[1], 'grantId', 'userId', 'room', 'expiresAt', 'claimed', 'argsHash', 'channel')
117
+ if g[1] ~= ARGV[1] then return {'mismatch'} end
118
+ if g[2] ~= ARGV[2] then return {'forbidden'} end
119
+ if tonumber(ARGV[3]) >= tonumber(g[4]) then return {'expired'} end
120
+ local inRoom = false
121
+ for _, r in ipairs(cjson.decode(ARGV[5])) do if r == g[3] then inRoom = true end end
122
+ if not inRoom then return {'forbidden'} end
123
+ if g[5] ~= '' then return {'used'} end
124
+ redis.call('HSET', KEYS[1], 'claimed', ARGV[4])
125
+ return {'ok', g[6], g[4], g[7], g[3]}`;
74
126
  // KEYS: state, record, seen. ARGV: jti, argsHash, tool, userId, conversationId.
75
127
  // A redemption uses it: it did not expire undecided. It answers the receipt audience fixed at creation.
76
128
  const REDEEM = `
@@ -82,26 +134,30 @@ end
82
134
  local record = redis.call('GET', KEYS[2])
83
135
  redis.call('DEL', KEYS[1], KEYS[2], KEYS[3])
84
136
  return {'ok', record, s[7], s[8] or ''}`;
85
- // KEYS: state, record, seen, withdrawn. ARGV: userId, conversationId, reason.
137
+ // KEYS: state, record, seen, withdrawn, grant, and the conversation's set when the hold withdraws it. ARGV: userId (''
138
+ // for any user of the conversation: the server's own authority, on a take-over), conversationId, reason, approval id.
86
139
  // Expire-now. A pending approval, or an approved one not yet redeemed, loses its state and record,
87
140
  // which is exactly what its time running out does: a decision is then refused, a token redeemed
88
141
  // after it answers 'used', and SETTLE finds "state gone, seen present". The memory (seen) is left
89
142
  // as it is, so one the person had approved still says 'approved'; why it was withdrawn is kept
90
- // beside it for as long as the memory lasts.
143
+ // beside it for as long as the memory lasts. A grant pushed for it and not yet claimed can no longer be claimed.
91
144
  const WITHDRAW = `
145
+ if KEYS[6] then redis.call('SREM', KEYS[6], ARGV[4]) end
92
146
  if redis.call('EXISTS', KEYS[1]) == 0 then
93
147
  local seen = redis.call('GET', KEYS[3])
94
148
  if not seen then return 'unknown' end
95
149
  local m = cjson.decode(seen)
96
- if m['userId'] ~= ARGV[1] or m['conversationId'] ~= ARGV[2] then return 'unknown' end
150
+ if (ARGV[1] ~= '' and m['userId'] ~= ARGV[1]) or m['conversationId'] ~= ARGV[2] then return 'unknown' end
97
151
  return 'settled'
98
152
  end
99
153
  local o = redis.call('HMGET', KEYS[1], 'userId', 'conversationId')
100
- if o[1] ~= ARGV[1] or o[2] ~= ARGV[2] then return 'unknown' end
101
- redis.call('DEL', KEYS[1], KEYS[2])
154
+ if (ARGV[1] ~= '' and o[1] ~= ARGV[1]) or o[2] ~= ARGV[2] then return 'unknown' end
155
+ redis.call('DEL', KEYS[1], KEYS[2], KEYS[5])
102
156
  local left = redis.call('PTTL', KEYS[3])
103
157
  if left > 0 then redis.call('SET', KEYS[4], ARGV[3], 'PX', left) end
104
158
  return 'withdrawn'`;
159
+ // KEYS: conversation set. The conversation's approval ids.
160
+ const OPEN_IN_CONVERSATION = `return redis.call('SMEMBERS', KEYS[1])`;
105
161
  // KEYS: state, seen, settled, withdrawn. ARGV: userId, conversationId, lease ms.
106
162
  // The approval's own keys lapse in Redis at its expiry, so "state gone, seen present" is this
107
163
  // server's Redis saying it expired undecided. The claim is one SET NX: exactly one caller gets it,
@@ -150,10 +206,19 @@ const REFUSALS = {
150
206
  expired: 'this approval has expired',
151
207
  used: 'this approval has already been used',
152
208
  mismatch: 'this token is not for the stored call',
209
+ channel: "an action on the person's page is approved on its card, or by its readback by voice, on the phone or in chat when it was stored with its turn's room; never by SMS",
210
+ };
211
+ const CLAIM_REFUSALS = {
212
+ unknown: 'no such grant is waiting: it was never pushed, was withdrawn, or has expired',
213
+ mismatch: 'this is not the grant that was pushed',
214
+ forbidden: "this grant is another user's, or this tab is not in its room",
215
+ expired: 'this grant has expired',
216
+ used: 'another tab has already taken this grant',
153
217
  };
154
218
  export function createApprovalStore(redis, signer, logger, options = {}) {
155
219
  const expiryClaimLeaseMs = options.expiryClaimLeaseMs ?? EXPIRY_CLAIM_LEASE_MS;
156
220
  const receipts = options.receipts ?? null;
221
+ const push = options.push ?? null;
157
222
  /**
158
223
  * The receipt audience, fixed as the approval is stored: none for a UI action
159
224
  * (the browser checks its own grant), the tool's own for a host or API tool,
@@ -166,6 +231,8 @@ export function createApprovalStore(redis, signer, logger, options = {}) {
166
231
  if (input.toolKind === 'ui') {
167
232
  return input.audience === undefined ? { ok: true, audience: '' } : refusal('invalid', 'a UI action gets no receipt, so it names no audience');
168
233
  }
234
+ if (input.room !== undefined)
235
+ return refusal('invalid', "only an action on the person's page names the room of its turn");
169
236
  if (!receipts)
170
237
  return { ok: true, audience: '' };
171
238
  return { ok: true, audience: input.audience ?? receipts.defaultAudience };
@@ -241,10 +308,10 @@ export function createApprovalStore(redis, signer, logger, options = {}) {
241
308
  if (!audience.ok)
242
309
  return audience;
243
310
  const seen = { userId: input.userId, conversationId: input.conversationId, expiresAt: input.expiresAt };
244
- const result = await redis.eval(CREATE, 6, recordKey(input.approvalId), stateKey(input.approvalId), declinedKey(input.approvalId), seenKey(input.approvalId), settledKey(input.approvalId), withdrawnKey(input.approvalId), JSON.stringify(input), input.expiresAt - now, input.userId, input.conversationId, input.tool, input.argsHash, input.expiresAt, JSON.stringify(seen), input.expiresAt - now + EXPIRED_APPROVAL_MEMORY_MS, audience.audience);
311
+ const result = await redis.eval(CREATE, 7, recordKey(input.approvalId), stateKey(input.approvalId), declinedKey(input.approvalId), seenKey(input.approvalId), settledKey(input.approvalId), withdrawnKey(input.approvalId), conversationKey(input.conversationId), JSON.stringify(input), input.expiresAt - now, input.userId, input.conversationId, input.tool, input.argsHash, input.expiresAt, JSON.stringify(seen), input.expiresAt - now + EXPIRED_APPROVAL_MEMORY_MS, audience.audience, input.toolKind ?? 'backend', input.approvalId, input.room ?? '');
245
312
  if (result !== 'ok')
246
313
  return refusal('decided', `an approval ${input.approvalId} already exists`);
247
- logger.info(audit(input, { expiresAt: input.expiresAt, ...(audience.audience ? { audience: audience.audience } : {}) }), 'Approval stored');
314
+ logger.info(audit(input, { expiresAt: input.expiresAt, ...(audience.audience ? { audience: audience.audience } : {}), ...(input.room ? { room: input.room } : {}) }), 'Approval stored');
248
315
  return { ok: true, approvalId: input.approvalId, argsHash: input.argsHash, expiresAt: input.expiresAt };
249
316
  },
250
317
  async decide(approvalId, { userId, decision, channel }) {
@@ -257,18 +324,25 @@ export function createApprovalStore(redis, signer, logger, options = {}) {
257
324
  tool: seen.kind === 'open' ? seen.pending.tool : '',
258
325
  title: seen.kind === 'open' ? seen.pending.preview.title : '',
259
326
  };
260
- const [outcome, raw] = (await redis.eval(DECIDE, 4, stateKey(approvalId), recordKey(approvalId), declinedKey(approvalId), seenKey(approvalId), userId, decision, Date.now(), jti, channel, DECLINED_TTL_SEC, JSON.stringify(declined),
327
+ const grantId = crypto.randomUUID();
328
+ const [outcome, raw, room, grantUntil] = (await redis.eval(DECIDE, 5, stateKey(approvalId), recordKey(approvalId), declinedKey(approvalId), seenKey(approvalId), grantKey(approvalId), userId, decision, Date.now(), jti, channel, DECLINED_TTL_SEC, JSON.stringify(declined),
261
329
  // The memory of the approval once it is approved: written by the script, never re-encoded in Lua.
262
330
  seen.kind === 'open'
263
331
  ? JSON.stringify({ userId: seen.pending.userId, conversationId: seen.pending.conversationId, expiresAt: seen.pending.expiresAt, decided: 'approved' })
264
- : ''));
332
+ : '',
333
+ // A grant can reach the tab only when the server can push it.
334
+ push && approvesUIByReadback(channel) ? '1' : '0', grantId, APPROVAL_GRANT_TTL_MS));
265
335
  if (outcome !== 'approved' && outcome !== 'declined') {
266
336
  logger.warn({ approvalId, userId, decision, channel, reason: outcome }, 'Approval decision refused');
267
337
  return refusal(outcome, REFUSALS[outcome] ?? outcome);
268
338
  }
269
339
  const pending = JSON.parse(raw);
270
340
  if (outcome === 'declined') {
271
- logger.info(audit(pending, { channel }), 'Approval declined');
341
+ logger.info(audit(pending, { channel, ...(room ? { room } : {}) }), 'Approval declined');
342
+ // The card on the person's page says it was declined where they said so.
343
+ if (room && push && channel !== 'ui') {
344
+ push(room, APPROVAL_PUSH_EVENTS.DECLINED, { approvalId, conversationId: pending.conversationId, channel, timestamp: Date.now() });
345
+ }
272
346
  return { ok: true, decision: 'decline', approvalId };
273
347
  }
274
348
  const token = signer.sign({
@@ -283,9 +357,36 @@ export function createApprovalStore(redis, signer, logger, options = {}) {
283
357
  exp: Math.floor(pending.expiresAt / 1000),
284
358
  jti,
285
359
  });
286
- logger.info(audit(pending, { channel, expiresAt: pending.expiresAt }), 'Approval approved');
360
+ if (room && grantUntil && push && approvesUIByReadback(channel)) {
361
+ // Written in the script that approved it: the tab on the room claims it, once.
362
+ const grant = {
363
+ approvalId,
364
+ grantId,
365
+ argsHash: pending.argsHash,
366
+ expiresAt: Number(grantUntil),
367
+ conversationId: pending.conversationId,
368
+ room,
369
+ channel,
370
+ timestamp: Date.now(),
371
+ };
372
+ push(room, APPROVAL_PUSH_EVENTS.GRANTED, grant);
373
+ logger.info(audit(pending, { channel, expiresAt: pending.expiresAt, room, grantId, grantExpiresAt: grant.expiresAt }), 'Approval approved; grant pushed to the room');
374
+ }
375
+ else {
376
+ logger.info(audit(pending, { channel, expiresAt: pending.expiresAt }), 'Approval approved');
377
+ }
287
378
  return { ok: true, decision: 'approve', approvalId, token, argsHash: pending.argsHash, expiresAt: pending.expiresAt, channel };
288
379
  },
380
+ async claim(approvalId, grantId, claimer) {
381
+ const [outcome, hash, until, channel, room] = ((await redis.eval(CLAIM, 1, grantKey(approvalId), grantId, claimer.userId, Date.now(), claimer.socketId, JSON.stringify(claimer.rooms))) ?? []);
382
+ if (outcome !== 'ok' || !hash || !until || !channel) {
383
+ const reason = (outcome ?? 'unknown');
384
+ logger.warn({ approvalId, grantId, userId: claimer.userId, socketId: claimer.socketId, reason }, 'Approval grant claim refused');
385
+ return refusal(reason, CLAIM_REFUSALS[reason] ?? reason);
386
+ }
387
+ logger.info({ approvalId, grantId, userId: claimer.userId, socketId: claimer.socketId, room, channel }, 'Approval grant claimed');
388
+ return { ok: true, approvalId, argsHash: hash, expiresAt: Number(until), channel: channel };
389
+ },
289
390
  async redeem(token, caller) {
290
391
  const checked = signer.verify(token);
291
392
  if (!checked.ok) {
@@ -345,11 +446,23 @@ export function createApprovalStore(redis, signer, logger, options = {}) {
345
446
  return { approvalId, outcome: 'unknown' };
346
447
  },
347
448
  async withdraw(approvalId, { userId, conversationId }, reason) {
348
- const outcome = (await redis.eval(WITHDRAW, 4, stateKey(approvalId), recordKey(approvalId), seenKey(approvalId), withdrawnKey(approvalId), userId, conversationId, reason));
449
+ const outcome = (await redis.eval(WITHDRAW, 5, stateKey(approvalId), recordKey(approvalId), seenKey(approvalId), withdrawnKey(approvalId), grantKey(approvalId), userId, conversationId, reason, approvalId));
349
450
  if (outcome === 'withdrawn')
350
451
  logger.info({ approvalId, userId, conversationId, reason }, 'Approval withdrawn before it was used');
351
452
  return { approvalId, outcome: outcome === 'withdrawn' || outcome === 'settled' ? outcome : 'unknown' };
352
453
  },
454
+ async withdrawOpen(conversationId, reason) {
455
+ const ids = ((await redis.eval(OPEN_IN_CONVERSATION, 1, conversationKey(conversationId))) ?? []);
456
+ const withdrawn = [];
457
+ for (const approvalId of ids) {
458
+ const outcome = await redis.eval(WITHDRAW, 6, stateKey(approvalId), recordKey(approvalId), seenKey(approvalId), withdrawnKey(approvalId), grantKey(approvalId), conversationKey(conversationId), '', conversationId, reason, approvalId);
459
+ if (outcome === 'withdrawn')
460
+ withdrawn.push(approvalId);
461
+ }
462
+ if (withdrawn.length > 0)
463
+ logger.info({ conversationId, reason, approvalIds: withdrawn }, 'Approvals of the conversation withdrawn before they were used');
464
+ return withdrawn;
465
+ },
353
466
  async confirmExpirySettled(approvalId, { userId, conversationId }) {
354
467
  const outcome = await redis.eval(CONFIRM, 3, stateKey(approvalId), seenKey(approvalId), settledKey(approvalId), userId, conversationId, EXPIRED_APPROVAL_MEMORY_MS);
355
468
  if (outcome === 'confirmed')