@ouispec/contract 0.4.8 → 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.
@@ -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 19 `$defs`, one type each | `https://schemas.closurestudio.ai/oui/v1/approvals.json` |
51
+ | [`approvals.json`](schemas/approvals.json) | its 20 `$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`, or `turn` for the room of the agent turn it belongs to (the host names that room in each turn). |
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,7 +688,7 @@ 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 SMS, the verbatim readback (on a voice, its `spokenReadback` when the host wrote one) and an affirmative next turn.
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 the exception on every channel: its page runs it only on its own grant, from a click on its card, so the model is told the card is on their screen, nothing is read back, and a conversation channel's approve of it is refused (`channel`). A spoken "no" still declines it.
690
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`).
691
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.
692
694
 
@@ -696,6 +698,8 @@ Render the card with `ApprovalCard` from `@ouispec/agent-react`, drawn with your
696
698
  <ApprovalCard components={{ Card: MyCard, Button: MyButton }} labels={{ approve: 'Place order' }} />
697
699
  ```
698
700
 
701
+ 5. When the realtime server holds receipt keys, redemption also returns a signed **receipt**, and a host or API tool's approved call carries it to the tool's own API: a generated API tool as the `OUI-Approval-Receipt` header, a host tool on `ctx.approval.receipt`. The API verifies it offline with `verifyApprovalReceipt` from `@ouispec/agent-core` (or any JOSE library) against the server's keys at `/.well-known/oui-approval-jwks.json`, and acts on each receipt's `jti` once. The receipt names the one API it is for, fixed when the approval was stored, and lasts 120 seconds. A UI action gets none.
702
+
699
703
  The card takes no `agent` prop, and a package that ships its own card declares it under `oui.personOnly` (`{ "ApprovalCard": "the person's own approval" }`), so the generator refuses to bind it: the assistant can never operate its own approval. The args hash is SHA-256 over the RFC 8785 canonical JSON of the arguments, lowercase hex; `oui-spec/approval-vectors.json` holds every implementation to it, in any language.
700
704
 
701
705
  > **Schema:** [`approvals.json#/$defs/ApprovalRequiredEvent`](schemas/approvals.json) · `https://schemas.closurestudio.ai/oui/v1/approvals.json#/$defs/ApprovalRequiredEvent` · TypeScript: `ApprovalRequiredEvent` from `@ouispec/contract`
@@ -742,6 +746,24 @@ The card takes no `agent` prop, and a package that ships its own card declares i
742
746
  > | `exp` | integer | yes | Expires at, epoch seconds. |
743
747
  > | `jti` | string | yes | A nonce. |
744
748
 
749
+ > **Schema:** [`approvals.json#/$defs/ApprovalReceiptClaims`](schemas/approvals.json) · `https://schemas.closurestudio.ai/oui/v1/approvals.json#/$defs/ApprovalReceiptClaims` · TypeScript: `ApprovalReceiptClaims` from `@ouispec/contract`
750
+ >
751
+ > | Field | Type | Required | What it is |
752
+ > |---|---|---|---|
753
+ > | `iss` | string | yes | The realtime server's public base URL. |
754
+ > | `aud` | string | yes | The one API the receipt is for: an origin, fixed when the approval was created. |
755
+ > | `approvalId` | string | yes | The approval id, which is the tool call id. |
756
+ > | `argsHash` | ArgsHash | yes | The approved call's args hash. |
757
+ > | `tool` | string | yes | The tool's name, as the worker offered it. |
758
+ > | `operationId` | string | | For a generated API tool, its OpenAPI `operationId`. |
759
+ > | `conversationId` | string | yes | |
760
+ > | `userId` | string | yes | The user who approved it. |
761
+ > | `accountId` | string | | The user's account, when the product has one. |
762
+ > | `channel` | ApprovalChannel | yes | How it was approved. |
763
+ > | `iat` | integer | yes | Issued at, epoch seconds. |
764
+ > | `exp` | integer | yes | Expires at, epoch seconds: `iat` + 120. |
765
+ > | `jti` | string | yes | Unique to this receipt: the call's idempotency key. |
766
+
745
767
  ## The conformance kit
746
768
 
747
769
  `@ouispec/testing` runs in your own test runner, in any DOM environment (jsdom, happy-dom, a browser), and reports against these schemas. Each check returns a report; `assertConformant(report)` throws with every violation listed, under its rule.
@@ -841,4 +863,202 @@ A compound control's wrapper is its namespace (`Select`), and its example render
841
863
 
