@ouispec/contract 0.4.9 → 0.6.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/INTEGRATOR-GUIDE.md +239 -6
- package/dist/generated/contract.d.ts +406 -11
- package/dist/generated/contract.d.ts.map +1 -1
- package/dist/generated/schemas.d.ts +37 -0
- package/dist/generated/schemas.d.ts.map +1 -1
- package/dist/generated/schemas.js +1033 -6
- package/dist/generated/schemas.js.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/render-contract.d.ts.map +1 -1
- package/dist/render-contract.js +2 -0
- package/dist/render-contract.js.map +1 -1
- package/package.json +1 -1
- package/schemas/agent-evals.json +219 -0
- package/schemas/approvals.json +70 -5
- package/schemas/conversation-takeover.json +410 -0
- package/schemas/event-declarations.json +1 -1
package/INTEGRATOR-GUIDE.md
CHANGED
|
@@ -48,8 +48,10 @@ Every schema of the contract is versioned together by `MANIFEST_VERSION`, and th
|
|
|
48
48
|
| [`oui-manifest.json`](schemas/oui-manifest.json) | `OuiManifest` | `https://schemas.closurestudio.ai/oui/v1/oui-manifest.json` |
|
|
49
49
|
| [`generated-knowledge.json`](schemas/generated-knowledge.json) | `GeneratedKnowledge` | `https://schemas.closurestudio.ai/oui/v1/generated-knowledge.json` |
|
|
50
50
|
| [`oui-config.json`](schemas/oui-config.json) | `OuiConfigFile` | `https://schemas.closurestudio.ai/oui/v1/oui-config.json` |
|
|
51
|
-
| [`approvals.json`](schemas/approvals.json) | its
|
|
51
|
+
| [`approvals.json`](schemas/approvals.json) | its 25 `$defs`, one type each | `https://schemas.closurestudio.ai/oui/v1/approvals.json` |
|
|
52
52
|
| [`event-declarations.json`](schemas/event-declarations.json) | `EventDeclarationDocument` | `https://schemas.closurestudio.ai/agent-sdk/event-declarations/v1.json` |
|
|
53
|
+
| [`conversation-takeover.json`](schemas/conversation-takeover.json) | its 16 `$defs`, one type each | `https://schemas.closurestudio.ai/oui/v1/conversation-takeover.json` |
|
|
54
|
+
| [`agent-evals.json`](schemas/agent-evals.json) | `AgentEvalSuite` | `https://schemas.closurestudio.ai/oui/v1/agent-evals.json` |
|
|
53
55
|
|
|
54
56
|
Validate any of these files in a build step with `contractProblems(ref, value)` from `@ouispec/contract/validate`, where `ref` is a file name (`control-table.json`) or a generated type's name (`ControlDescriptor`). The generator already validates every control table, room catalog, `oui.config.json`, manifest and knowledge it reads or writes, and fails the build on any problem.
|
|
55
57
|
|
|
@@ -674,7 +676,7 @@ It joins the room the completion declares for one job (`report:{jobId}`), and se
|
|
|
674
676
|
> | `description` | string | yes | |
|
|
675
677
|
> | `payload` | EventPayloadSchema | yes | The payload's JSON Schema: an object. |
|
|
676
678
|
> | `typeName` | string | | The name generated code gives the payload type. |
|
|
677
|
-
> | `rooms` | string[] | yes | The rooms the event is published to: names from the document's `rooms
|
|
679
|
+
> | `rooms` | string[] | yes | 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). |
|
|
678
680
|
> | `correlation` | string[] | yes | The payload fields that say which job, or which resource, the event is about (e.g. |
|
|
679
681
|
> | `role` | EventRole | yes | |
|
|
680
682
|
> | `completes` | string | | For a completion or failure: the kind of job it settles. |
|
|
@@ -686,9 +688,9 @@ It joins the room the completion declares for one job (`report:{jobId}`), and se
|
|
|
686
688
|
A `transaction` — an order, a payment, a send, a publish — and any `write` declared `destructive` run only on an approval the person gave, bound to the exact call. No policy waives it.
|
|
687
689
|
|
|
688
690
|
1. The agent worker stops the turn at the call, stores it with its args hash, and the person's tab receives `agent:approval_required` with a preview whose every word comes from the action's declaration, never from the model. A host may write that display copy itself (the worker's `approvals.preview`): to redact a value, or to say it in the person's language, with `spokenReadback` for a voice. The stored call and the args hash it is bound to stay the model's.
|
|
689
|
-
2. The tab renders the approval card. In a UI only a click on the card counts: a "yes" typed in chat is a message. On voice, phone and
|
|
690
|
-
3. The click goes to the approval store on the person's own socket (`approval:decide`). The store answers the decider only, with a single-use token and the call's args hash, and the tab's OUI runtime receives a grant (`grantApproval`).
|
|
691
|
-
4. The next turn carries the token, outside the message text. The worker redeems it for the stored call, exactly, and runs it. A UI action then reaches the tab carrying `approval: { approvalId, argsHash }`, and the tab runs it only when that matches its grant.
|
|
691
|
+
2. The tab renders the approval card. In a UI only a click on the card counts: a "yes" typed in chat is a message. On voice, phone, SMS and chat, the verbatim readback (on a voice, its `spokenReadback` when the host wrote one) and an affirmative next turn. The turn says which: its payload's `channel` (`ui` by default; a live call's turns are `voice`, or `phone` when your `resolveTurn` says so), and the worker tells the model about approvals in that channel's terms. On a conversation channel the readback is sent as the turn's last words, its pieces marked `readback: true`, and stored as the agent's; your classifier of the next message decides as the user (`POST /internal/approvals/{id}/decide` with that channel). An action on the person's page is approved by its card, and on `voice`, `phone` and `chat` by its readback too: it is read back like any other call, and its card is on the person's screen as well. On SMS, which has no page beside it, it stays card-only: the model is told the card is on their screen, nothing is read back, and an SMS approve of it is refused (`channel`). A spoken or texted "no" always declines it.
|
|
692
|
+
3. The click goes to the approval store on the person's own socket (`approval:decide`). The store answers the decider only, with a single-use token and the call's args hash, and the tab's OUI runtime receives a grant (`grantApproval`). When a page's action is approved by its readback on `voice`, `phone` or `chat`, the engine gets the token and the store pushes a single-use grant (`agent:approval_granted`) to the room the worker stored with the call: the turn's own. A tab whose open conversation it is, and which is in that room, claims it on its own socket (`approval:claim`); only the first claim gets the grant, which lasts two minutes at most, and that tab's runtime takes it. A decline is pushed too (`agent:approval_declined`), and the card says how the person decided. Only the store sends these: the emit API and a client's relay refuse them.
|
|
693
|
+
4. The next turn carries the token, outside the message text. The worker redeems it for the stored call, exactly, and runs it. A UI action then reaches the tab carrying `approval: { approvalId, argsHash }`, and the tab runs it only when that matches its grant. A tab that was never given that approval refuses the request on its receipt and neither runs nor answers it, so with the conversation open in two tabs only the one holding the grant runs it; a replayed grant is refused.
|
|
692
694
|
|
|
693
695
|
Render the card with `ApprovalCard` from `@ouispec/agent-react`, drawn with your design system's parts:
|
|
694
696
|
|
|
@@ -718,6 +720,39 @@ The card takes no `agent` prop, and a package that ships its own card declares i
|
|
|
718
720
|
>
|
|
719
721
|
> One of: { ok: true, decision: "approve", approvalId: string, token: string, argsHash: ArgsHash, expiresAt: number, channel: ApprovalChannel } \| { ok: true, decision: "decline", approvalId: string } \| ApprovalRefusal.
|
|
720
722
|
|
|
723
|
+
> **Schema:** [`approvals.json#/$defs/ApprovalGrantedEvent`](schemas/approvals.json) · `https://schemas.closurestudio.ai/oui/v1/approvals.json#/$defs/ApprovalGrantedEvent` · TypeScript: `ApprovalGrantedEvent` from `@ouispec/contract`
|
|
724
|
+
>
|
|
725
|
+
> | Field | Type | Required | What it is |
|
|
726
|
+
> |---|---|---|---|
|
|
727
|
+
> | `approvalId` | string | yes | |
|
|
728
|
+
> | `grantId` | string | yes | This grant, single use: what a claim names. |
|
|
729
|
+
> | `argsHash` | ArgsHash | yes | The approved call's args hash: what the tab's OUI runtime checks the request's params against. |
|
|
730
|
+
> | `expiresAt` | number | yes | Epoch ms: two minutes after the decision (`APPROVAL_GRANT_TTL_MS`), or the approval's own expiry if sooner. |
|
|
731
|
+
> | `conversationId` | string | yes | |
|
|
732
|
+
> | `room` | string | yes | The room it was pushed to: that of the turn that asked. |
|
|
733
|
+
> | `channel` | ReadbackUIApprovalChannel | yes | Where the person approved it. |
|
|
734
|
+
> | `timestamp` | number | yes | |
|
|
735
|
+
|
|
736
|
+
> **Schema:** [`approvals.json#/$defs/ApprovalClaimPayload`](schemas/approvals.json) · `https://schemas.closurestudio.ai/oui/v1/approvals.json#/$defs/ApprovalClaimPayload` · TypeScript: `ApprovalClaimPayload` from `@ouispec/contract`
|
|
737
|
+
>
|
|
738
|
+
> | Field | Type | Required | What it is |
|
|
739
|
+
> |---|---|---|---|
|
|
740
|
+
> | `approvalId` | string | yes | |
|
|
741
|
+
> | `grantId` | string | yes | |
|
|
742
|
+
|
|
743
|
+
> **Schema:** [`approvals.json#/$defs/ApprovalClaimResult`](schemas/approvals.json) · `https://schemas.closurestudio.ai/oui/v1/approvals.json#/$defs/ApprovalClaimResult` · TypeScript: `ApprovalClaimResult` from `@ouispec/contract`
|
|
744
|
+
>
|
|
745
|
+
> One of: { ok: true, approvalId: string, argsHash: ArgsHash, expiresAt: number, channel: ReadbackUIApprovalChannel } \| ApprovalRefusal.
|
|
746
|
+
|
|
747
|
+
> **Schema:** [`approvals.json#/$defs/ApprovalDeclinedEvent`](schemas/approvals.json) · `https://schemas.closurestudio.ai/oui/v1/approvals.json#/$defs/ApprovalDeclinedEvent` · TypeScript: `ApprovalDeclinedEvent` from `@ouispec/contract`
|
|
748
|
+
>
|
|
749
|
+
> | Field | Type | Required | What it is |
|
|
750
|
+
> |---|---|---|---|
|
|
751
|
+
> | `approvalId` | string | yes | |
|
|
752
|
+
> | `conversationId` | string | yes | |
|
|
753
|
+
> | `channel` | "voice" \| "phone" \| "sms" \| "chat" | yes | Where the person declined it: a conversation channel. |
|
|
754
|
+
> | `timestamp` | number | yes | |
|
|
755
|
+
|
|
721
756
|
> **Schema:** [`approvals.json#/$defs/ApprovalContinuation`](schemas/approvals.json) · `https://schemas.closurestudio.ai/oui/v1/approvals.json#/$defs/ApprovalContinuation` · TypeScript: `ApprovalContinuation` from `@ouispec/contract`
|
|
722
757
|
>
|
|
723
758
|
> One of: { approvalId: string, decision: "approve", token: string } \| { approvalId: string, decision: "decline" }.
|
|
@@ -861,4 +896,202 @@ A compound control's wrapper is its namespace (`Select`), and its example render
|
|
|
861
896
|
|
|
862
897
|
## Conversations
|
|
863
898
|
|
|
864
|
-
The agent client never makes HTTP requests; the product supplies callbacks. Beyond `createConversation` and `sendMessage` (which passes an approval continuation through unchanged, as `approval`, and, for a message the person spoke, how it was entered as `context.input`: `{ mode: 'voice', language }`, which the product passes to the worker on the turn's context and stores with the message, so `getConversation` returns it as the message's `input`), two optional callbacks let a person return to earlier conversations: `listConversations({ limit, offset, … })` and `getConversation(id)`. Each conversation `listConversations` returns may say how the message its `preview` is taken from was entered, as `previewInput`, and each search match how its message was, as `input`, both `{ mode: 'voice', language }` for a spoken message, so a list can mark a conversation that began by voice; the client keeps only what it recognises. With `getConversation`, the client also restores the tab's active conversation after a reload. Both must return only the signed-in person's conversations.
|
|
899
|
+
The agent client never makes HTTP requests; the product supplies callbacks. Beyond `createConversation` and `sendMessage` (which passes an approval continuation through unchanged, as `approval`, and, for a message the person spoke, how it was entered as `context.input`: `{ mode: 'voice', language }`, which the product passes to the worker on the turn's context and stores with the message, so `getConversation` returns it as the message's `input`), two optional callbacks let a person return to earlier conversations: `listConversations({ limit, offset, … })` and `getConversation(id)`. Each conversation `listConversations` returns may say how the message its `preview` is taken from was entered, as `previewInput`, and each search match how its message was, as `input`, both `{ mode: 'voice', language }` for a spoken message, so a list can mark a conversation that began by voice; the client keeps only what it recognises. With `getConversation`, the client also restores the tab's active conversation after a reload. Both must return only the signed-in person's conversations. A conversation a person on the staff has taken over also returns its `role: 'staff'` messages and take-over entries, each with its `speaker`, and the current `hold` (see [Staff take over a conversation, and hand it back](#staff-take-over-a-conversation-and-hand-it-back)).
|
|
900
|
+
|
|
901
|
+
## Staff take over a conversation, and hand it back
|
|
902
|
+
|
|
903
|
+
A person on the product's staff can take a live conversation from the agent, answer the customer as themselves in the same conversation, and hand it back. While a person **holds** the conversation the agent does not answer: a turn that is running stops at a safe point and keeps what it had produced, marked `taken_over`; a turn that arrives is not run by the model and stores nothing. On hand-back the agent's next turn reads the whole exchange, the person's messages under their name, in its history.
|
|
904
|
+
|
|
905
|
+
**Who may take over is yours to decide.** The realtime server keeps the hold and enforces it, and never decides staff permissions: its routes take the internal key, and your API calls them after its own check that this person may take this conversation, as it does before it asks for a room token.
|
|
906
|
+
|
|
907
|
+
| Your API's route does | Then calls (internal key) |
|
|
908
|
+
|---|---|
|
|
909
|
+
| Take over: check the staff member may; store a take-over entry | `POST /internal/conversations/{id}/hold` with `TakeOverRequest`. The server stops the conversation's running turn and withdraws every approval of it still waiting, or approved and not yet used (`taken_over`): the person now answering asked for none of them. Its answer lists them as `withdrawn`; a later turn records each as withdrawn, and none of them runs or gets a receipt |
|
|
910
|
+
| Send as staff: store the message with `role: 'staff'` and its speaker | `POST /internal/conversations/{id}/messages` with `AnnounceMessageRequest` (refused unless the speaker holds it) |
|
|
911
|
+
| Hand back: store a hand-back entry | `POST /internal/conversations/{id}/hold/release` with `HandBackRequest`: with `userId`, only the holder may; without it, you release it on your own authority (an idle policy, a manager) |
|
|
912
|
+
| Every customer and agent message you store | `POST /internal/conversations/{id}/messages`, so the staff watching see it |
|
|
913
|
+
|
|
914
|
+
`GET /internal/conversations/{id}/hold` answers who holds it (204: nobody). `createHttpConversationClient({ url, apiKey })` from `@ouispec/agent-worker` calls all of them. The three events they send, `agent:conversation_taken_over`, `agent:conversation_handed_back` and `agent:conversation_message`, are the server's own: `/api/emit` refuses them, so no event says a conversation changed hands when it did not.
|
|
915
|
+
|
|
916
|
+
**The conversation's room.** The events go to the rooms you name in each request: the conversation's own room (name it as you like, `support:conversation:{id}`, and have your `RoomPolicy` require a token for it), and any of your own (a team's board). The event catalog reserves the room name `conversation` for it, as it reserves `turn`; your declaration document may not declare a room by that name. Mint the conversation room's token for the customer whose conversation it is, and for each staff member who may watch it.
|
|
917
|
+
|
|
918
|
+
**What you store, and hand back.** A staff message is a stored message with `role: 'staff'`, its `content` and its `speaker` (`StaffSpeaker`). The take-over and the hand-back are stored too, as `role: 'staff'` entries with no content and `takeover: 'taken_over' | 'handed_back'`. `getHistory` returns each as `{ role: 'staff', content, speaker, takeover? }`; `getConversation` returns them on `messages`, and the conversation's current `hold`. The worker gives them to the model as the business's side of the conversation, under the person's name, so the agent knows what they told the customer and never takes their words for its own. A customer cannot forge one: the customer's text only ever reaches the model as the customer's.
|
|
919
|
+
|
|
920
|
+
**In the customer's tab.** Give `AgentClientConfig` a `conversationRoom(conversationId)` that returns `{ room, roomToken }`. The provider joins the room for the open conversation; `useAgent().hold` says who holds it; a person's messages arrive as messages with `role: 'staff'` and their `speaker`; the take-over and hand-back as `role: 'staff'` messages with `takeover`. The customer keeps typing: their messages reach your API as always, and `isProcessing` stays false while the conversation is held.
|
|
921
|
+
|
|
922
|
+
**In the staff console.** Give `AgentClientConfig` a `staff` seam (`getConversation`, `takeOver`, `handBack`, `sendMessage`: your routes above) and `conversationRoom`, and use `useStaffConversation(conversationId)` inside the provider: it loads the conversation, follows it live, and takes over, sends and hands back.
|
|
923
|
+
|
|
924
|
+
**An anonymous customer.** Nothing requires a signed-in user. Issue a website visitor a session token when your widget loads (after your origin check and rate limit), with a visitor id as `userId`; have your `AuthAdapter` verify it, and mint the visitor's conversation-room and turn-room tokens only for its own conversation. Its turns, stops and approvals are then the visitor's.
|
|
925
|
+
|
|
926
|
+
**On a live call.** The live-call handler answers a turn of a held conversation with `done { stopReason: 'taken_over' }` and no words, and makes no model call; a turn speaking when the conversation is taken over stops there with the same end, and an opening is not greeted, your template included. The call service keeps its own state: quiet the character there too, so it stops at once rather than when its next turn is refused. Take the conversation's hold first (every channel stops answering), then the call's; to hand back, resume the call, then release the conversation's hold, so the agent answers the caller's next words. What the person says in the call reaches you as the call service's transcript: store each of their turns as a `staff` message with their `speaker`, so after the hand-back the agent answers from the whole exchange.
|
|
927
|
+
|
|
928
|
+
**What stays yours:** who is on duty, the alert to staff and how long they have to answer it, the mobile take-over screen, warm transfer on a phone call, and when an idle conversation goes back to the agent. Each has its seam above: your route before the hold, the events in your own rooms, `release` without a `userId`.
|
|
929
|
+
|
|
930
|
+
> **Schema:** [`conversation-takeover.json#/$defs/StaffSpeaker`](schemas/conversation-takeover.json) · `https://schemas.closurestudio.ai/oui/v1/conversation-takeover.json#/$defs/StaffSpeaker` · TypeScript: `StaffSpeaker` from `@ouispec/contract`
|
|
931
|
+
>
|
|
932
|
+
> | Field | Type | Required | What it is |
|
|
933
|
+
> |---|---|---|---|
|
|
934
|
+
> | `userId` | string | yes | The staff member's id, as the product's realtime identity names them. |
|
|
935
|
+
> | `displayName` | string | yes | The name the customer sees ("Jordan"). |
|
|
936
|
+
> | `role` | string | | What the customer sees beside the name ("Toyota of Quillhaven sales"). |
|
|
937
|
+
|
|
938
|
+
> **Schema:** [`conversation-takeover.json#/$defs/ConversationHold`](schemas/conversation-takeover.json) · `https://schemas.closurestudio.ai/oui/v1/conversation-takeover.json#/$defs/ConversationHold` · TypeScript: `ConversationHold` from `@ouispec/contract`
|
|
939
|
+
>
|
|
940
|
+
> | Field | Type | Required | What it is |
|
|
941
|
+
> |---|---|---|---|
|
|
942
|
+
> | `conversationId` | string | yes | |
|
|
943
|
+
> | `holder` | StaffSpeaker | yes | |
|
|
944
|
+
> | `since` | number | yes | When it was taken, epoch ms by the realtime server's clock. |
|
|
945
|
+
|
|
946
|
+
> **Schema:** [`conversation-takeover.json#/$defs/TakeOverRequest`](schemas/conversation-takeover.json) · `https://schemas.closurestudio.ai/oui/v1/conversation-takeover.json#/$defs/TakeOverRequest` · TypeScript: `TakeOverRequest` from `@ouispec/contract`
|
|
947
|
+
>
|
|
948
|
+
> | Field | Type | Required | What it is |
|
|
949
|
+
> |---|---|---|---|
|
|
950
|
+
> | `holder` | StaffSpeaker | yes | |
|
|
951
|
+
> | `rooms` | ConversationRooms | yes | |
|
|
952
|
+
|
|
953
|
+
> **Schema:** [`conversation-takeover.json#/$defs/TakeOverResult`](schemas/conversation-takeover.json) · `https://schemas.closurestudio.ai/oui/v1/conversation-takeover.json#/$defs/TakeOverResult` · TypeScript: `TakeOverResult` from `@ouispec/contract`
|
|
954
|
+
>
|
|
955
|
+
> One of: { ok: true, change: "taken_over" \| "already", hold: ConversationHold, withdrawn?: string[] } \| { ok: false, reason: "held", hold: ConversationHold }.
|
|
956
|
+
|
|
957
|
+
> **Schema:** [`conversation-takeover.json#/$defs/HandBackRequest`](schemas/conversation-takeover.json) · `https://schemas.closurestudio.ai/oui/v1/conversation-takeover.json#/$defs/HandBackRequest` · TypeScript: `HandBackRequest` from `@ouispec/contract`
|
|
958
|
+
>
|
|
959
|
+
> | Field | Type | Required | What it is |
|
|
960
|
+
> |---|---|---|---|
|
|
961
|
+
> | `userId` | string | | The staff member handing it back; must be the holder. |
|
|
962
|
+
> | `rooms` | ConversationRooms | yes | |
|
|
963
|
+
|
|
964
|
+
> **Schema:** [`conversation-takeover.json#/$defs/AnnounceMessageRequest`](schemas/conversation-takeover.json) · `https://schemas.closurestudio.ai/oui/v1/conversation-takeover.json#/$defs/AnnounceMessageRequest` · TypeScript: `AnnounceMessageRequest` from `@ouispec/contract`
|
|
965
|
+
>
|
|
966
|
+
> | Field | Type | Required | What it is |
|
|
967
|
+
> |---|---|---|---|
|
|
968
|
+
> | `message` | ConversationMessage | yes | |
|
|
969
|
+
> | `rooms` | ConversationRooms | yes | |
|
|
970
|
+
|
|
971
|
+
> **Schema:** [`conversation-takeover.json#/$defs/ConversationMessage`](schemas/conversation-takeover.json) · `https://schemas.closurestudio.ai/oui/v1/conversation-takeover.json#/$defs/ConversationMessage` · TypeScript: `ConversationMessage` from `@ouispec/contract`
|
|
972
|
+
>
|
|
973
|
+
> | Field | Type | Required | What it is |
|
|
974
|
+
> |---|---|---|---|
|
|
975
|
+
> | `id` | string | yes | The product's id for the stored message. |
|
|
976
|
+
> | `role` | ConversationMessageRole | yes | |
|
|
977
|
+
> | `content` | string | yes | |
|
|
978
|
+
> | `createdAt` | string | yes | When it was stored, ISO 8601. |
|
|
979
|
+
> | `speaker` | StaffSpeaker | | Set on a `staff` message: who wrote it. |
|
|
980
|
+
|
|
981
|
+
> **Schema:** [`conversation-takeover.json#/$defs/ConversationTakenOverEvent`](schemas/conversation-takeover.json) · `https://schemas.closurestudio.ai/oui/v1/conversation-takeover.json#/$defs/ConversationTakenOverEvent` · TypeScript: `ConversationTakenOverEvent` from `@ouispec/contract`
|
|
982
|
+
>
|
|
983
|
+
> | Field | Type | Required | What it is |
|
|
984
|
+
> |---|---|---|---|
|
|
985
|
+
> | `conversationId` | string | yes | |
|
|
986
|
+
> | `hold` | ConversationHold | yes | |
|
|
987
|
+
> | `at` | number | yes | Epoch ms. |
|
|
988
|
+
|
|
989
|
+
> **Schema:** [`conversation-takeover.json#/$defs/ConversationHandedBackEvent`](schemas/conversation-takeover.json) · `https://schemas.closurestudio.ai/oui/v1/conversation-takeover.json#/$defs/ConversationHandedBackEvent` · TypeScript: `ConversationHandedBackEvent` from `@ouispec/contract`
|
|
990
|
+
>
|
|
991
|
+
> | Field | Type | Required | What it is |
|
|
992
|
+
> |---|---|---|---|
|
|
993
|
+
> | `conversationId` | string | yes | |
|
|
994
|
+
> | `hold` | ConversationHold | yes | The hold that ended. |
|
|
995
|
+
> | `by` | HandBackCause | yes | |
|
|
996
|
+
> | `at` | number | yes | Epoch ms. |
|
|
997
|
+
|
|
998
|
+
## Evals: one scenario set, every channel, in CI
|
|
999
|
+
|
|
1000
|
+
`@ouispec/agent-evals` runs scenarios you write as data against your **real** agent configuration (its persona or system prompt, its tools, its `ToolPolicy` and `TurnPolicy`, and its hooks: `beforeTurn`, `filterEvent`, and its approval preview and check) through the SDK's own turn runner, on every channel you serve, and fails your CI when an assertion does not hold. In CI it replays recorded model responses: no credentials, no network, the same answer every run.
|
|
1001
|
+
|
|
1002
|
+
**A suite** is a JSON or YAML file (`AgentEvalSuite`). A scenario's turns are the customer's messages (`user`), the customer's answer to a waiting approval (`approval: approve | decline`), and a person on the staff taking over, writing and handing back (`staff`). After a turn, `expect` says what must hold, and `expectOn.<channel>` what must also hold on one channel:
|
|
1003
|
+
|
|
1004
|
+
| Assertion | Holds when |
|
|
1005
|
+
|---|---|
|
|
1006
|
+
| `says`, `mustNotSay` | each matcher matches the reply; none does. A string is found ignoring case; `{ pattern, flags }` is a regular expression; `{ rubric }` is decided by a judge model |
|
|
1007
|
+
| `toolCalled` | the agent called each tool, its arguments holding the given ones as a subset |
|
|
1008
|
+
| `toolNotCalled` | it called none of them (`*`: no tool at all) |
|
|
1009
|
+
| `approvalRequested` | the turn stopped for the customer's approval of that call, with a readback that is present and matches (`false`: it stopped for none) |
|
|
1010
|
+
| `refusal` | the reply declines (`true`: the usual phrasing; or a matcher) |
|
|
1011
|
+
| `doesNotStore` | the matchers appear nowhere the turn stored: its text, its tool arguments, its tool results |
|
|
1012
|
+
| `held` | the turn ran no model call, because a person held the conversation |
|
|
1013
|
+
|
|
1014
|
+
```yaml
|
|
1015
|
+
version: 1
|
|
1016
|
+
name: dealer
|
|
1017
|
+
stubs:
|
|
1018
|
+
inventory_search:
|
|
1019
|
+
- when: { stock: T2417 }
|
|
1020
|
+
result: { success: true, data: { stock: T2417, price: 31995, status: available } }
|
|
1021
|
+
scenarios:
|
|
1022
|
+
- id: price-only
|
|
1023
|
+
title: Quotes the dealer price and no payments
|
|
1024
|
+
turns:
|
|
1025
|
+
- user: Is T2417 still available, and what's the price?
|
|
1026
|
+
expect:
|
|
1027
|
+
toolCalled: [{ name: inventory_search, args: { stock: T2417 } }]
|
|
1028
|
+
says: ["31,995"]
|
|
1029
|
+
mustNotSay: [{ pattern: "per month|/mo|APR", flags: i }]
|
|
1030
|
+
```
|
|
1031
|
+
|
|
1032
|
+
**Every tool is stubbed.** A stub is data in the suite or the scenario (`when`, a subset of the call's arguments; `result`), first match wins, the scenario's first; or a function in the configuration. A call to a tool with no stub fails the scenario: an eval never reaches your backend.
|
|
1033
|
+
|
|
1034
|
+
**Channels.** Your configuration names them, and what each changes: `approvals` (the card, `ui`, or a conversation channel, `chat`, `sms`, `voice`, `phone`, where the readback is sent and the next message confirms it), `input` (what each customer message carries as `context.input`, so a voice channel marks it spoken), and `context`. The turn carries its channel, and the worker tells the model about approvals in that channel's terms. Every scenario runs on every channel of its suite unless it names fewer, so a change that breaks SMS and not web chat fails.
|
|
1035
|
+
|
|
1036
|
+
```ts
|
|
1037
|
+
// agent-evals.config.mjs
|
|
1038
|
+
import { createAmazonBedrock } from '@ai-sdk/amazon-bedrock';
|
|
1039
|
+
import { defineEvals } from '@ouispec/agent-evals';
|
|
1040
|
+
import { dealerAgent } from './src/dealer-agent.js'; // the parts your worker runs with
|
|
1041
|
+
|
|
1042
|
+
export default defineEvals({
|
|
1043
|
+
root: new URL('.', import.meta.url),
|
|
1044
|
+
suites: ['evals/dealer.evals.yaml'],
|
|
1045
|
+
cassettes: 'evals/cassettes',
|
|
1046
|
+
channels: {
|
|
1047
|
+
web_chat: { approvals: 'ui' },
|
|
1048
|
+
sms: { approvals: 'sms' },
|
|
1049
|
+
voice: { approvals: 'voice', input: { mode: 'voice', language: 'en' } },
|
|
1050
|
+
},
|
|
1051
|
+
model: ({ fetch, mode }) =>
|
|
1052
|
+
createAmazonBedrock({
|
|
1053
|
+
region: 'us-east-1',
|
|
1054
|
+
fetch,
|
|
1055
|
+
...(mode === 'replay' ? { credentialProvider: async () => ({ accessKeyId: 'replay', secretAccessKey: 'replay' }) } : {}),
|
|
1056
|
+
})('us.anthropic.claude-sonnet-4-6'),
|
|
1057
|
+
agent: ({ channel }) => dealerAgent({ channel }), // persona, tools, toolPolicy, turnPolicy, beforeTurn, filterEvent, approvals
|
|
1058
|
+
});
|
|
1059
|
+
```
|
|
1060
|
+
|
|
1061
|
+
**Run it.** `agent-evals` (in CI: replays the recordings), `agent-evals --record` (runs the live model and writes them), `agent-evals --live` (runs it and writes nothing). `--channel` and `--scenario` narrow a run; `--json` and `--junit` write reports. It exits 1 when any case fails, listing each failed assertion with its turn, channel and the reply. In a test runner, `evalCases(config)` gives one case per scenario and channel, each throwing with every failure.
|
|
1062
|
+
|
|
1063
|
+
**A recording knows what it was recorded against**: your system prompt, your tools' names, descriptions and schemas, the scenario's turns and the channel. Change any of them and its replay fails until you record it again, rather than passing on answers to a question no longer asked.
|
|
1064
|
+
|
|
1065
|
+
The package ships an example: a fake dealer tool set, with scenarios for disclosure, price and no payments, an injected instruction, an SSN refused and not stored, a request for a person, a booking that runs only after its readback is confirmed, and a take-over and hand-back, on web chat, SMS and voice.
|
|
1066
|
+
|
|
1067
|
+
> **Schema:** [`agent-evals.json`](schemas/agent-evals.json) · `https://schemas.closurestudio.ai/oui/v1/agent-evals.json` · TypeScript: `AgentEvalSuite` from `@ouispec/contract`
|
|
1068
|
+
>
|
|
1069
|
+
> | Field | Type | Required | What it is |
|
|
1070
|
+
> |---|---|---|---|
|
|
1071
|
+
> | `version` | 1 | yes | The suite format's version. |
|
|
1072
|
+
> | `name` | string | yes | The suite's name, as reports show it. |
|
|
1073
|
+
> | `description` | string | | |
|
|
1074
|
+
> | `channels` | AgentEvalChannelList | | The channels every scenario runs on, as the eval configuration names them (`web_chat`, `sms`, `voice`). |
|
|
1075
|
+
> | `context` | object | | What every turn of every scenario carries as its context, before the channel's and the scenario's own. |
|
|
1076
|
+
> | `stubs` | AgentEvalStubs | | What each tool returns, for every scenario; a scenario's own stubs come first. |
|
|
1077
|
+
> | `scenarios` | AgentEvalScenario[] | yes | |
|
|
1078
|
+
|
|
1079
|
+
> **Schema:** [`agent-evals.json#/$defs/AgentEvalExpectation`](schemas/agent-evals.json) · `https://schemas.closurestudio.ai/oui/v1/agent-evals.json#/$defs/AgentEvalExpectation` · TypeScript: `AgentEvalExpectation` from `@ouispec/contract`
|
|
1080
|
+
>
|
|
1081
|
+
> | Field | Type | Required | What it is |
|
|
1082
|
+
> |---|---|---|---|
|
|
1083
|
+
> | `says` | AgentEvalTextMatcher[] | | Each must match the reply. |
|
|
1084
|
+
> | `mustNotSay` | AgentEvalTextMatcher[] | | None may match the reply. |
|
|
1085
|
+
> | `toolCalled` | AgentEvalToolCall[] | | Each was called, with these arguments. |
|
|
1086
|
+
> | `toolNotCalled` | string[] | | None of these was called; `*` means no tool at all. |
|
|
1087
|
+
> | `approvalRequested` | false \| AgentEvalApprovalExpectation | | The turn stopped for the customer's approval of this call; `false`: it did not stop for any. |
|
|
1088
|
+
> | `refusal` | true \| AgentEvalTextMatcher | | The reply declines: `true` for the usual phrasing of a refusal (can't, cannot, unable, not able, won't, not allowed), or a matcher for the agent's own words. |
|
|
1089
|
+
> | `doesNotStore` | AgentEvalTextMatcher[] | | None of these appears in anything the turn stored: its text, its tool calls' arguments, its tool results. |
|
|
1090
|
+
> | `held` | boolean | | `true`: the turn ran no model call, because a person held the conversation. |
|
|
1091
|
+
|
|
1092
|
+
> **Schema:** [`agent-evals.json#/$defs/AgentEvalStubCase`](schemas/agent-evals.json) · `https://schemas.closurestudio.ai/oui/v1/agent-evals.json#/$defs/AgentEvalStubCase` · TypeScript: `AgentEvalStubCase` from `@ouispec/contract`
|
|
1093
|
+
>
|
|
1094
|
+
> | Field | Type | Required | What it is |
|
|
1095
|
+
> |---|---|---|---|
|
|
1096
|
+
> | `when` | object | | |
|
|
1097
|
+
> | `result` | { success: boolean, data?: any, error?: string } | yes | |
|