842
864
  ## Conversations
843
865
 
844
- 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.
866
+ 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)).
867
+
868
+ ## Staff take over a conversation, and hand it back
869
+
870
+ 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.
871
+
872
+ **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.
873
+
874
+ | Your API's route does | Then calls (internal key) |
875
+ |---|---|
876
+ | 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 |
877
+ | 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) |
878
+ | 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) |
879
+ | Every customer and agent message you store | `POST /internal/conversations/{id}/messages`, so the staff watching see it |
880
+
881
+ `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.
882
+
883
+ **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.
884
+
885
+ **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.
886
+
887
+ **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.
888
+
889
+ **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.
890
+
891
+ **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.
892
+
893
+ **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.
894
+
895
+ **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`.
896
+
897
+ > **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`
898
+ >
899
+ > | Field | Type | Required | What it is |
900
+ > |---|---|---|---|
901
+ > | `userId` | string | yes | The staff member's id, as the product's realtime identity names them. |
902
+ > | `displayName` | string | yes | The name the customer sees ("Jordan"). |
903
+ > | `role` | string | | What the customer sees beside the name ("Toyota of Quillhaven sales"). |
904
+
905
+ > **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`
906
+ >
907
+ > | Field | Type | Required | What it is |
908
+ > |---|---|---|---|
909
+ > | `conversationId` | string | yes | |
910
+ > | `holder` | StaffSpeaker | yes | |
911
+ > | `since` | number | yes | When it was taken, epoch ms by the realtime server's clock. |
912
+
913
+ > **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`
914
+ >
915
+ > | Field | Type | Required | What it is |
916
+ > |---|---|---|---|
917
+ > | `holder` | StaffSpeaker | yes | |
918
+ > | `rooms` | ConversationRooms | yes | |
919
+
920
+ > **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`
921
+ >
922
+ > One of: { ok: true, change: "taken_over" \| "already", hold: ConversationHold, withdrawn?: string[] } \| { ok: false, reason: "held", hold: ConversationHold }.
923
+
924
+ > **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`
925
+ >
926
+ > | Field | Type | Required | What it is |
927
+ > |---|---|---|---|
928
+ > | `userId` | string | | The staff member handing it back; must be the holder. |
929
+ > | `rooms` | ConversationRooms | yes | |
930
+
931
+ > **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`
932
+ >
933
+ > | Field | Type | Required | What it is |
934
+ > |---|---|---|---|
935
+ > | `message` | ConversationMessage | yes | |
936
+ > | `rooms` | ConversationRooms | yes | |
937
+
938
+ > **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`
939
+ >
940
+ > | Field | Type | Required | What it is |
941
+ > |---|---|---|---|
942
+ > | `id` | string | yes | The product's id for the stored message. |
943
+ > | `role` | ConversationMessageRole | yes | |
944
+ > | `content` | string | yes | |
945
+ > | `createdAt` | string | yes | When it was stored, ISO 8601. |
946
+ > | `speaker` | StaffSpeaker | | Set on a `staff` message: who wrote it. |
947
+
948
+ > **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`
949
+ >
950
+ > | Field | Type | Required | What it is |
951
+ > |---|---|---|---|
952
+ > | `conversationId` | string | yes | |
953
+ > | `hold` | ConversationHold | yes | |
954
+ > | `at` | number | yes | Epoch ms. |
955
+
956
+ > **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`
957
+ >
958
+ > | Field | Type | Required | What it is |
959
+ > |---|---|---|---|
960
+ > | `conversationId` | string | yes | |
961
+ > | `hold` | ConversationHold | yes | The hold that ended. |
962
+ > | `by` | HandBackCause | yes | |
963
+ > | `at` | number | yes | Epoch ms. |
964
+
965
+ ## Evals: one scenario set, every channel, in CI
966
+
967
+ `@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.
968
+
969
+ **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:
970
+
971
+ | Assertion | Holds when |
972
+ |---|---|
973
+ | `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 |
974
+ | `toolCalled` | the agent called each tool, its arguments holding the given ones as a subset |
975
+ | `toolNotCalled` | it called none of them (`*`: no tool at all) |
976
+ | `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) |
977
+ | `refusal` | the reply declines (`true`: the usual phrasing; or a matcher) |
978
+ | `doesNotStore` | the matchers appear nowhere the turn stored: its text, its tool arguments, its tool results |
979
+ | `held` | the turn ran no model call, because a person held the conversation |
980
+
981
+ ```yaml
982
+ version: 1
983
+ name: dealer
984
+ stubs:
985
+ inventory_search:
986
+ - when: { stock: T2417 }
987
+ result: { success: true, data: { stock: T2417, price: 31995, status: available } }
988
+ scenarios:
989
+ - id: price-only
990
+ title: Quotes the dealer price and no payments
991
+ turns:
992
+ - user: Is T2417 still available, and what's the price?
993
+ expect:
994
+ toolCalled: [{ name: inventory_search, args: { stock: T2417 } }]
995
+ says: ["31,995"]
996
+ mustNotSay: [{ pattern: "per month|/mo|APR", flags: i }]
997
+ ```
998
+
999
+ **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.
1000
+
1001
+ **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.
1002
+
1003
+ ```ts
1004
+ // agent-evals.config.mjs
1005
+ import { createAmazonBedrock } from '@ai-sdk/amazon-bedrock';
1006
+ import { defineEvals } from '@ouispec/agent-evals';
1007
+ import { dealerAgent } from './src/dealer-agent.js'; // the parts your worker runs with
1008
+
1009
+ export default defineEvals({
1010
+ root: new URL('.', import.meta.url),
1011
+ suites: ['evals/dealer.evals.yaml'],
1012
+ cassettes: 'evals/cassettes',
1013
+ channels: {
1014
+ web_chat: { approvals: 'ui' },
1015
+ sms: { approvals: 'sms' },
1016
+ voice: { approvals: 'voice', input: { mode: 'voice', language: 'en' } },
1017
+ },
1018
+ model: ({ fetch, mode }) =>
1019
+ createAmazonBedrock({
1020
+ region: 'us-east-1',
1021
+ fetch,
1022
+ ...(mode === 'replay' ? { credentialProvider: async () => ({ accessKeyId: 'replay', secretAccessKey: 'replay' }) } : {}),
1023
+ })('us.anthropic.claude-sonnet-4-6'),
1024
+ agent: ({ channel }) => dealerAgent({ channel }), // persona, tools, toolPolicy, turnPolicy, beforeTurn, filterEvent, approvals
1025
+ });
1026
+ ```
1027
+
1028
+ **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.
1029
+
1030
+ **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.
1031
+
1032
+ 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.
1033
+
1034
+ > **Schema:** [`agent-evals.json`](schemas/agent-evals.json) · `https://schemas.closurestudio.ai/oui/v1/agent-evals.json` · TypeScript: `AgentEvalSuite` from `@ouispec/contract`
1035
+ >
1036
+ > | Field | Type | Required | What it is |
1037
+ > |---|---|---|---|
1038
+ > | `version` | 1 | yes | The suite format's version. |
1039
+ > | `name` | string | yes | The suite's name, as reports show it. |
1040
+ > | `description` | string | | |
1041
+ > | `channels` | AgentEvalChannelList | | The channels every scenario runs on, as the eval configuration names them (`web_chat`, `sms`, `voice`). |
1042
+ > | `context` | object | | What every turn of every scenario carries as its context, before the channel's and the scenario's own. |
1043
+ > | `stubs` | AgentEvalStubs | | What each tool returns, for every scenario; a scenario's own stubs come first. |
1044
+ > | `scenarios` | AgentEvalScenario[] | yes | |
1045
+
1046
+ > **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`
1047
+ >
1048
+ > | Field | Type | Required | What it is |
1049
+ > |---|---|---|---|
1050
+ > | `says` | AgentEvalTextMatcher[] | | Each must match the reply. |
1051
+ > | `mustNotSay` | AgentEvalTextMatcher[] | | None may match the reply. |
1052
+ > | `toolCalled` | AgentEvalToolCall[] | | Each was called, with these arguments. |
1053
+ > | `toolNotCalled` | string[] | | None of these was called; `*` means no tool at all. |
1054
+ > | `approvalRequested` | false \| AgentEvalApprovalExpectation | | The turn stopped for the customer's approval of this call; `false`: it did not stop for any. |
1055
+ > | `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. |
1056
+ > | `doesNotStore` | AgentEvalTextMatcher[] | | None of these appears in anything the turn stored: its text, its tool calls' arguments, its tool results. |
1057
+ > | `held` | boolean | | `true`: the turn ran no model call, because a person held the conversation. |
1058
+
1059
+ > **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`
1060
+ >
1061
+ > | Field | Type | Required | What it is |
1062
+ > |---|---|---|---|
1063
+ > | `when` | object | | |
1064
+ > | `result` | { success: boolean, data?: any, error?: string } | yes | |